How an order becomes a coffee

CloudBrew runs entirely on Cloudflare's developer platform. The diagram is live: a link lights up only when that service has really just done something for an order.

PhoneWorkersD1QueuesWorkflowsR2ScreensWorkers KVWorkers AIDurable ObjectsCoffee machine

Durable Objects

One machine, one at a time

Two single-instance objects. CoffeeMachine owns the appliance: it lets one order brew at a time, waits for a cup, and never repeats a start it is unsure about. OrderHub holds every screen's WebSocket and replays what a reconnecting screen missed.

There is exactly one coffee machine. A Durable Object is exactly one instance with its own storage — the natural owner of a shared physical thing.

Just now

Nothing yet. Place an order and watch this fill up.

Durable Objects documentation ↗

The code that does it — an excerpt of what is running

src/server/machine/coordinator.ts
// Write the intent down before the command leaves. If this object is
// restarted in the middle of the request it comes back knowing that a
// command may be on its way, and looks at the machine instead of sending
// another one.
const sentAt = Date.now();
slot.phase = "starting";
slot.note = null;
slot.held = false;
slot.commandAt = sentAt;
slot.commandOutcome = null;
slot.interrupted = false;
slot.blind = false;
slot.lastProofAt = sentAt;
this.proofChannel = this.channel();
slot.counterBaseline = counterSum(this.state.appliance);
slot.deadline = sentAt + this.scale(START_BLIND_STEP_MS, settings);
slot.hardDeadline = sentAt + this.scale(START_HARD_MS, settings);
slot.evidence = { commandSentAt: nowIso(sentAt), ...(slot.mode === "simulation" ? { simulated: true } : {}) };
await this.save("slot");

// Sent exactly once. Whatever the answer, it is never sent again for
// this clearance: only the machine's own reports move the order on.
const outcome = await this.sendStart(slot, settings, sentAt);

Follow one order

Or say it out loud

Guests can also call McLovin, the voice barista, from the ordering page and talk their way to a coffee. The order still travels the path above.

  1. RealtimeThe callThe phone sends its microphone to Cloudflare's Realtime network over WebRTC and hears McLovin the same way. Cameras go from guest to guest; McLovin only listens.
  2. Durable ObjectsThe roomA second Worker, the voice agent, keeps one Durable Object per call: who is in it, whose turn it is to speak, and the conversation. The network hands it each microphone and carries back what it says.
  3. Workers AIEars, words and a voiceSpeech is recognised as it is spoken, a model answers in a sentence or two, and a voice model says it. Orders are not left to the model: they are read back and confirmed by fixed rules.
  4. Service bindingsThe orderThis Worker joins the call for the guest, so the agent's join code never reaches a phone. With the agent's order desk connected, a spoken “yes” places the order through the same API as the menu; until then McLovin takes practice orders and the phone offers the drink to place by hand.

What it promises

There is one real machine and a room full of phones. These are the rules that keep that safe.

One order per tap
A double tap, a retry or a redelivered queue message never becomes a second order or a second drink.
One drink at a time
A unique index in D1 and a single Durable Object both guarantee that only one order can hold the machine.
No cup, no coffee
Nothing is brewed until a person confirms that an empty cup is under the spout.
Never start twice on a guess
If a start command gets no clear answer it is not repeated. CloudBrew watches what the machine does instead.
Finished means the machine said so
An order is ready when the machine reports that the program ran and ended — not when a timer runs out.