System Design (50 Qs)•Part 3: Distributed Transactions, Consensus & Reliability (26 - 36)
Distributed Locking: Redlock Algorithm vs ZooKeeper / etcd.
In Simple Words: Coordinate exclusive access to a shared resource across multiple independent compute instances.
- Redis Redlock: Acquires lock across $N$ independent Redis masters (typically 5). Lock is granted if acquired on $ge (N/2 + 1)$ masters within validity time.
- ZooKeeper / etcd: Uses consensus-backed ephemeral sequential nodes. If holder crashes, heartbeat loss automatically drops the ephemeral node and triggers a watch event for the next in line.