← The Books

Taking Stock Without Stopping

How do you take an accurate snapshot of an entire distributed system while it keeps running, when no single machine can see the whole network at once? And what can such a snapshot reliably tell you?

To find out, we follow three ancient Greek trading houses that suspect bandits are robbing their carts on the coastal road, and must count every jar they own, including those in transit, without halting trade.

To find out, we follow the algorithm step by step. Three processes pass units of a resource to one another over channels, and must record the state of the whole system, including what is in transit, without ever pausing.

After K. Mani Chandy and Leslie Lamport, Distributed Snapshots: Determining Global States of Distributed Systems, 1985

A harbour town seen from the slope above it: a curving shore, a paved quay with beached boats and a storehouse by the road; in the foreground an accountant and a clerk check a tally, and a cart comes down the road behind
Where this book sits
Draws on
Leads to
  • Checkpointing and Rollback-Recovery for Distributed SystemsKoo & Toueg 1987
  • On Distributed SnapshotsLai & Yang 1987
  • Virtual Time and Global States of Distributed SystemsMattern 1988 · Ordering Without Clocks
  • Consistent Detection of Global PredicatesCooper & Marzullo 1991
  • Lightweight Asynchronous Snapshots for Distributed DataflowsCarbone et al. 2015

Each link shows how one paper built on an idea from another. Hover over or tap any link to read how.

a paper this book retells a paper retold in another book a paper outside the series

The cliff road in the morning: a mule draws a cart loaded with amphorae, its driver at its head, while in the foreground a bandit crouches behind a bush, watching it pass
The ring road of ArcheThe model

Three houses, carts on one cliff roadThree processes, six channels

House 1, House 2, and House 3 sit along the coast of Arche, separated by a steep mountain. Carts of jars and messengers travel from house to house along the coastal cliff road, and bandits have been spotted on the island.Three processes, P1, P2 and P3, pass messages along directed channels. Some messages carry units of a resource from one process to another, and units may be lost in transit.

No overtakingNothing may pass another on a road track, so carts and messengers always reach the far gate in the exact order they set out.*FIFO channelsNothing may pass another on a channel, so messages always arrive in the exact order they were sent.
One track each wayEach house has a direct one-way track to each of the other two houses, making six directed road tracks in all.One channel each wayEach process has a direct one-way channel to each of the other two processes, making six directed channels in all.
Bandits take carts, not messengersBandits may ambush a loaded cart on the road. A messenger carrying no goods is not worth a bandit's trouble, so every messenger arrives safely.Units may be lost, markers are notA fault may remove a message that carries units. A marker message carries nothing of value, so it always arrives safely.
The houses' questionThe question

How much do we hold between us?How much does the system hold?

During a busy winter of trade, rumors spread that bandits were seizing carts along the cliff road. Whenever a cart left one house and took a long time to reach the next, nobody could tell whether it had been stolen by bandits or was merely delayed behind a slow mule.While the system is busy, there are signs that some messages carrying units are being lost. Whenever a message takes a long time to reach its destination, nobody can tell whether it has been lost or is merely delayed behind a slow channel.

To find out whether they have actually been robbed, the three houses want to take a complete inventory of every jar of oil and grain they hold across the island, and compare that count against what their account scrolls say they ought to own. Any shortfall will prove what the bandits took.To find out whether units have actually been lost, the three processes want to take a complete inventory of every unit in the system and compare that count against what the total ought to be. Any shortfall will prove what was lost.

The catch is that the houses' jars sit in two different kinds of places: some rest inside the three storehouses, while the rest are out on the road, strapped to carts and pack-mules in transit.*The catch is that units sit in two different kinds of places: some rest inside the three processes’ local states, while the rest are in transit, carried by messages on the channels.

The island of Arche from far out over the sea in the evening light: one mountain rising to a ridge in the middle, a low coast ringing it

The scribes' first idea is the obvious one: send an auditor to each of the three storehouses, count the jars inside each one, and add the three numbers together. The recorder of the customs rolls watched the carts moving along the cliff road and immediately saw why that plan fails:The first idea is the obvious one: ask each of the three processes in turn for its local count, and add the three numbers together. Watching the messages moving along the channels, it is easy to see why that plan fails:

Morning oneCase one

Counted twice

Suppose House 3's auditor counts early and House 2's counts late. In between, a cart carries 200 jars of oil from House 3 to House 2. House 3 counted those jars before they left, and House 2 counts them a second time after they arrive, making the total 200 jars too high!Suppose P3 reports its count early and P2 reports its count later. In between, a message carries 200 units from P3 to P2. P3 counted those units before they left, and P2 counts them a second time after they arrive, making the total 200 units too high!

Morning twoCase two

Counted by nobody

