Google Chubby: The Lock Service That Inspired ZooKeeper
Explore Google Chubby's architecture, lock-based coordination, Paxos integration, cell hierarchy, and its influence on distributed systems design.
The 2006 Chubby paper describes Google's lock service and coarse-grained file system, including its cell architecture, advisory locks, and use of Paxos. It also influenced ZooKeeper, though the systems differ in their APIs and behavior. This article distinguishes the published design from unverified claims about Google's current internal systems.
Google Chubby: The Lock Service That Inspired ZooKeeper
The 2006 OSDI paper “The Chubby lock service for loosely-coupled distributed systems” describes a lock service and coarse-grained file system built for Google’s internal use at that time. The paper is the source for the design details below; it does not establish how Google’s internal systems are deployed today.
Chubby offered coordination primitives such as locks, leader election, and configuration storage. The ZooKeeper paper later cited Chubby as an influence, but ZooKeeper and etcd have their own APIs and semantics. Chubby itself was not released as a public product.
Design Philosophy
Chubby was built around a few key observations:
Coarse-grained locks are easier: Acquiring a distributed lock is expensive. Chubby optimized for coarse-grained locks held for seconds or minutes, not fine-grained locks held for milliseconds. The overhead of lock acquisition amortized over longer hold times.
Locks and files are related: A lock can be naturally represented as a file with specific semantics. A file containing the lock holder’s identity serves both as state and as the lock itself.
Event notification matters: Applications need to know when configuration changes, when a lock is released, or when a machine fails. Chubby built event notification into its API.
Cell hierarchy reduces confusion: Rather than a flat namespace, Chubby organized data into cells, each serving a subset of the overall namespace. This isolation simplified deployment and failure boundaries.
graph TD
A[Chubby Cell 1<br/>Namespace] --> B[Replica 1]
A --> C[Replica 2]
A --> D[Replica 3]
A --> J[Replica 4]
A --> K[Replica 5]
E[Chubby Cell 2<br/>Namespace] --> F[Replica 1]
E --> G[Replica 2]
E --> H[Replica 3]
E --> L[Replica 4]
E --> M[Replica 5]
Illustrative Cell-Migration Scenario
The Chubby paper describes cells and their role in the namespace, but it does not document the migration playbook below as a Google operating procedure. The sequence is a conceptual example of questions an operator would need to resolve when moving a coordination workload: provision a destination, decide how state is copied and kept consistent, redirect clients, handle retries and stale connections, then retire the source. It does not imply zero downtime, a particular DNS-based mechanism, or that Google used these steps.
A cell is a replication and failure boundary in the paper’s design. Adding replicas can change fault tolerance, but it does not automatically solve a workload or capacity bottleneck. Any migration or cross-cell namespace design would depend on the application and implementation; details beyond the paper are illustrative here.
Illustrative questions: How is state copied? How do clients switch safely?
How are stale connections handled? When is it safe to retire the source?
This is a design exercise, not a documented Chubby migration procedure.
Introduction
In the 2006 paper’s design, a Chubby cell consists of five replicas. They use Paxos to agree on operation order, so the cell can continue through some replica failures.
One replica is the master at any given time. All writes go through the master, which replicates to others via Paxos. Reads can be served by any replica, which locally cache data for performance.
graph TD
C[Client] -->|Write| M[Master]
C -->|Read| R1[Replica 1]
C -->|Read| R2[Replica 2]
M -->|Replicate| R1
M -->|Replicate| R2
M -->|Replicate| R3[Replica 3]
R1 -.->|Cache| C
R2 -.->|Cache| C
R3 -.->|Cache| C
Paxos gives Chubby linearizable reads and writes, the strongest consistency guarantee. This matters when two processes both think they hold the same lock—that’s the kind of inconsistency Paxos prevents.
Master Election and Failover: Conceptual Sequence
The paper describes leases, master election, and client recovery, but it does not give a universal failover timeline. The sequence below is a conceptual way to think about those steps, not a latency guarantee:
sequenceDiagram
participant M as Current master
participant R as Replicas
participant C as Client
M--xR: Lease renewal stops
Note over R: Lease and election rules determine when a successor can serve
R->>C: Client observes or discovers the new master
Note over C: Reconnect and handle recovery depend on client behavior
The paper describes master leases and client recovery, but it does not define a universal failover time. The sequence above is conceptual. Real availability depends on implementation, configuration, failure mode, and client behavior.
The File System Interface
Chubby presents a file system interface (like Unix) rather than a key-value API. Files organize in directories forming a path hierarchy.
/ls/google/chubby/cells/bigtable/master
/ls/google/chubby/cells/gfs/primary
/ls/services/search/config
/ls/services/search/locks/query
Each file has:
- Content: Small amounts of binary data (typically less than 1 MB)
- ACLs: Access control lists for permissions
- Metadata: Modification times, lock holders, etc.
- Locks: Optional advisory locks
# Chubby client operations (conceptual)
open("/ls/services/search/config") # Open a file
setContents("replicas=5, shard=true") # Write data
getContents() # Read data
acquire("my-process-id") # Acquire lock
release("my-process-id") # Release lock
Files can be ephemeral, automatically deleted when the client that created them closes its handle. If a process dies, its ephemeral files disappear, signaling failure to others.
Advisory Locks
Chubby provides advisory locks, not mandatory ones. A process can access a file without acquiring its lock, but coordination requires disciplines to actually use the locks.
# Conceptual Chubby lock acquisition
lock = chubby.lock("/ls/services/search/locks/query")
if lock.acquire(blocking=True, timeout=30):
try:
# Critical section - we hold the lock
config = read_config()
do_query(config)
finally:
lock.release()
else:
# Could not acquire lock
raise Exception("Lock acquisition timed out")
The lock advisory nature means misbehaving clients can ignore locks. In practice, this is rarely a problem because correct clients follow the protocol, and incorrect clients fail in predictable ways that trigger alerts.
Events and Notifications
Clients subscribe to events on files and directories. When things happen, Chubby notifies the client:
- File modified: Content of a watched file changed
- Lock acquired/released: Someone acquired or released a lock
- Child added/removed: A child directory or file was created or deleted
- Master failure: The cell master failed and a new one was elected
- Connection alive/broken: Connection to Chubby cell state changed
# Subscribe to file change events
handle = chubby.openFile("/ls/services/search/config")
handle.subscribe(chubby.FILE_MODIFIED, callback=reload_config)
# Subscribe to lock events
lock = chubby.lock("/ls/services/search/locks/master")
lock.subscribe(chubby.LOCK_ACQUIRED, callback=i_am_master_now)
The event mechanism lets clients react to changes without polling. For large-scale systems, this cuts down on load for both clients and the coordination service.
Chubby and Paxos
The Chubby paper describes using Paxos for consensus among replicas and explains how the protocol fits into this paper-era production system:
- Database backing store: Chubby uses a simple database (originally BerkeleyDB, later custom) to store state
- Instance numbers: Each Paxos instance is numbered, and Chubby runs many instances in parallel for different operations
- Epoch numbers: Masters are identified by epoch numbers, preventing old masters from acting after a new master is elected
- Lease mechanism: The master holds a lease from replicas, renewing it periodically
sequenceDiagram
participant R1 as Replica 1
participant R2 as Replica 2
participant R3 as Replica 3
participant M as Master
Note over M: Prepare to renew lease
M->>R1: Prepare(N=5)
M->>R2: Prepare(N=5)
M->>R3: Prepare(N=5)
R1-->>M: Promise(N=5,v=4)
R2-->>M: Promise(N=5,v=4)
R3-->>M: Promise(N=5,v=4)
Note over M: Majority promised!
M->>R1: Accept(N=5,v=5)
M->>R2: Accept(N=5,v=5)
M->>R3: Accept(N=5,v=5)
The lease mechanism ensures that if the master fails, replicas wait until the lease expires before accepting a new master. This prevents split-brain where two masters think they are in charge.
Paxos Integration Deep Dive
The original Paxos paper leaves several implementation details unspecified. Chubby’s production deployment fills in these gaps:
Epoch Numbers (Master Identity):
Epoch numbers are monotonically increasing integers that identify a master’s term. When a new master is elected, it increments the epoch number. Any message from an old epoch (lower epoch number) is rejected by replicas. This solves the “old master waking up” problem: if a master crashes and a new one is elected, but the old master recovers and tries to issue commands, replicas reject them because the old master’s epoch is stale.
# Simplified epoch check on replica
def handle_master_message(master_epoch, master_id, operation):
if master_epoch < self.current_epoch:
raise Rejected(f"Stale epoch {master_epoch} < {self.current_epoch}")
if master_epoch == self.current_epoch and master_id != self.master_id:
raise Rejected(f"Master ID mismatch")
# Accept the operation
self.process(operation)
Proposal Numbers (Operation Ordering):
Each Paxos instance (representing one Chubby operation) has a unique proposal number. Proposal numbers are structured as (round_number, replica_id) tuples, compared lexicographically. The higher round number wins, and if round numbers tie, the higher replica ID breaks the tie. This total ordering ensures that even if two proposers compete, only one value can be chosen per instance.
# Proposal number comparison
def compare_proposals(p1: tuple[int, int], p2: tuple[int, int]) -> int:
"""Returns 1 if p1 > p2, -1 if p1 < p2, 0 if equal"""
if p1[0] != p2[0]:
return 1 if p1[0] > p2[0] else -1
return 1 if p1[1] > p2[1] else -1
Chubby runs thousands of Paxos instances in parallel, one per operation. The instance number identifies which operation is being agreed upon, while proposal numbers sequence competing proposals within that instance.
Lease Mechanism in Detail:
In the Chubby design described by the paper, replicas make a timed promise to the master. The master must renew its lease before expiry or it can no longer act as master. This differs from Raft’s heartbeat-based election mechanism:
| Aspect | Chubby Master Lease | Raft Leader Heartbeat |
|---|---|---|
| Renewal trigger | Time-based, before expiry | Periodic heartbeat |
| Validity period | Explicit lease interval | Election timeout margin |
| **Stale leader detection | Lease expiry timeout | Heartbeat timeout |
| Replica promise | “I will not accept others” | “I will not vote for others” |
The paper’s protocol has the master renew its lease; if renewal fails, replicas wait for the lease to expire before electing a successor. The interval is a protocol parameter, not a universal timing guarantee for every implementation or a present-day Google setting.
# Conceptual lease renewal timeline
T=0s Master acquires lease (lease_duration=5s)
T=3s Master renews lease (at 60% of duration)
T=6s Master renews lease again
T=11s Master crashes, fails to renew
T=16s Lease expires (master + lease_duration)
T=16s+ Replicas accept new master election
Database Backing Store:
Chubby originally used BerkeleyDB as its backing store, later replacing it with a custom database. The database stores the Paxos log and application state. Each write goes to the WAL (write-ahead log) before being applied, enabling crash recovery. The database also stores the cell’s configuration, lock states, and file metadata.
Use Cases at Google
The Chubby paper describes several uses inside Google at the time of publication:
Leader Election: For Bigtable and GFS, one server needed to be primary. Chubby’s lock mechanism enabled reliable leader election without complex consensus code in each system.
Configuration Storage: Service configurations, feature flags, and routing tables lived in Chubby. Event notifications let services reload without restart.
Naming Service: Before DNS was sufficient, Chubby served as a naming service. Machine names, service endpoints, and discovery information lived in Chubby.
Distributed Locks: Semaphores and barriers for distributed batch jobs used Chubby locks to coordinate across thousands of machines.
Original Bigtable Dependency Context
Chubby and Bigtable have a deep historical relationship that shaped Google’s early infrastructure. Bigtable was designed to be a distributed storage system for structured data, capable of scaling to petabytes across thousands of machines. But Bigtable’s original design assumed the existence of a coordination service: tablets needed to know who the master was, where to find their tablet server, and how to recover from failures.
Chubby was built, in part, to solve this coordination problem for Bigtable. The original Bigtable paper (2006) describes how it uses Chubby for:
- Master election: The Bigtable master uses a Chubby exclusive lock to ensure only one master exists at a time
- Tablet location: Bigtable stores tablet location metadata in Chubby files, allowing clients to find the right tablet server
- Server lease management: Tablet servers maintain Chubby locks; if a tablet server loses its lock (crashed or network partition), the master knows to reassign its tablets
# Bigtable/Chubby interaction example
/chubby/cells/bigtable/master # Bigtable master election lock
/chubby/cells/bigtable/tablets/ # Directory containing tablet location data
/chubby/cells/bigtable/tserver/ # Ephemeral files for live tablet servers
The original Bigtable paper describes the system’s dependency on Chubby for master election, tablet location information, and tablet-server locks. That published design makes the dependency important to understand, but it does not establish how current Bigtable or Google services are operated. Claims about present-day cell assignments, retry policy, or Chubby replacements would need a current, independently verifiable source.
The ZooKeeper Connection
The ZooKeeper paper cites Chubby as an influence. The systems share a coordination-service lineage, but their interfaces and feature sets differ. For example, the ZooKeeper 3.9.3 Programmer’s Guide documents one-shot standard watches and persistent recursive watches (available since 3.6.0). The etcd v3.6 API documentation describes revision-based watches over a flat key space. These are version-specific examples, not timeless descriptions of every release.
Feature Comparison: Published Chubby Design and Versioned Public APIs
| Feature | Chubby (2006 paper) | ZooKeeper 3.9.3 docs | etcd v3.6 docs |
|---|---|---|---|
| Data model | Hierarchical files and directories | Hierarchical znodes | Flat binary key space with range operations |
| Change notification | Chubby events described in the paper | Standard watches are one-shot; persistent recursive watches are also available | Revision-based watch streams over key ranges |
| Coordination | Advisory locks and sequencers | Coordination primitives and recipes | Transactions, leases, and lock APIs |
| Evidence | Original paper | Programmer’s Guide | API docs |
This is a feature-level comparison, not a performance ranking. Chubby refers to the design documented in 2006; the ZooKeeper and etcd columns refer to the cited documentation versions. APIs, watch behavior, deployment models, and performance vary across releases and configuration. The ZooKeeper paper cites Chubby as an influence; that does not make etcd a Chubby descendant.
Limitations and Evolution
The 2006 paper presents Chubby as a coordination service for coarse-grained locks and small amounts of data, with clients using caching and notifications to limit requests. Those design choices make it a poor fit for rapidly changing application data. The paper does not describe later migrations or establish the service’s present-day status inside Google.
Trade-off Analysis
| Paper-era design choice | Benefit | Cost or limitation |
|---|---|---|
| Coarse-grained advisory locks | Clients can coordinate around long-lived work without making Chubby a mandatory lock manager | Clients must obey the locking protocol; the service does not control access to external resources |
| Replicated state with Paxos | A cell can make progress when a quorum is available | A cell that loses quorum cannot safely accept replicated updates |
| Hierarchical namespace and small files | Familiar organization for coordination metadata | Not a general-purpose filesystem or high-throughput data store |
| Client caching and notifications | Reduces repeated reads for stable data | Clients must handle disconnection and refresh behavior correctly |
These are trade-offs described by the 2006 paper, not a current product comparison or performance benchmark.
When to Use / When Not to Use
Chubby is useful to study when designing coarse-grained coordination, leader election, and configuration storage. Its paper explains the rationale for offering locks and a small file-system-like namespace as a shared service rather than having each client implement consensus.
Chubby is not available as a public product. For a deployable system, evaluate an available coordination service against the exact needs of the application. ZooKeeper’s cited 3.9.3 guide and etcd’s v3.6 API documentation describe different data models and notification semantics; neither should be treated as a drop-in Chubby implementation.
The paper’s focus on coarse-grained locks also makes the design a poor conceptual fit for per-record locking or rapidly changing application data. Those workloads call for mechanisms designed around their access patterns.
Failover: What the Paper Supports
The paper describes a master lease and the recovery steps used by the Chubby design. At a high level, the master must keep its lease valid, replicas need a safe way to elect a successor, and clients must reconnect and recover their handles. The exact delay depends on implementation, configuration, failure mode, and client behavior; the paper should not be read as a current service-level target.
The illustrative migration scenario earlier in this article is a model for discussing those questions. It is not a Google runbook, a documented zero-downtime migration, or a promise about present-day systems. Likewise, DNS cutovers, cell federation, operator alerts, file-handle thresholds, and database-maintenance procedures should not be attributed to Google without a primary source.
Quick Recap Checklist
- The 2006 paper describes Chubby as a lock service and coarse-grained file system
- The published design uses Paxos within a cell and advisory locks for coordination
- Chubby’s paper-era design includes client caching and event notifications
- The ZooKeeper paper cites Chubby as an influence; the two services have different APIs
- ZooKeeper 3.9.3 has one-shot standard watches and persistent recursive watches
- etcd v3.6 exposes revision-based watches, leases, and transactions over a flat key space
- Migration procedures, zero-downtime stories, and claims about current Google deployments are not established by the Chubby paper
Interview Questions
Expected answer points:
- Distributed lock acquisition is expensive (network round-trips, consensus overhead)
- Coarse-grained locks held for seconds or minutes amortize this overhead effectively
- Fine-grained locks held for milliseconds would make the coordination service a bottleneck
- Chubby was designed for coordination among relatively few processes, not per-record locking
Expected answer points:
- Master holds a lease from replicas, renewed periodically before expiry
- If master fails to renew (crash or partition), replicas wait until lease expires before accepting a new master
- Epoch numbers ensure old masters cannot issue commands after a new master is elected
- During partition, the old master cannot commit writes because it lacks quorum-backed lease
Expected answer points:
- Epoch numbers are monotonically increasing integers identifying a master's term
- When a new master is elected, the epoch number increments
- Any message from an old epoch (lower epoch number) is rejected by replicas
- This solves the "old master waking up" problem after network partition recovery
Expected answer points:
- Ephemeral files are automatically deleted when the client that created them closes its handle
- If a process dies, its ephemeral files disappear automatically
- This signals failure to other clients without requiring explicit cleanup
- Used for service discovery: a tablet server creates an ephemeral file; when it dies, the file disappears and the master knows to reassign its tablets
Expected answer points:
- The Chubby paper describes event notifications for changes relevant to a client’s handles
- In ZooKeeper 3.9.3, standard watches are one-shot; persistent recursive watches are also available, a feature added in 3.6.0
- These descriptions are tied to the cited paper and release documentation; they are not universal descriptions of all versions
Expected answer points:
- Chubby presents a hierarchical Unix-like namespace with directories and files
- Each file has content, ACLs, metadata, and optional advisory locks
- Paths like /ls/google/chubby/cells/bigtable/master mirror familiar file paths
- Key-value stores typically use flat namespaces; Chubby's hierarchy organizes data naturally for naming and service discovery
Expected answer points:
- Paxos requires a majority quorum to operate (3 out of 5 can acknowledge writes)
- Five replicas tolerate two simultaneous failures while maintaining quorum
- Three replicas would only tolerate one failure (majority is 2)
- Seven replicas would be more resilient but add more latency and resource overhead
Expected answer points:
- The master must renew its lease with replica support to remain authoritative
- Replicas use the lease protocol and Paxos state to avoid accepting conflicting masters
- Clients should use the documented Chubby interface and sequencer checks when coordinating actions outside Chubby
- Do not infer a current outage procedure or a `WAIT_ANY` recommendation unless a source documents it
Expected answer points:
- Bigtable master uses a Chubby exclusive lock for master election (only one master at a time)
- Tablet location metadata is stored in Chubby files so clients can find the right tablet server
- Tablet servers maintain Chubby locks; losing a lock signals the master to reassign tablets
- The dependency was unidirectional: Bigtable depended on Chubby, but Chubby did not depend on Bigtable
Expected answer points:
- Chubby: time-based renewal before expiry; explicit lease interval with duration
- Raft: periodic heartbeat messages; election timeout margin determines validity
- Chubby replica promises "I will not accept others" during lease validity
- Raft follower promises "I will not vote for others" during election timeout
- Both achieve similar goals (preventing split-brain) through different mechanisms
Expected answer points:
- Use the 2006 paper as evidence for the implementation details it actually publishes
- Claims about later database replacements, current storage internals, or maintenance procedures need a separate primary source
- Do not treat a plausible implementation detail as a documented fact
Expected answer points:
- Each Paxos instance has a unique proposal number structured as (round_number, replica_id)
- Comparison is lexicographic: higher round number wins
- If round numbers tie, higher replica ID breaks the tie
- This total ordering ensures only one value can be chosen per instance, even with competing proposers
Expected answer points:
- Standard watches are one-shot and must be registered again for later changes
- Persistent recursive watches are also available, introduced in ZooKeeper 3.6.0
- The guide documents behavior, not a single motivation for the design choice
- See the linked 3.9.3 Programmer’s Guide for release-specific semantics
Expected answer points:
- The paper describes the cell model and namespace, but does not document the migration playbook or federation claims in this article
- DNS cutovers, zero-downtime guarantees, and cross-cell proxy behavior here are illustrative, not verified Google procedures
- Any operational claim about later versions needs a primary source for that version
Expected answer points:
- The paper describes lease expiration, master election, and client recovery as parts of the process
- It does not provide a universal outage target for current deployments
- Cell configuration, failure conditions, client behavior, and software version affect observed recovery time
- Compare ZooKeeper or etcd timing only against a specified release and configuration
Expected answer points:
- Each cell serves a subset of the overall namespace with its own replica set
- Failure of one cell does not directly impact others serving different namespaces
- This isolation simplifies deployment boundaries and failure domains
- Services can be assigned to cells based on criticality or load characteristics
Expected answer points:
- Chubby was designed for coarse-grained coordination and low-volume storage, not high-frequency data access
- Some clients cache data and use notifications to reduce polling
- The paper is not evidence of why Google may have adopted other internal systems later
Expected answer points:
- The original Paxos paper left several implementation details unspecified
- Chubby filled gaps: epoch numbers, proposal numbering, lease mechanisms, database backing store
- Chubby runs thousands of Paxos instances in parallel (one per operation)
- Instance numbers identify which operation is being agreed upon, while proposal numbers sequence competing proposals
Expected answer points:
- Mandatory locks would require Chubby to intercept and block all file access attempts
- This would create a centralized bottleneck defeating Chubby's distributed design
- Advisory locks are a convention: correct clients use them, incorrect clients fail predictably
- In practice, well-behaved clients follow the protocol, and misbehaving ones trigger alerts
Expected answer points:
- The ZooKeeper research paper cites Chubby as an influence
- etcd exposes a distinct v3 API with key ranges, revision-based watches, leases, and transactions
- Similar coordination problems do not establish a direct lineage or identical semantics
- Use versioned documentation when comparing behavior
Further Reading
-
The Chubby lock service for loosely-coupled distributed systems (OSDI 2006) — Primary source for Chubby’s published design and paper-era use.
-
ZooKeeper 3.9.3 Programmer’s Guide — Watch semantics for the cited release.
-
etcd v3.6 API documentation — Public API behavior for the cited release.
-
Distributed Transactions explains the Paxos consensus algorithm Chubby uses
-
etcd Distributed Storage introduces etcd’s key-value model and coordination role
-
Apache ZooKeeper introduces ZooKeeper’s coordination API
-
Consistency Models covers linearizability guarantees that Paxos provides
Conclusion
Chubby was a pioneering coordination service demonstrating how to build production-grade distributed consensus:
- Production Paxos: Showed how Paxos could work efficiently for real-world use
- Coarse-grained locking: Provided locks as a service, amortizing coordination overhead
- Event notifications: Built reactive patterns into the coordination service itself
- Hierarchical namespace: Made data organization intuitive, like familiar file systems
The 2006 Chubby paper is essential reading for distributed systems practitioners. It explains not just how Chubby works, but why decisions were made, and what trade-offs were accepted.
The Chubby design remains useful to study. The ZooKeeper paper identifies Chubby as an influence; broader claims about the lineage of etcd or Consul should be made only with sources that establish that connection.
The lesson: coordination is a common problem worth solving once and well. Getting consensus right is hard enough without every team inventing their own poorly-tested version. Chubby proved that a well-designed coordination service could be general enough and efficient enough to serve as infrastructure for large-scale distributed systems.
Category
Related Posts
etcd: Distributed Key-Value Store for Configuration
Deep dive into etcd architecture using Raft consensus, watches for reactive configuration, leader election patterns, and Kubernetes integration.
Google Spanner: Globally Distributed SQL at Scale
Google Spanner architecture combining relational model with horizontal scalability, TrueTime API for global consistency, and F1 database implementation.
Multi-Paxos
Multi-Paxos extends basic Paxos to achieve consensus on sequences of values, enabling practical replicated state machines for distributed systems and databases.