Cloudflare Durable Objects
Implement a production-ready Cloudflare Durable Object in TypeScript from a spec, and get it right where most implementations get it wrong. Durable Objects combine compute with strongly-consistent, co-located storage in globally-unique, single-threaded…
Runs on Jetty's managed sandbox. No setup. Free for your first 10 runs.
Real runs, real outputs.
ChatRoom — WebSockets + persistent counter + idle cleanup
A multi-room chat DO: WebSocket Hibernation API for broadcast, a SQLite-backed message counter incremented with an atomic INSERT ... ON CONFLICT upsert, and a…
6 steps · start to finish.
- 1Step 1
Environment Setup
▶mkdir -p "{{results_dir}}" S="{{spec}}" [ -n "$S" ] && [ "$S" != "{{spec}}" ] || { echo "ERROR: no spec provided"; exit 1; } echo "Building Durable Object for spec (first 120 chars): ${S:0:120}" - 2Step 2
Understand the Spec
▶Identify, from the spec: the DO's state (what must persist), any scheduling (→ alarm, not setTimeout), any concurrency-sensitive mutations (→ atomic SQL / blockConcurrencyWhile), any WebSocket usage…
- 3Step 3
Implement `durable_object.ts`
▶Write the full TypeScript implementation. Apply the Rules, the API, and the Gotchas above. In particular: persist anything that must survive idle; schedule with setAlarm; make counters atomic; use…
- 4Step 4
Configure `wrangler.jsonc`
▶Write the Workers config: the DO binding and a new_sqlite_classes migration (unique, sequential tag). Set compatibility_date >= 2024-04-03.
- 5Step 5
Self-Review Against the Gotchas
▶Write {{results_dir}}/self_review.md: for each relevant gotcha, state how the implementation guards against it (or why it does not apply). Be specific — quote the line that handles it. If you find a…
- 6Step 6
Evaluate & Validate
▶Evaluate the implementation against the gotcha checklist, then write {{results_dir}}/validation_report.json: