Keep Nigel Alive
How Nigel is built
Nigel is a tardigrade that a whole room keeps alive from their phones. He is also the smallest complete production system: he holds state, answers in real time, uses AI, sits behind a security check, and can go down. All of that is one program, one config file, one deploy on the Cloudflare Developer Platform.
In plain words
- Your phone opens one live line to the nearest Cloudflare data centre.
- A tiny program there passes your tap to Nigel — one small computer that is Nigel, with his own memory. There is exactly one of him in the world.
- He updates his memory (a real database inside him, no network hop) and sends the new state back to every phone in the room.
- When his mood changes, an AI writes his words and paints his face. Every AI call goes through a meter that logs the cost and caches repeats.
- Let him dry out and he sleeps: his heartbeat stops and nothing is billed until someone taps. Let him starve and he dies, and only the room, together, can bring him back.
The words on the screens
- Worker
- The one program. It runs in the Cloudflare data centre nearest whoever is calling it. No server to keep warm.
- Durable Object
- A small always-there computer with its own memory, addressed by name. Nigel is one. The relays that hold the phones' lines are four more. One customer, one object; a million customers, a million objects.
- SQLite in Nigel
- His memory: a real database living inside the object. Saving takes microseconds and survives a redeploy, a sleep, and a restart.
- Alarm
- His heartbeat timer. The object wakes itself every few seconds to age him, and deletes the timer when he sleeps.
- Workers AI · AI Gateway
- Models on Cloudflare GPUs (Llama writes, FLUX paints), billed per use. The gateway is the meter: cost, cache, and a spend cap.
- Queues · D1 · Analytics Engine
- Every tap is also written to a diary (D1) via a queue, off Nigel's critical path, and metered (Analytics Engine).
- Workflows
- The durable death-to-revival window. It waits, for as long as it takes, for the room to vote him back.
- Turnstile
- The silent human check at the door. Security on the same platform, same bill, no puzzle.
- R2 · KV
- His photo album, and the presenter's settings.
Build your own
The whole of Nigel is about 4,900 lines in 19 files, one wrangler.jsonc, and one command:
npm create cloudflare@latest my-pet cd my-pet npx wrangler deploy
Start here:
- Durable Objects — the one-object-per-thing idea that makes Nigel possible.
- Workers AI and AI Gateway — his words, his face, and the meter.
- Workflows — the durable revival window.
- Architecting on Cloudflare — Jamie Lord's book, where the thinking behind this comes from.
What is real, and what is an estimate
Your round trip, the room count, where your phone entered the network, where Nigel's object runs, the deployed version, each model call's duration, and the AI Gateway cache HIT/MISS are all real. The money is an estimate from the public price list, and says so. The AWS map is a fair sketch of one reasonable design, not a quote.