Suppose the auditors count at the same hours as before, but a cart of 200 jars leaves House 2 before its auditor looks and has not reached House 3 when its auditor finishes. Those jars left House 2 before its auditor looked, and arrived at House 3 after its auditor finished, so 200 jars vanish from the count even though no bandit touched them!Suppose the counts are taken at the same times as before, but a message carrying 200 units leaves P2 before P2 is asked and has not reached P3 when P3 reports. Those units left P2 before its count was taken, and arrived at P3 after its count finished, so 200 units drop out of the total even though nothing was lost!

The root cause

Wrong by whatever moved

Counting the storehouses one after another is always off by the net goods that travelled between an already-counted house and an uncounted one, and without a shared clock, nobody can tell how much moved in between.Counting the processes one after another is always off by the net units that travelled between an already-counted process and an uncounted one, and without a shared clock, nobody can tell how much moved in between.

In both mornings, the auditors counted the storehouses accurately, but missed or double-counted the goods moving along the road. The most obvious way to keep moving carts from spoiling the count is simply to halt all road traffic while the auditors work.In both cases, the local counts were accurate, but the units moving between processes were missed or double-counted. The most obvious way to keep moving units from spoiling the count is simply to halt all traffic while the counts are taken.

The first thought

Why not stop the road?Why not stop the system?

Suppose the houses agree to freeze all trade: stop sending carts, wait until every cart already on the road has rolled into a gate, count the three storehouses while the roads sit empty, and then resume business.Suppose the processes agree to freeze all activity: stop sending messages, wait until every message already in transit has arrived, record the three local states while the channels sit empty, and then resume.

Thinking through how to actually carry out that freeze reveals two problems, and a surprising shortcut that eliminates the need to stop at all:

First problem

Halting trade is expensiveHalting the system is expensive

The three houses supply the island's port towns every day. Freezing all shipments until the longest stretch of road empties out brings the island's commerce to a standstill.The system serves requests continuously. Freezing all activity until the slowest channel drains brings the whole service to a standstill.

Second problem

The stop order travels by roadThe stop order travels by message

Without a shared clock, the order to stop must travel by messenger. Each house stops sending new carts when the messenger arrives, keeps receiving carts still on the road, and counts once its incoming tracks are empty.Without a shared clock, the order to stop must travel by message. Each process stops sending new messages when the order arrives, keeps receiving messages still in transit, and records its state once its incoming channels are empty.

The hidden catch

How do you know a road is empty?How do you know a channel is empty?

Standing at a gate, a clerk cannot see around the sea cliffs to tell whether another cart is still lumbering along the road. To prove a track is empty, each house must send a final messenger the moment it stops, meaning "no more carts behind me."A process cannot see inside a channel to tell whether another message is still on its way. To prove a channel is empty, each process must send a final message the moment it stops, meaning “no more messages behind me.”

Look closely at that third card. Even if the houses stopped all trade, they would still need to send a special messenger down every track to mark the end of the carts sent before the freeze! The recorder of the customs rolls realized what that meant: if a messenger can mark the boundary between pre-count carts and post-count carts on a narrow road where nobody overtakes, the houses do not need to stop sending carts behind that messenger at all.Look closely at that third card. Even if the processes stopped all activity, they would still need to send a special message down every channel to mark the end of the messages sent before the freeze! The insight follows: if a special message can mark the boundary between pre-record messages and post-record messages on a FIFO channel, the processes do not need to stop sending messages behind it at all.

House 1's accountant added a second insight. Freezing the road was an attempt to capture the island at a single simultaneous instant. In truth, the houses do not need a simultaneous instant; they only need a sound (consistent) inventory where no jar is counted twice and no jar slips through the cracks.A second insight follows. Freezing the system was an attempt to capture it at a single simultaneous instant. In truth, the processes do not need a simultaneous instant; they only need a consistent snapshot where no unit is counted twice and no unit slips through the cracks.

To build that sound inventory while the carts keep rolling, we first have to be crystal clear about all the places on Arche that can hold jars.To build that consistent snapshot while the system keeps running, we first have to be crystal clear about all the places that can hold units.

What is being countedWhat is being recorded

Nine places, not threeNine numbers, not three

Every house naturally thinks of its inventory as the jars sitting under its own roof. But jars strapped to a cart out on the cliff road belong to the island's stock just as surely as jars in a cellar, and ignoring the road is precisely why the auditors' first attempt went wrong.Every process naturally thinks of its inventory as the units in its own local state. But units carried by messages in transit belong to the system’s total just as surely as units held locally, and ignoring the channels is precisely why the first attempt went wrong.

