Chat
Chat is a real-time, multi-room WebSocket communication application. Built on Cloudflare Workers and utilizing Durable Objects, it supports persistent, synchronized, and low-latency chat sessions between multiple concurrent users within custom-defined rooms.
Technical Stack
State & WebSocket Sync
| Compute Engine | Cloudflare Workers |
| State Coordinator | Durable Objects (Single-instance routing) |
| WebSocket Sync | PartyKit (PartyServer API integration) |
| Session Logic | WebSockets (in-memory pub/sub) |
Data & Storage
| DB Engine | Durable Object SQL Storage API |
| Chat History | Serverless SQL tables scoped per room |
| Frontend UI | Vanilla JS & WebSockets |
| Language | TypeScript |
Durable SQL Storage API: Instead of holding chat history entirely in RAM or making slow external database roundtrips, the chat room’s Durable Object writes directly to its own local, high-speed SQLite database file using Cloudflare’s SQL Storage API.
Core Features
- Multi-Room Separation — Dynamic room generation based on URL slug paths. Users in the same URL route are grouped into a dedicated Durable Object instance.
- WebSocket Broadcasts — Messages sent by a user are instantly broadcast to all active connections in that room, ensuring real-time text delivery.
- Automatic History Load — When a new user opens a room, the Durable Object queries its local SQL table to retrieve and render the chat room’s message history.
- PartyServer Simplicity — Leverages the PartyKit/PartyServer API to streamline socket connections and event routing without complex state management code.