CS PAPERS DEEP READ · PAPER 72

Distributed Snapshots

K. Mani Chandy & Leslie Lamport · ACM TOCS · 1985

中文 →

What did this paper do?

In 1985, Chandy and Lamport gave a way to take a coherent photograph of an entire distributed system — without stopping it, and without any clock that every machine agrees on. When a stream engine like Flink saves its progress every few seconds and resumes from the last save after a crash, it is running this paper's idea.

Start with something odd

Say the system holds just two accounts, A and B, with 100 dollars between them, and you want to check the total. You ask A: "how much do you have?" — A says 100. But right after you hang up, A wires 50 to B. You ask B — B says 50. That adds up to 150. Fifty dollars appeared out of nowhere.

Reversing the order is just as bad: ask A first (already wired, 50 left), then B (the money is still in flight, still 0) — a total of 50, and money has vanished. You did not miscount. The problem is that your two questions did not happen at the same instant. And in a distributed system there is no such thing as "the same instant": no two clocks agree, and you cannot make the world hold still while you take a picture.

What is new here

The older options were to stop the system (which stops the business with it) or to synchronize clocks (which never gets accurate enough). This paper changed the goal instead: stop chasing "the same instant" and settle for "not self-contradictory." As long as the photo never shows "B received money that A has not sent yet" — an effect arriving before its cause — it is a legitimate photo, even if the system never actually looked like that at any single moment. For a great many questions, that is enough.

How it works

The trick is embarrassingly simple. It needs one thing: a red card.

Why can't this contradict itself? Because a line is a queue: what is sent first arrives first. So the red card becomes a divider on that line: everything ahead of it was sent before the photo, everything behind it was sent after. The "after" messages can never get into the photo (no money appears from nowhere), and any "before" message not yet delivered is guaranteed to land inside the window between "I recorded myself" and "the card arrived" (no money vanishes). There is no conductor and nobody is paused — each machine watches only its own few lines and makes a local decision, and a globally coherent photo assembles itself.

What it bought us

With a photo in hand, a pile of questions that only make sense from outside the system become judgements about one static picture: is it deadlocked? is the work finished? is anyone still using this memory? Plus the most practical use of all — the save point: store the photo, and after a crash restart from it instead of from the beginning.

One honest caveat: the photo may describe a moment that never actually happened — it is merely coherent. So it cannot answer fleeting questions like "how long is the queue right now."

Remember this

You cannot capture "the same instant," so settle for a photo that is merely self-consistent: whoever wants a snapshot records itself first, then drops a marker onto every outgoing line; whoever receives a marker does the same and passes it on; and whatever arrives between "I recorded myself" and "the marker got here" was in flight at photo time and is recorded too. Nobody stops, nobody synchronizes clocks, and a globally consistent picture assembles itself.

Want the marker rules as the paper states them, the space-time picture of a consistent cut, and the theorem that the snapshot may never have existed? → Switch to the deep read