A complete snapshot of Arche therefore consists of nine numbers: the stock inside each of the three storehouses, plus the jars currently travelling along each of the six one-way road tracks connecting pairs of houses.* Click each of the nine places on the map below.A complete snapshot therefore consists of nine numbers: the local state of each of the three processes, plus the units currently in transit on each of the six one-way channels connecting pairs of processes. Click each of the nine places on the diagram below.

Nine places to countNine places to record

Three storehouses and six tracks. Choose any of them.Three processes and six channels. Choose any of them.

Counting a storehouse is easy, a clerk can tally the shelves quickly. Counting the jars on a winding cliff road that the clerk cannot see from the house's gate is harder.Recording a local state is easy, a process can read its own memory. Counting the units in a channel it cannot see inside is harder.

The recorder of the customs rolls saw the answer: you do not have to look at the road to count what is on it, because every cart on a road track eventually rolls through the receiving house's gate. A receiving house simply needs to record on a wax slate every cart that arrives along that track after the house counted its own storehouse, and stop recording the moment the last cart sent before the sender's count has arrived.The answer: you do not have to look inside a channel to record what is in it, because every message on a channel eventually arrives at the receiving process. A receiving process simply needs to log every message that arrives along that channel after the process recorded its own state, and stop logging the moment the last message sent before the sender’s recording has arrived.

And to tell the receiving gate the exact moment that last pre-count cart has arrived, the houses use the messenger in the red sash.And to tell the receiver the exact moment that last pre-record message has arrived, the processes use a marker.

Chandy and Lamport's marker algorithm

The red sashThe marker

The signal that divides pre-count carts from post-count carts is a messenger wearing a bright red sash (a marker). Because no one can overtake on the narrow road, when a red-sashed messenger walks through a gate, every cart sent down that track before the sash has already arrived.The signal that divides pre-record messages from post-record messages is a special marker message. Because channels are FIFO, when a marker arrives, every message sent on that channel before the marker has already arrived.

The messenger carries no jars, no orders, and no timestamps. Their sole job is to mark the boundary in a road track's stream of traffic.The marker carries no units, no orders, and no timestamps. Its sole job is to mark the boundary in a channel’s stream of messages.

The road into a harbour town in the morning: a messenger with a broad red sash walks past a cart loaded with jars, towards the masts and white houses ahead

The entire snapshot procedure comes down to one rule for sending a red sash and two cases for receiving one:The entire snapshot procedure comes down to one rule for sending a marker and two cases for receiving one:

The rule of sending

Count your storehouse, then send sashesRecord your state, then send markers

When a house counts its own storehouse, it immediately dispatches one messenger in a red sash down each of its two outgoing tracks, before sending any further carts.When a process records its own local state, it immediately sends one marker down each of its two outgoing channels, before sending any further messages.

Receiving · Case 1

First sash seen (not yet counted)First marker seen (not yet recorded)

If a red sash arrives at a house that has not yet counted its own storehouse, the house immediately counts its storehouse, records that this incoming track held 0 jars, and sends red sashes down its outgoing tracks.If a marker arrives at a process that has not yet recorded its state, the process immediately records its state, records that this incoming channel held 0 units, and sends markers down its outgoing channels.

Receiving · Case 2

Later sash seen (already counted)Later marker seen (already recorded)

If a red sash arrives at a house that has already counted its storehouse, the house closes its wax slate for that incoming track: the jars that arrived on that track between the house's own count and this sash are that track's recorded holding.If a marker arrives at a process that has already recorded its state, the process closes its record for that incoming channel: the units that arrived on that channel between the process’s own recording and this marker are that channel’s recorded holding.

Any house can initiate the count without coordinating beforehand, and no cart or mule ever has to stop. Scroll through the eleven steps below to watch a full count unfold while carts keep moving across the island.Any process can initiate the snapshot without coordinating beforehand, and no message ever has to stop. Scroll through the eleven steps below to watch a full snapshot unfold while messages keep moving.

1 · The morning1 · Business as usual

Carts on the roadMessages in transit

Trade is already underway: a cart of 30 jars is rolling from House 3 to House 2, and a cart of 10 jars is rolling from House 2 to House 3. Each colored circle on the road is a cart showing how many jars it carries.The system is already busy: a message carrying 30 units is travelling from P3 to P2, and a message carrying 10 units is travelling from P2 to P3. Each coloured circle on a channel is a message showing how many units it carries.

2 · Business goes on

Another cart leavesAnother message is sent

Before anyone starts a count, House 3 dispatches a second cart carrying 15 jars toward House 2, leaving 45 jars in House 3's storehouse.Before anyone starts a snapshot, P3 sends a second message carrying 15 units toward P2, leaving 45 units in P3’s local state.

3 · The rule of sending

House 1 starts the countP1 starts the snapshot

