The Edge Mesh
Technical Overview
Section titled “Technical Overview”CF Messenger reimagines real-time chat by pushing it entirely into Cloudflare’s edge mesh. Durable Objects, Workers, and WebSockets collaborate to deliver an MSN-inspired UX while showcasing how stateful coordination can run without centralised servers.
Key Capabilities:
- Global, low-latency entry via Cloudflare Workers in 300+ cities.
- Session validation and presence orchestration inside SESSION_KV and Durable Objects with 20-minute TTLs.
- WebSocket multiparty routing without an external signalling layer or central Redis cluster.
Visual Architecture
Section titled “Visual Architecture”The following sequence diagram illustrates the lifecycle of a secure, real-time message within the mesh:
sequenceDiagram
participant Browser
participant Turnstile as Cloudflare Turnstile
participant Edge as Cloudflare Worker
participant Auth as SESSION_KV
participant Chat as ChatRoom (Durable Object)
participant Presence as PresenceRoom (Durable Object)
participant Bot as Bot Orchestrator
participant AI as Workers AI
Note over Browser,Edge: Login Phase
Browser->>Edge: POST /api/auth/login + Turnstile Token
Edge->>Turnstile: siteverify (Server-Side Validation)
Turnstile-->>Edge: success
Edge->>Auth: Store Session (20m TTL)
Edge-->>Browser: Session Token
Note over Browser,Chat: Real-time Message Flow
Browser->>Edge: WebSocket Connect (Session Token)
Edge->>Auth: Validate Token
Auth-->>Edge: Identity confirmed
Edge->>Presence: Update global heartbeat
Edge->>Chat: Route message to room
activate Chat
Chat->>Chat: Schema + rate checks
Chat->>Chat: Append to buffer (latest 100)
Chat-->>Browser: Broadcast `chat` packet
Note over Chat,Bot: @bot mention detected
Chat->>Bot: Quota Check (Neurons / KV)
Bot->>AI: Llama 3.2 1B Inference
Bot-->>Chat: Character-accurate response
Chat-->>Browser: Broadcast bot reply
deactivate Chat
Note: reconnection flows, hibernation wake-ups, and private room invitation workflows are omitted for clarity.