CS PAPERS DEEP-READ · PAPER 20

The Chubby Lock Service

Mike Burrows · Google · OSDI 2006

中文 →

What did this paper do?

Inside Google there's an unassuming little service called Chubby. Almost every big system — GFS, Bigtable, MapReduce from the previous batch — leans on it to do one job: pick "who's in charge" out of a crowd of machines, and get every machine to agree on the same boss. Its real trick is taking a famously hard distributed-systems problem and packaging it into a tool anyone can use, so application programmers never have to wrestle with the brain-bending theory themselves.

First, the hard problem

Say you have a pile of machines cooperating, and you need one of them to be the "leader" (it makes decisions, keeps the books). The requirement: every machine must agree on the same leader, and at no instant may two machines both think they're in charge. Sounds easy? But these machines crash without warning, cables get cut, messages arrive late. In that world, "getting everyone to agree on one thing" is hard enough to be its own field of study. Worse, nearly every team has to face the same pit from scratch.

The idea: a shared "safe-deposit box + padlock"

Chubby's move is neat: it offers something like a shared network drive where you can make tiny files and jot a few lines; and every file can carry a lock that only one person can grab at a time. So leader election becomes something a grade-schooler gets — whoever grabs the lock is the leader, and after grabbing it they write their name into the file; every other machine reads the file and knows who the leader is. Elect a leader, stash a critical note, let everyone find each other — all in this one place.

How does it guarantee only one person grabs the lock?

The key is that Chubby isn't one machine — it's a team of 5 machines with one iron rule: any decision needs a majority to agree — at least 3 of the 5 say yes before it counts. Why does that rule stop "two bosses"? Because one decision needs 3 votes, so two contradictory decisions would need 6 votes total — and there are only 5 machines, not enough to go around. The math itself rules out two simultaneous leaders. Even if one or two machines die, the rest can still form a majority and keep going. This "majority vote" rule is exactly the classic Paxos consensus algorithm. Chubby's contribution isn't inventing it — it's burying it inside a service, done once, so everyone gets it for free.

Why does everyone love it?

Because it hides the hard part. To add "highly available leader election" to your system, you'd normally have to read a stack of papers, spend months, and still likely get it wrong. With Chubby you only need the moves you already know from any operating system — make a file, grab a lock, read a file — with tiny changes to your code. It got so popular it ended up being used as the whole company's "phone book" (a name service): people wrote "which machine is service X on" into Chubby and looked each other up — a use even the author didn't anticipate.

Remember one thing

Chubby takes the hard problem "how do crash-prone machines agree on one leader" and packages it as a "files + locks" service like a shared drive: whoever grabs the lock is the leader. Inside, 5 machines and a "majority-only" rule guarantee the lock is never grabbed by two people at once. It turns leader election from a craft into a function call — and became the foundation under nearly all of Google's big systems.

Want Chubby's architecture, its lease-and-cache machinery, and the full "why a lock service, not a library" argument? → switch to the deep read