House 1 decides to start the inventory: it records its own storehouse stock (100 jars), opens wax slates to log incoming carts on its two incoming tracks, and immediately sends a red-sashed messenger (red dot) down each of its two outgoing tracks.P1 decides to start the snapshot: it records its own local state (100 units), opens records to log incoming messages on its two incoming channels, and immediately sends a marker (red dot) down each of its two outgoing channels.

4 · Business goes on

A cart behind the sashA message behind the marker

Right after sending its sashes, House 1 dispatches a cart of 20 jars to House 2. House 1's current stock drops to 80, but its recorded snapshot remains 100, and because nobody overtakes on the road, this cart travels behind the red sash.Right after sending its markers, P1 sends a message carrying 20 units to P2. P1’s current state drops to 80, but its recorded state remains 100, and because channels are FIFO, this message travels behind the marker.

5 · Receiving (Case 1)

House 2 receives its first sashP2 receives its first marker

First the 30-jar cart from House 3 rolls into House 2, raising House 2's stock to 100. Moments later, the red sash from House 1 arrives. Since House 2 has not counted yet, it records its storehouse at 100 (including those 30 jars), records 0 for the track from House 1, opens a slate for the track from House 3, and sends out its own red sashes.First the 30-unit message from P3 arrives at P2, raising P2’s state to 100. Moments later, the marker from P1 arrives. Since P2 has not recorded yet, it records its state as 100 (including those 30 units), records 0 for the channel from P1, opens a record for the channel from P3, and sends out its own markers.

6 · Behind the sash6 · Behind the marker

The 20-jar cart arrivesThe 20-unit message arrives

Now House 1's 20-jar cart reaches House 2. Because House 2 already closed the slate for the track from House 1 when the sash arrived, it does not add these 20 jars to the snapshot, avoiding a double-count, since House 1 already included them in its 100!Now P1’s 20-unit message reaches P2. Because P2 already closed the record for the channel from P1 when the marker arrived, it does not add these 20 units to the snapshot, avoiding a double-count, since P1 already included them in its 100!

7 · On the open slate7 · On the open record

A cart caught in transitA message caught in transit

Next, the 15-jar cart from House 3 rolls into House 2. Because House 2 has already counted its storehouse and has not yet seen a red sash from House 3, it logs these 15 jars on its open slate for the track from House 3.Next, the 15-unit message from P3 arrives at P2. Because P2 has already recorded its state and has not yet seen a marker from P3, it logs these 15 units on its open record for the channel from P3.

8 · Receiving (Case 1)

House 3 receives its first sashP3 receives its first marker

House 1's other red sash reaches House 3. House 3 immediately records its storehouse at 45 (which excludes the 15 jars it sent earlier), records 0 for the track from House 1, opens a slate for the track from House 2, and sends out its own red sashes.P1’s other marker reaches P3. P3 immediately records its state as 45 (which excludes the 15 units it sent earlier), records 0 for the channel from P1, opens a record for the channel from P2, and sends out its own markers.

9 · On the open slate9 · On the open record

Another cart caught in transitAnother message caught in transit

The 10-jar cart from House 2 rolls into House 3. Because House 3 has already counted its storehouse and is still waiting for House 2's red sash, it logs these 10 jars on its slate for the track from House 2.The 10-unit message from P2 arrives at P3. Because P3 has already recorded its state and is still waiting for P2’s marker, it logs these 10 units on its record for the channel from P2.

10 · Receiving (Case 2)

Every remaining sash arrivesEvery remaining marker arrives

The remaining red sashes reach their destinations, closing the open slates at all three houses. Every storehouse has been counted and every road slate is now closed.The remaining markers reach their destinations, closing the open records at all three processes. Every local state has been recorded and every channel record is now closed.

11 · The total

Nine numbers, added together

Adding the three recorded storehouses and six road slates gives jars, matching the exact jars on the island when the morning began! Not a single jar was counted twice, and not a single jar in transit was missed.Adding the three recorded states and six channel records gives units, matching the exact units in the system when the snapshot began! Not a single unit was counted twice, and not a single unit in transit was missed.

Notice how the wax slates and red sashes work together. Once a house counts its storehouse, it starts logging every cart arriving on an incoming track until that track's red sash walks through the gate. Those logged carts are precisely the ones that left the neighboring house before the neighbor counted its storehouse, and arrived after this house counted its own, in other words, the exact carts that were in transit across the boundary of the count!Notice how the channel records and markers work together. Once a process records its state, it starts logging every message arriving on an incoming channel until that channel’s marker arrives. Those logged messages are precisely the ones that were sent by the neighbouring process before it recorded its state, and arrived after this process recorded its own, in other words, the exact messages that were in transit across the boundary of the snapshot!

