Answer
Zookeeper adopts a master-slave architecture design, achieving data consistency and high availability through the ZAB protocol.
Cluster Roles
-
Leader
- Handles all write requests
- Responsible for coordinating cluster state
- Maintains data replica synchronization
- The only node that can process transaction requests
-
Follower
- Handles client read requests
- Participates in Leader election voting
- Receives data synchronization from Leader
- Forwards write requests to Leader
-
Observer
- Only handles read requests
- Does not participate in Leader election
- Does not participate in data write voting
- Receives data synchronization from Leader
Architecture Advantages
High Availability:
- Any node failure in the cluster does not affect service
- New Leader automatically elected when Leader fails
- Supports rapid fault recovery
Scalability:
- Improve read performance by adding Observer nodes
- Horizontally scale read capability
- Reduce load on Leader and Follower
Data Consistency:
- ZAB protocol guarantees strong consistency
- All Followers synchronize data with Leader
- Read requests may read stale data
Deployment Recommendations
Node Count:
- Production environment recommends 3, 5, or 7 nodes
- Odd number of nodes facilitates election voting
- Minimum 3 nodes to ensure high availability
Role Assignment:
- Leader + Follower: Ensure data consistency
- Add Observer: Improve read performance
- Typical configuration: 3 nodes (1 Leader + 2 Followers)
Network Requirements:
- Low-latency network between nodes
- Stable network connection
- Avoid cross-datacenter deployment
Client Connection
- Client connects to any available node
- Automatic reconnection mechanism
- Session timeout detection
- Watcher event notification