Zookeeper zookeeper.forceSync, Zab and Paxos
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. At the core of Apache ZooKeeper's operations, is the ability to ensure reliability and high-throughput even in the presence of network partitions and failure scenarios. In this discussion, we will delve deep into the zookeeper.forceSync configuration, the Zab (ZooKeeper Atomic Broadcast) protocol, and compare it with the Paxos protocol, highlighting their relevance and applications in distributed systems.
Zookeeper.forceSync
zookeeper.forceSync is a configuration parameter in ZooKeeper that controls how data is synchronized across nodes. When set to no, it does not force the leader to perform an fsync on transaction log entries. The transaction logs are only synced based on periodic intervals or the amount of data unsynced instead. In contrast, setting this value to yes mandates that every transaction is followed by fsync, thereby ensuring immediate durability of the log entry.
The choice between enabling and disabling it involves a trade-off between performance and data integrity. Disabling might offer better performance at the risk of potential data loss, while enabling it ensures better data safety at the cost of performance.
Example Usage:
This parameter can be set in the zoo.cfg configuration file:
ZooKeeper Atomic Broadcast (Zab)
Zab is a protocol used by ZooKeeper for managing distributed updates, particularly aimed at maintaining a consistent ordered log of updates across all of ZooKeeper’s ensemble nodes. It ensures that all these changes occur as atomic transactions. The Zab protocol works in two main phases: the discovery and synchronization phase, and the broadcast phase.
- Discovery and Synchronization: This phase deals with electing a leader and synchronizing the state of all servers with the leader to ensure data consistency.
- Broadcast: In this phase, the leader accepts requests from clients and forwards these as messages to all followers. Each message contains a transaction that modifies the system's state.
Zab ensures that each transaction from a leader is replicated to all followers in the same order, achieving consistency across the cluster.
Paxos
Paxos is a protocol for achieving consensus among distributed systems which may otherwise be unreliable. Paxos ensures that among a number of possible proposals, only one is chosen. It can tolerate faults as long as a majority of its components are operational.
Key steps in the Paxos protocol:
- Proposal: A proposer suggests a value.
- Acceptance: Acceptors vote on proposed values they have received, choosing the first proposal seen.
- Learning: Once a majority of acceptors approve a proposal, the value is chosen and learners can be informed of the decision.
Paxos is complex due to its multi-phase consensus process and is typically harder to implement directly compared to protocols like Zab, which are specifically tailored for simpler, more predictable workflows like those in ZooKeeper.
Comparison of Zab and Paxos
| Feature | Zab | Paxos |
| Design Focus | Transaction ordering and replication | Consensus among distributed agents |
| Complexity | Medium, specialized for ZooKeeper | High, generic |
| Suitability | Ordered changes in a replicated log | General agreement in distributed systems |
| Typical Use Case | ZooKeeper ensemble coordination | Multi-scenario distributed systems |
| Fault Tolerance | Leader-based recovery | Majority consensus |
| Implementation specificity | Integral to ZooKeeper | Broadly used, diverse implementations |
Additional Considerations
Beyond the basics, understanding how protocols like Zab and Paxos are implemented and leveraged can provide deeper insights into designing robust distributed systems. For example, considering the impact on system performance when turning zookeeper.forceSync on or off or choosing between Zab and Paxos depending on application requirements and setup complexity.
Overall, the choice between using Zab and Paxos depends on specific system requirements, predictability of operations, and the desired level of abstraction and ease of implementation. Each has its strengths and is better suited to different kinds of distributed system challenges.
Related reading
- zsh command not found rabbitmq-server
- -bash bin/kafka-topics.sh No such file or directory installed via ambari
- -bash kafka-server-start.sh command not found
- 100% cpu usage by all kafka brokers
- 1000 items, 1000 nodes, 3 items per node, best replication scheme to minimize data loss as nodes fail?
- 1 Kafka topic with consumer filters vs. many topics without consumer filters
- 0-1 Knapsack w/ partitioning constraints
- 0/1 knapsack with dependent item weight?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.