This guarantee relies on two physical facts about the ring road:* no overtaking on any track (FIFO delivery, so a sash cleanly separates pre-count carts from post-count carts), and every red sash eventually arrives. If bandits hijack a loaded cart during the count, that does not break the arrangement: a stolen cart vanishes from the island's stock just like goods sold away, whereas a red-sashed messenger carries no loot and always gets through to close the slate.This guarantee relies on two facts about the channels:* FIFO delivery (so a marker cleanly separates pre-record messages from post-record messages), and every marker eventually arrives. If a fault drops a message carrying units during the snapshot, that does not break the algorithm: a dropped message is simply removed from the system’s stock just like units spent elsewhere, whereas a marker carries nothing to lose and always gets through to close the record.

Because each house records its storehouse whenever the first sash reaches it, the three houses take their counts at different hours. The question left is why combining counts from different hours can never reproduce the auditors' double-counting mistake.Because each process records its state whenever the first marker reaches it, the three processes record at different times. The question left is why combining records from different times can never reproduce the double-counting mistake.

Consistent global states · Cuts

Cuts that hold and cuts that do not

To see why the nine numbers always fit together, we can draw the morning on a circular timeline: each house is a line radiating outward as time passes, and each cart is a curved arrow from the moment it leaves one house to the moment it reaches the next.To see why the nine numbers always fit together, we can draw the execution as a timeline: each process is a lane with real time running left to right, and each message is an arrow from the moment it is sent to the moment it is received.

Joining the three dots where the three houses recorded their storehouses forms a dashed loop called a cut. Everything inside the loop happened before the local count at that house; everything outside the loop happened after.Joining the three dots where the three processes recorded their states forms a dashed line called a cut. Everything to its left happened before the local recording at that process; everything to its right happened after.

A cart that starts inside the loop and lands outside it left before its sender counted and arrived after its receiver counted, which is completely natural and is caught on the receiver's road slate. The only thing that can ruin a cut is an inward-crossing cart: a cart sent after the sender counted its storehouse that somehow arrives before the receiver counts its own! Such a cart would include an effect inside the cut while leaving its cause outside, double-counting those jars in both storehouses.A message that starts before the cut and lands after it was sent before its sender recorded and arrived after its receiver recorded, which is completely natural and is caught on the receiver’s channel record. The only thing that can ruin a cut is an backward-crossing message: a message sent after the sender recorded its state that somehow arrives before the receiver records its own! Such a message would include an effect before the cut while leaving its cause after it, double-counting those units in both states.

Click any cart in the diagram below to see how it is counted under the red sash rules, and then switch to an uncoordinated count to see an inward-crossing cart ruin the total.Click any message in the diagram below to see how it is counted under the marker rules, and then switch to an uncoordinated snapshot to see an backward-crossing message ruin the total.

The morning's carts choose a cartThe execution’s messages choose a message

Each line tracks one house moving outward over time. The dashed loop (the cut) connects the moments when each house recorded its storehouse, and each numbered arc is a cart.Each lane is one process, with real time running left to right. The dashed line (the cut) runs through the moment each process recorded its state, with what came before shaded to its left, and each numbered arrow is a message.

No cart can ever cross the cut inward when the houses use red sashes, because the moment a house counts its storehouse, it sends a red sash down every outgoing track before sending any post-count cart. Since no cart can overtake the sash on the narrow road, the red sash always reaches the neighboring house first, forcing that neighbor to count its storehouse before the post-count cart can arrive!No message can ever cross the cut backward when the processes use markers, because the moment a process records its state, it sends a marker down every outgoing channel before sending any post-record message. Since no message can overtake the marker on a FIFO channel, the marker always reaches the neighbouring process first, forcing that neighbour to record its state before the post-record message can arrive!

So the nine numbers form a completely consistent cut with no double-counting and no missing carts. Yet because the three houses counted at different times, it is not clear what moment of the morning this snapshot describes.So the nine numbers form a completely consistent cut with no double-counting and no missing messages. Yet because the three processes recorded at different times, it is not clear what moment of the execution this snapshot describes.

Proof · no message ever crosses the snapshot cut inwardProof · no message ever crosses the snapshot cut backward

