Real-Time Backend
Edge Computing
A user in Tokyo sees a colleague's cursor with 250ms lag. Collaborative editing feels sluggish. Moving WebSocket to the Cloudflare edge cut it to 15ms. The difference between 'awkward' and 'unnoticeable'.
- Figma moved multiplayer cursors onto Cloudflare Workers; latency dropped from 80-120ms to 15-30ms for users in Europe and Asia
- Cloudflare Durable Objects billing: 0.15 USD per million WebSocket messages vs an equivalent K8s cluster, 3-5x cheaper thanks to automatic scale-to-zero
- Discord uses edge nodes for voice/video signaling; the initial WebRTC connection setup latency dropped from 800ms to 150ms
Edge computing for real-time: why it matters
A user in Tokyo connects to a WebSocket server in us-east-1. Round-trip time: 170ms. Every chat message adds 340ms of latency (round trip). In Slack this is unnoticed because messages are sparse. In a multiplayer game it is a disaster.
Edge computing brings compute closer to the user. Cloudflare Workers run at 300+ points of presence around the world. A user in Tokyo connects to a Tokyo edge node: latency is 5-10ms instead of 170ms.
But edge has a fundamental problem: two users in different cities want to chat in the same room. Their edge nodes are different. How do you sync state between them?
In 2022 Figma moved multiplayer cursors onto Cloudflare Workers. Cursor movement latency dropped from 80-120ms to 15-30ms for users in Europe and Asia. That made collaborative editing feel subjectively instant.
What is the main problem of edge computing for synchronous real-time interactions?
Cloudflare Durable Objects: state at the edge
A Durable Object (DO) is a singleton object that lives at one specific Cloudflare point of presence. It has persistent storage and can hold WebSocket connections. Multiple Workers from different regions can reach the same DO via RPC.
For a chat room: each room is one DO. Every user in that room connects their Worker to that single DO. The DO fans messages out to all connected Workers, which deliver them to users over their local connections.
How do Durable Objects solve the problem of state synchronization between edge nodes?
State management at the edge: persistent storage and hibernation
A DO has built-in transactional key-value storage. It is not Redis: it is local storage accessible only to that specific DO. Operations are synchronous from the DO's logical viewpoint but asynchronous under the hood.
Hibernation is the key cost optimization. If a DO has no active WebSocket connections, Cloudflare evicts it from memory. On the next request it is restored from storage. Without hibernation, a DO would consume resources continuously.
What happens to a Durable Object during hibernation?
Real latency numbers: when edge helps and when it does not
Edge does not always help. The latency profile depends on the type of interaction. Local actions (cursor movement, typing indicator) win. Global ones (a message in an international chat) are less predictable.
Cursor movement and typing indicators are the ideal case for edge: they matter only to users in the same region (in practice, often the same office). For chat messages you need global fan-out, and the edge advantage is smaller.
Cloudflare Durable Objects billing: USD 0.15 per million WebSocket messages plus storage. For most applications that is 3-5x cheaper than an equivalent K8s cluster thanks to automatic scale-to-zero. But at very high load (100M+ messages/day) K8s can be cheaper.
Edge computing always reduces latency compared with a centralized server
Edge reduces latency only for local interactions; for global fan-out the win is smaller, and there are cases where the edge adds a hop
If a Durable Object lives in us-east-1 (because the first connecting user was there) but the rest of the users are in Asia, they still pay for the trans-ocean hop to the DO. The edge Worker adds a hop instead of removing one.
Which scenario gets the biggest latency win from edge computing?
Summary
- Edge computing cuts latency for local interactions by 10-20x; the win shrinks for global fan-out
- Durable Objects are a singleton on one edge node; Workers from different regions reach them via RPC
- Hibernation evicts a DO from memory when no connections remain and restores from storage on the next request
- Cursor movement and typing indicators are the ideal edge case; global chat sees a smaller win
Related topics
Edge computing overlaps with several areas of distributed systems
- CAP theorem — Durable Objects pick CP: singleton guarantees consistency, availability drops if the node is unreachable
- Infrastructure (K8s) — Edge as an alternative to K8s for WebSocket: a different trade-off between control and operational complexity
- Cost Optimization — Edge per-message billing vs K8s per-resource billing - different models with different break-even points
- Feature Flags — Rollout at the edge: Cloudflare Workers support feature flags via Workers KV
Вопросы для размышления
- How do you choose the region for a Durable Object for a room when users are evenly distributed worldwide?
- What happens to a DO if the Cloudflare edge node in its region goes down - is there automatic failover?
- When should you pick a traditional K8s cluster over Cloudflare Durable Objects for WebSocket?