Interview Practice
Read aloud is unavailable in this browser. Reading preferences still work.

Chubby

How Chubby Works

Let’s learn how Chubby works.

1 min read

Service initialization

Upon initialization, Chubby performs the following steps:

  • A master is chosen among Chubby replicas using Paxos.
  • Current master information is persisted in storage, and all replicas become aware of the master.

Client initialization

Upon initialization, a Chubby client performs the following steps:

  • Client contacts the DNS to know the listed Chubby replicas.
  • Client calls any Chubby server directly via Remote Procedure Call (RPC).
  • If that replica is not the master, it will return the address of the current master.
  • Once the master is located, the client maintains a session with it and sends all requests to it until it indicates that it is not the master anymore or stops responding.
Chubby high-level architecture
Chubby high-level architecture

Leader election example using Chubby

Let’s take an example of an application that uses Chubby to elect a single master from a bunch of instances of the same application.

Once the master election starts, all candidates attempt to acquire a Chubby lock on a file associated with the election. Whoever acquires the lock first becomes the master. The master writes its identity on the file, so that other processes know who the current master is.

Diagram: How Chubby Works

Sample pseudocode for leader election

The pseudocode below shows how easy it is to add leader election logic to existing applications with just a few additional code lines.

Diagram: How Chubby Works
Save a specific section