Marker-sending rule: a process records its local state and immediately sends a marker on every outgoing channel before sending any further messages. Marker-receiving rule: upon receiving a marker, a process that has not yet recorded its state does so immediately; a process that has already recorded closes that incoming channel's state. Channels are FIFO and every marker eventually arrives. Claim. No message sent after its sender recorded is ever received before its receiver recorded.

  1. Call an event at a house early (inside the cut) if it occurred before that house recorded its storehouse, and late (outside the cut) if it occurred after.Call an event at a process early (before the cut) if it occurred before that process recorded its state, and late (after the cut) if it occurred after.
  2. Suppose for contradiction that some cart crosses the cut inward: it is dispatched late at House i and arrives early at House j.Suppose for contradiction that some message crosses the cut backward: it is dispatched late at process i and arrives early at process j.
  3. Because the cart was dispatched late, House i had already recorded its storehouse. By the marker-sending rule, House i sent a red sash down the track to House j before dispatching that cart.Because the message was dispatched late, process i had already recorded its state. By the marker-sending rule, process i sent a marker down the channel to process j before dispatching that message.
  4. Because the track from House i to House j is FIFO, the red sash must arrive at House j before the cart does.Because the channel from process i to process j is FIFO, the marker must arrive at process j before the message does.
  5. By the marker-receiving rule, House j records its storehouse no later than the arrival of that red sash.By the marker-receiving rule, process j records its state no later than the arrival of that marker.
  6. Therefore, House j had already recorded its storehouse before the cart arrived, meaning the cart's arrival was late, not early. This contradiction proves that no cart can cross the cut inward.∎Therefore, process j had already recorded its state before the message arrived—meaning the message's arrival was late, not early. This contradiction proves that no message can cross the cut backward.∎
The ruined round wall on the crown of the mountain, seen from above, with scrub and cypresses on the slopes around
What the snapshot represents

A morning nobody lived throughA state the system never held

Remarkably, the nine numbers may describe a state of the island that never existed at any single moment in real time!Remarkably, the nine numbers may describe a global state that never existed at any single moment in real time!

To see how, suppose House 1 records its storehouse first, and House 2 records a little while later. Right after House 1 records, it sells 40 jars of oil into its own port town. Soon after, still before House 2 has recorded, House 2 mills 80 measures of barley into flour. Neither local action touches a road, a cart, or a sash.To see how, suppose P1 records its state first, and P2 records a little while later. Right after P1 records, it spends 40 units on its own (an internal step). Soon after, still before P2 has recorded, P2 converts 80 units of one resource into another. Neither local action touches a channel, a message, or a marker.

Look at what the combined snapshot records: it captures House 1 before the oil sale (still holding the 40 jars), and House 2 after the milling (with the barley already turned into flour). Yet in real time under the sun, the island was never in that combined state: while House 1 still held the 40 jars, the barley had not yet been milled; by the time the barley was milled, the 40 jars were already gone!Look at what the combined snapshot records: it captures P1 before the spend (still holding the 40 units), and P2 after the conversion (with the units already converted). Yet in real time, the system was never in that combined state: while P1 still held the 40 units, the conversion had not yet happened; by the time of the conversion, the 40 units were already gone!

Try swapping the order of those two independent local events in the interactive below to see how the recorded snapshot relates to the morning the houses actually lived through.Try swapping the order of those two independent local events in the interactive below to see how the recorded snapshot relates to the execution the processes actually lived through.

The same four entries in two ordersThe same four events in two orders

The morning as livedThe execution as it happened
A morning the count could have livedAn execution the snapshot could have seen

The snapshot is still trustworthy although it describes a state the island never actually passed through. To state the guarantee precisely, call the island's true state when the first sash went out the start, the nine-number snapshot the recorded island, and the island's true state when the last slate closed the end.The snapshot is still trustworthy although it describes a state the system never actually passed through. To state the guarantee precisely, call the system’s true state when the first marker went out the start (Sbegin), the nine-number snapshot the recorded state (S*), and the system’s true state when the last channel record closed the end (Send).

Chandy and Lamport proved two things: first, the recorded island can be reached from the start simply by running the pre-cut events in a causally valid order; second, the end can be reached from the recorded island by running the remaining post-cut events.Chandy and Lamport proved two things: first, the recorded state can be reached from the start simply by running the pre-cut events in a causally valid order; second, the end can be reached from the recorded state by running the remaining post-cut events.

In other words, the recorded island lies on a completely valid execution path from the start of the count to the end! Because the oil sale at House 1 and the barley milling at House 2 occurred on opposite sides of the mountain with no slips between them, they were concurrent (unrelated)*, so swapping their order changes nothing about any house's final state or any chain of cause and effect.In other words, the recorded state lies on a completely valid execution path from the start of the snapshot to the end! Because the spend at P1 and the conversion at P2 occurred with no messages between them, they were concurrent (unrelated)*, so swapping their order changes nothing about any process’s final state or any chain of cause and effect.

The snapshot captures a valid state the island could have passed through between the start and the end of the count, which leaves the matter of what questions such a snapshot can reliably answer.The snapshot captures a valid state the system could have passed through between the start and the end of the snapshot, which leaves the matter of what questions such a snapshot can reliably answer.

Proof · the recorded snapshot lies on a valid execution path

Let Sbegin be the global state when the snapshot began, S* the recorded snapshot state, and Send the global state when the final channel record closed. Theorem. There exists a causally valid permutation of the actual events between Sbegin and Send that passes directly through S*: Sbegin →* S* →* Send.

  1. List the actual sequence of events that occurred on the island between Sbegin and Send: e₁, e₂, …, em. Classify each event as early (occurring at a house before that house recorded its state) or late (occurring after that house recorded its state).List the actual sequence of events that occurred in the system between Sbegin and Send: e₁, e₂, …, em. Classify each event as early (occurring at a process before that process recorded its state) or late (occurring after that process recorded its state).
  2. In the real-time execution, some late event at one house may occur before an early event at another house. Suppose a late event ei is immediately followed by an early event ei+1.In the real-time execution, some late event at one process may occur before an early event at another process. Suppose a late event ei is immediately followed by an early event ei+1.
  3. Claim: ei and ei+1 can be swapped without changing any process or channel state. First, they cannot belong to the same house, because at any single house all early events precede the recording and all late events follow it. Second, ei cannot have caused ei+1, because that would require a message sent after recording (late) to arrive before recording (early), which our cut-consistency proof ruled out. Thus ei and ei+1 are independent events at different houses and commute.Claim: ei and ei+1 can be swapped without changing any process or channel state. First, they cannot belong to the same process, because at any single process all early events precede the recording and all late events follow it. Second, ei cannot have caused ei+1, because that would require a message sent after recording (late) to arrive before recording (early), which our cut-consistency proof ruled out. Thus ei and ei+1 are independent events at different processes and commute.
  4. Repeatedly swap adjacent (late, early) pairs until all early events precede all late events.
  5. Executing all early events starting from Sbegin brings every house to the exact state it had when it recorded, and leaves on each channel the exact messages sent early and received late—which is precisely the recorded snapshot S*. Executing the remaining late events from S* then reaches Send.∎Executing all early events starting from Sbegin brings every process to the exact state it had when it recorded, and leaves on each channel the exact messages sent early and received late—which is precisely the recorded snapshot S*. Executing the remaining late events from S* then reaches Send.∎
Detecting stable properties

What such a total is good forWhat such a snapshot is good for

Because a snapshot describes a morning nobody actually lived through, it cannot answer questions about fleeting moments, such as whether House 2 held 300 jars at the exact instant a ship dropped anchor. Without a shared hour, no count across the houses can speak for a single instant.Because a snapshot describes a state the system may never have held, it cannot answer questions about fleeting moments, such as whether P2 held 300 units at the exact instant a request arrived. Without synchronized clocks, no distributed snapshot can speak for a single wall-clock instant.

Instead, the snapshot is built to answer questions about settled properties (stable properties): conditions that, once they become true, stay true forever. If we look only at the closed circle of trade between the three houses (setting aside outside port-town sales), classic examples include:Instead, the snapshot is built to answer questions about stable properties: conditions that, once they become true, stay true forever. If we look only at the closed system of the three processes (setting aside any outside traffic), classic examples include:

  • Everything delivered (Termination): Every cart has arrived and all three houses have finished their work.Termination: Every message has arrived and all three processes have finished their work.
  • Standstill (Deadlock): Every house is waiting for a cart from another house before it can send one of its own.Deadlock: Every process is waiting for a message from another process before it can send one of its own.
  • Exhaustion of supply: A vintage has run out across the island, and no trade between the houses can create more.Exhaustion of a resource: A resource has run out across the system, and no exchange between the processes can create more.
  • Deficit (Data loss / theft): Jars have disappeared from the closed trading loop, as when bandits seize a cart on the road.Deficit (data loss): Units have disappeared from the closed system, as when a fault drops a message carrying them.

For any settled property, the recorded snapshot gives an ironclad answer about the real island: if the property holds in the snapshot, it definitely holds on the real island by the time the count finishes (since the end state is reachable from the snapshot, and once true, a settled property stays true). Conversely, if the property does not hold in the snapshot, it definitely did not hold when the count began (since the snapshot is reachable from the start state).For any stable property, the recorded snapshot gives an ironclad answer about the real system: if the property holds in the snapshot, it definitely holds in the real system by the time the snapshot finishes (since the end state is reachable from the snapshot, and once true, a stable property stays true). Conversely, if the property does not hold in the snapshot, it definitely did not hold when the snapshot began (since the snapshot is reachable from the start state).

That directly solves the houses' bandit problem! By running a red-sash count on a day with no port-town buying or selling, normal shipments merely move jars from one of the nine places to another without changing the sum. Test the three cases below to see what the snapshot tells the houses when bandits strike.That directly solves the lost-units problem! By running a marker snapshot while no units enter or leave the system, normal messages merely move units from one of the nine places to another without changing the sum. Test the three cases below to see what the snapshot tells the processes when a fault strikes.

Have the bandits robbed us? a day with no buying or sellingHave units been lost? no units enter or leave

