What's the purpose of using Zookeeper rather than just databases for managing distributed systems?
Asked Answered
T

4

26

I’m learning Zookeeper and so far I don't understand the purpose of using it for distributed systems that databases can't solve.

The use cases I’ve read are implementing a lock, barrier, etc for distributed systems by having Zookeeper clients read/write to Zookeeper servers. Can’t the same be achieved by read/write to databases?

For example my book describes the way to implement a lock with Zookeeper is to have Zookeeper clients who want to acquire the lock create an ephemeral znode with a sequential flag set under the lock-znode. Then the lock is owned by the client whose child znode has the lowest sequence number.

All other Zookeeper examples in the book are again just using it to store/retrieve values.

It seems the only thing that differs Zookeeper from a database/any storage is the “watcher” concept. But that can be built using something else.

I know my simplified view of Zookeeper is a misunderstanding. So can someone tell me what Zookeeper truly provides that a database/custom watcher can’t?

Theta answered 30/3, 2016 at 14:59 Comment(0)
C
13

Can’t the same be achieved by read/write to databases?

In theory, yes it is possible, but usually, it is not a good idea to use databases for demanding usecases of distributed coordination. I have seen microservices using relational databases for managing distributed locks with very bad consequences (e.g. thousands of deadlocks in the databases) which in turn resulted in poor DBA-developer relation :-)

Zookeeper has some key characteristics which make it a good candidate for managing application metadata

  • Possibility to scale horizontally by adding new nodes to ensemble
  • Data is guaranteed to be eventually consistent within a certain timebound. It is possible to have strict consistency at a higher cost if clients desire it (Zookeeper is a CP system in CAP terms)
  • Ordering guarantee -- all clients are guaranteed to be able to read data in the order in which they have been written

All of the above could be achieved by databases, but only with significant effort from application clients. Also watches and ephemeral nodes could be achieved by databases by using techniques such as triggers, timeouts etc. But they are often considered inefficient or antipatterns.

Relational databases offer strong transactional guarantees which usually come at a cost but are often not required for managing application metadata. So it make sense to look for a more specialized solution such as Zookeeper or Chubby.

Also, Zookeeper stores all its data in memory (which limits its usecases), resulting in highly performant reads. This is usually not the case with most databases.

Curie answered 16/2, 2018 at 17:31 Comment(1)
zk isnt cp system. its highly available, but it can be cp with the sync api thats provided.Poster
S
8

I think you're asking yourself the wrong question when you try to figure out the purpose of Zookeeper, instead of asking what Zookeeper can do that "databases" can not do (btw Zookeeper is also a database) ask what Zookeeper is better at than other available databases. If you start to ask yourself that question you will hopefully understand why people decide to use Zookeeper in their distributed services.

Take ephemeral nodes for example, the huge benefit of using them is not that they make a much better lock than some other way. The benefit of using ephemeral nodes is that they will automatically be removed if the client loses connection to Zookeeper.

And then we can have a look at the CAP theorem where Zookeeper closest resembles a CP system. And you must once again decide if this is what you want out of your database.

tldr: Zookeeper is better in some aspects and worse in others compared to other databases.

Sweatshop answered 30/3, 2016 at 22:5 Comment(3)
Thanks for pointing me to the right direction! It was confusing since how I read about is using Zookeeper to read/write but people rarely describe Zookeeper with RDBMS so I thought it was completely different.Theta
One thing I don't understand is how is Zookeeper any more Partition Tolerant than any RDBMS?Theta
I think you should look in to this question about NoSql vs RDBM, I think it might help you. dba.stackexchange.com/questions/34892/…Sweatshop
I
3

Late in the party. Just to provide another thought:

Yes, it's quite common to use SQL database for server coordinations in production. However, you will likely be asked to build a HA (high availability) system, right? So your SQL DB will have to be HA. That means you will need the leader-follower architecture (a follower SQL DB), follower will need to be promoted to the leader if the leader dies (MHA nodes + manager), when the previous leader is back to life it must know that it's no longer the leader. These questions have answers but will cost engineer effort to set them up. So Zookeeper is invented.

I sometimes consider Zookeeper as a simplified version of HA SQL cluster with a subset of functionalities.

Similarly, why people choose to use NoSQL VS SQL. With the proper partitioning, SQL can also scale well, right? So why NoSQL. One motivation is to reduce the effort level in case of handling node failures. When a NoSQL node is dead, it can automatically fallback to another node and even trigger the data migration. But if one of your SQL partition leader is died, it usually requires manual treatment. This is like SQL VS Zookeeper. Someone coded up the HA + failover logic for you, so we can lay back, hopefully, in case of inevitable node failures.

Imparity answered 17/12, 2021 at 4:21 Comment(1)
can you elaborate on what you mean by manual work is required? I thought primary - slave with async replication. failover is automatic?Poster
F
1

ZooKeeper writes are linearizable. Linearizable means that all operations are totally ordered. Total order means that for every operation a and b, Either a happened before b, or b happened before a.

Linearizability is the strongest consistency level. Most databases give up on linearizability because it affects performance, and offer weaker consistency guarantees instead - e.g casuality (casual order).

ZooKeeper uses this to implement an atomic broadcast algorithm, which is equivalent to consensus.

Full answered 24/1, 2022 at 23:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.