How it’s built

Why a single-writer object needs no consensus

The bakery never runs a consensus protocol, and two visitors racing for the last place in a pickup slot still get one place and one refusal. This is why that works, what it costs, and where the bakery pays.

What consensus is for

Suppose the count of places in the 10:00 pickup slot were kept on three servers, so that losing one loses nothing. Each server can take a hold. Two tabs press Place order at the same moment; one request reaches the first server and the other the third, and each sees a free place. Both say yes, and the slot is over its capacity. To stop that, the copies have to agree on one order of writes before any of them answers.

That agreement is what a consensus protocol provides. Raft keeps one log, the ordered list of every write, on several servers. One server leads: it takes every write, copies it to the others, and calls it committed once a majority holds it. The paper that set it out, In Search of an Understandable Consensus Algorithm (USENIX ATC 2014), is about making that safe whatever the network does, and the price is plain in its design: a leader to elect, a majority to reach on every write, and a minority that cannot make progress at all. The Raft Lab lets you crash its servers, split its network and watch its safety hold.

Consensus answers one question: how do several copies of the same state stay one? The bakery avoids the question by keeping one copy.

What a Durable Object is instead

A Durable Object is a named instance of a class, running on Cloudflare. As Cloudflare’s documentation describes it on 2026-11-06, there is one instance for a name in the whole world, it runs in a single location, it is single-threaded, and its storage sits with it: private to that instance, transactional and strongly consistent. Writes made with no wait between them are committed together or not at all, the runtime holds new requests back while the object’s code runs, and it holds the object’s answers back until its writes are stored.

So the bakery gives each thing that must never be double-booked an object of its own. The places in a day are the Schedule object for that sandbox and that day. An order is its own Order object, and a catering job its own CateringEvent.

What that buys

Every write to a day’s places goes through one object, one at a time, so the object itself is the order of writes, and there is nothing to agree on. When two tabs race for the last place at 10:00, both requests reach the same Schedule object. The first hold is decided and committed in one step. The second runs after it, finds the slot full, and is refused, with the next free slot named. One reservation and one refusal, with no lock service, no leader and no quorum.

The same is true of an order, so two tabs pressing the same button on the kitchen board cannot disagree about where the order is, and of a catering job, which moves one transaction at a time.

What it gives up

One copy is a choice with costs, and they are the costs consensus exists to remove.

Where the bakery pays

The last cost shapes the whole design. Because no transaction spans two objects, every object writes its events to an outbox in the same transaction as its state, and the Queue carries them to the others at least once, each subscriber skipping what it has already applied: the outbox, the Queue and the dead letters. Because a catering job touches the Schedule, Billing and Stripe over weeks, it is a saga by alarm: a chain of single-object transactions, each started by an event or a timer, and undone by steps of its own rather than a rollback. And because throughput is per object, the bakery divides by what it protects: a Schedule and a Dispatch per sandbox and day, an Order per order, and everything per sandbox, so no object carries more than one visitor’s bakery.

What the bakery does not do is replicate. If the object that holds a day’s places cannot be reached, that day’s checkout waits; it never guesses. For a made-up bakery with one kitchen that is the right trade: a few seconds of waiting, rarely, for never selling the same place twice and never running a consensus protocol to make sure.

Sources

Back to the Raft principle on How it’s built, to the decision that chose it, ADR 0003, or to the lab.