The account scrolls say the three houses should hold 270 jars between them. Choose when a bandit ambushes a cart of 30 jars on the road.The books say the three processes should hold 270 units between them. Choose when a fault drops a message carrying 30 units.

Because the red-sash count captures every jar in the storehouses and every jar in transit on the road, a cart that is merely slow turns up on a wax slate and is counted, whereas a stolen cart vanishes from the sum. If the nine numbers fall short of the account scrolls, the houses know for certain that bandits have robbed them by the time the count ends; if the nine numbers match the scrolls, they know for certain that not a single jar had been stolen when the count began.Because the marker snapshot captures every unit in the local states and every unit in transit on the channels, a message that is merely slow turns up on a channel record and is counted, whereas a dropped message drops out of the sum. If the nine numbers fall short of the expected total, the processes know for certain that units have been lost by the time the snapshot ends; if the nine numbers match the books, they know for certain that not a single unit had been lost when the snapshot began.

The decision rule for stable properties, in the paper's terms

A global predicate y is stable if for every global state S where y(S) is true, y(S') remains true for all states S' reachable from S. Let Sbegin →* S* →* Send be as in the reachability theorem. Decision rule. Evaluate the stable predicate y on the recorded snapshot S*:

  1. If y(S*) is true: Since Send is reachable from S* and y is stable, y(Send) must be true. The property definitely holds in the real system when the snapshot completes.
  2. If y(S*) is false: Since S* is reachable from Sbegin, if y(Sbegin) had been true, stability would force y(S*) to be true as well. Thus y(Sbegin) must be false: the property definitely did not hold when the snapshot began.∎

Examples of stable properties include distributed termination, deadlock, loss of tokens or conserved quantities (deficit), and unreachability of objects (garbage collection).

A running distributed system can record a consistent global snapshot without ever pausing its work, capturing a state it may never have inhabited at one instant, but could have passed through.

Because that recorded snapshot lies on a valid causal path from the start of the count to the end, it reliably settles every question whose answer, once true, stays true.

The Chandy–Lamport snapshot algorithm is the foundation for taking a consistent record of a system that keeps running.

Setting Three Houses Keeping Order

The system, stated formally

The system consists of a finite set of processes (the houses) connected by directed channels (the six one-way tracks of the ring road). Each channel delivers messages in the exact order sent (FIFO), without corruption, after an arbitrary finite delay, and never loses a marker. (The paper’s channels lose nothing; here a bandit may take a cart off a track, which removes its goods from the count like a sale, and the argument needs only FIFO order and that every marker arrives.) There is no shared global clock, and no process can directly inspect another process's memory or a channel's in-flight messages. A global state consists of the local state of every process together with the sequence of messages currently in transit on every channel.The system consists of a finite set of processes connected by directed channels. Each channel delivers messages in the exact order sent (FIFO), without corruption, after an arbitrary finite delay, and never loses a marker. (The paper’s channels lose nothing; here a fault may drop a message, which removes its units from the count like a spend, and the argument needs only FIFO order and that every marker arrives.) There is no shared global clock, and no process can directly inspect another process's memory or a channel's in-flight messages. A global state consists of the local state of every process together with the sequence of messages currently in transit on every channel.

The paper behind this book

The paper behind this book. K. Mani Chandy and Leslie Lamport, “Distributed Snapshots: Determining Global States of Distributed Systems,” ACM Transactions on Computer Systems 3, 1 (February 1985), 63–75. Covers the formal definition of global state, the marker-sending and marker-receiving rules, the reachability theorem, and stable property detection.

The ideas. In a distributed system, no single observer can view the state of all processes and channels at the same instant. Freezing the system and waiting for all channels to drain is expensive—and knowing when a channel has drained already requires sending an end-of-stream marker. Chandy and Lamport showed how those same markers can capture a consistent global snapshot while normal computation continues without interruption.

Whenever a process records its local state, it immediately sends a marker down every outgoing channel before sending any further application messages. Because channels are FIFO, markers cleanly partition each channel's message stream into pre-snapshot and post-snapshot messages. A receiving process records the messages arriving on each incoming channel between its own state recording and the arrival of that channel's marker, guaranteeing that no message crosses the snapshot cut inward (sent after the sender recorded, yet received before the receiver recorded).

Although the recorded snapshot S* may never have occurred at any single instant of physical time, it is causally consistent: reachable from the state Sbegin when the snapshot started, and able to reach the state Send when the snapshot finished. That makes S* sufficient to detect any stable property—such as deadlock, termination, garbage collection, or token loss—whose truth is preserved under all future steps.

Chandy, K. M., and Lamport, L. Distributed snapshots: determining global states of distributed systems. ACM Trans. Comput. Syst. 3, 1 (1985), 63–75.