◉RORK LABJP
●MCP — Rork now lets you add and manage your own MCP servers inside Plugins (11/21)●2.5 ROUTE — From 12/1, apps calling gemini-2.5-flash are routed to 3.5 Flash-Lite and billed at its rates (9 days left)●CHANNEL — Users report Android notification channel reads and writes failing in Expo Go●NEW — New: three clues to check before replying to a stuck-on-splash review●EXPORT — Export your projects before you downgrade or cancel a plan●SONNET 4.5 — Apps that call Sonnet 4.5 through the API should switch before it retires on 11/30●MCP — Rork now lets you add and manage your own MCP servers inside Plugins (11/21)●2.5 ROUTE — From 12/1, apps calling gemini-2.5-flash are routed to 3.5 Flash-Lite and billed at its rates (9 days left)●CHANNEL — Users report Android notification channel reads and writes failing in Expo Go●NEW — New: three clues to check before replying to a stuck-on-splash review●EXPORT — Export your projects before you downgrade or cancel a plan●SONNET 4.5 — Apps that call Sonnet 4.5 through the API should switch before it retires on 11/30
Articles/Dev Tools
⬡ Dev Tools/2026-04-29Advanced

Building a Real-Time Collaborative App Backend with Rork and Cloudflare Durable Objects — Full Implementation Guide

A production-grade walkthrough for adding a self-hosted real-time collaboration backend to your Rork app using Cloudflare Durable Objects. Covers WebSocket lifecycle, hibernation-aware sessions, optimistic updates from React Native, and cost-aware design patterns — without depending on Liveblocks or Yjs hosting.

Rork620CloudflareDurable ObjectsWebSocketReal-timeBackend6

✦ Premium Article

"I want to build a whiteboard or polling feature in Rork, but Liveblocks pricing does not scale with my user base." This is a question I hear constantly from indie developers right now. Hosted services like Liveblocks and Yjs are pleasant to start with, but the moment user counts grow, your monthly bill jumps in ways that hurt even apps that are already monetized.

I learned this the hard way. I built a small voting app on Rork and bolted Liveblocks onto it. The first month came in at three times my projection, and that was on a free-tier app. Over the next six months, I migrated everything to Cloudflare Durable Objects. The result was about a tenfold reduction in monthly cost, and latency actually felt snappier from Tokyo, where most of my users live.

This guide distills everything I learned from that migration. We will cover the conceptual model of Durable Objects, the WebSocket client you embed in your Rork app, and the operational pitfalls that bit me — all with code you can paste into a real project.

Why Durable Objects, Versus Other Options

There are several ways to build a real-time backend, and choosing without understanding the trade-offs hurts later. Here is how I think about it.

  • Liveblocks, PartyKit, Pusher: Beautiful SDKs and a fast on-ramp, but priced on monthly active connections. If your app is free or freemium and you have many concurrent collaborators, the math becomes unfriendly very quickly.
  • Supabase Realtime: Subscribes to Postgres changes. Excellent for persisting structured state, but ill-suited for the high-frequency, low-latency events that real-time collaboration generates (cursor positions, presence pings, in-progress strokes).
  • Self-hosted WebSockets on Node.js plus Redis: Full control, but the operational burden — autoscaling, sticky sessions, regional fallback — is realistically more than a solo developer wants to take on.
  • Cloudflare Durable Objects: Combines a WebSocket server and persistent storage into a single addressable object that runs at the edge. Pricing is based on object execution time, which makes forecasts predictable.

The single feature that made me commit to Durable Objects was the per-state object scoping. Every whiteboard URL, every chat room, every poll can map to its own object. Only the participants of that room ever route to that instance. When the room is idle, the object hibernates and you stop paying. This matches the cost shape of an indie app: you pay precisely for the rooms that are active right now.

The Architecture at a Glance

Before writing code, it helps to picture the request flow.

  1. The Rork app holds a roomId (for example, the slug of a whiteboard) and opens a WebSocket against /ws/:roomId on the Worker.
  2. The Worker translates that roomId into a Durable Object instance, then forwards the upgraded connection to it.
  3. The Durable Object accepts the connection via state.acceptWebSocket(), registering it as a hibernation-aware WebSocket.
  4. Messages from clients are mutated against in-memory state and broadcast to the other connections attached to the same object.
  5. Anything that needs to outlive a single session (drawn shapes, chat history) is written to the object's SQLite storage.

Because Cloudflare guarantees one logical instance per object ID worldwide, you also get free message ordering within a room. There is no need for an external lock or queue.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦You can now build a real-time collaboration backend on Cloudflare Durable Objects without paying for Liveblocks or hosted Yjs services
✦You will master production patterns for WebSocket lifecycle, reconnection, and state synchronization, with code that copy-pastes into a real Rork project
✦You will be able to design a scope-per-state cost architecture so collaborative apps (whiteboards, polls, chat rooms) stay cheap to operate at scale
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ Dev Tools2026-05-03
How I Cut My Rork App's AI Costs from $350 to $35/Month with Cloudflare AI Gateway
The default AI Gateway cache key is built from the request you actually send. Here is why prompt normalization silently does nothing, how to wire it in with cf-aig-cache-key, and the Workers and React Native code I run in production.
⬡ Dev Tools2026-11-19
New Wallpapers Showed Up Everywhere Except the Filters: Ship the Count and the Category Lists Together
I added 67 wallpapers in one batch. They appeared in the full list and in New, but not under a single category filter, because I had raised the ID limit and forgotten to ship the category lists. Here is a pre-bump check, a client-side way to spot silent fallbacks in an Expo app, and a post-release count against the origin.
⬡ Dev Tools2026-11-04
Catching the Few Seconds Before Streaming Audio Starts: A Loading State and a Timeout
You tap play and nothing happens for a moment. Here is how I model that gap with expo-audio: a requested flag, a 400ms delayed spinner, and an 8-second timeout.