How I built a live chat SaaS on Cloudflare Workers and Durable Objects

Pong Chat

A live chat widget looks simple: a bubble in the corner, a text box, an agent on the other side. Underneath, it is a realtime system with thousands of open sockets, presence, file uploads, email fallbacks, and now AI and video calls. I recently launched Pong Chat, a live chat and team inbox for websites. It runs entirely on Cloudflare, with no servers, containers or databases for me to look after.

This post covers the architecture, the decisions that kept the bill close to zero when nothing is happening, and a few things I learned along the way.

The constraints

I had two rules from day one, and every design choice was checked against both:

  1. Nothing runs or bills without a reason. A chat widget sits on a page all day doing nothing. If idle visitors cost money, a free plan is impossible.
  2. One person can operate it. One repository, one Worker, one deploy command. No backup jobs, no queue servers, no Redis.

That ruled out the classic stack of an app server, a database, a websocket server like Soketi with Redis, a separate vector database and a GeoIP service. That is four or five things to run before you write a single feature.

One Worker, several hostnames

Everything is a single Worker that routes by hostname:

Static files (the widget, the desk, fonts, icons) are Workers Static Assets, so most requests never invoke the Worker at all. The server code is TypeScript with Hono and Zod and raw SQL, with no ORM. The front end is plain JavaScript, semantic HTML and SCSS, bundled with esbuild. No framework, which keeps the widget small on the host page.

One Durable Object per workspace

This is the core decision. Every workspace (one company’s chat) lives in its own Durable Object, TenantDO, with its own SQLite database. Clients, aliases, conversations, messages, agents, settings, and every open visitor and agent socket all live in it.

Why this works so well for chat:

Next to TenantDO there are a few small singleton or per-resource objects:

Making idle cost nothing

Durable Objects bill for wall-clock duration while they are awake. A naive chat keeps every object awake forever, because some visitor somewhere has a socket open. Here is what keeps that bill down:

The result: a site with traffic but no agent online costs almost nothing, which is what makes a real free plan possible.

AI without a per-resolution fee

Most chat products charge per AI resolution. I wanted AI to be a flat part of the paid plan. That only works if inference is cheap and close to the data, so all of it runs on Workers AI:

Background work (webhooks with retries, embeddings, emails) goes through one Cloudflare Queue with batched consumers. It is used only when a workspace has the feature turned on.

Video calls and screen sharing in the chat

An agent can turn a chat into a video or voice call with screen sharing in both directions, right inside the widget. Nobody installs anything.

Media goes peer to peer over WebRTC. Cloudflare TURN relays it when a direct connection is impossible, with credentials minted by the Worker per call. Signalling rides the WebSocket the chat already has, so a call adds no new infrastructure. The agent’s browser records the call and uploads the recording to R2. Whisper turns it into a transcript, and the transcript lands in the conversation.

Seeing what the visitor sees

The features I use most as an agent are about context, not messages:

Email and channels

Inbound email is parsed in the Worker with postal-mime, including HTML-only mail turned into readable text. Outbound email uses Cloudflare Email Service. Telegram bots plug into the same inbox, and Instagram, Messenger and WhatsApp are in beta. Every channel produces the same webhook message shape, so an integration written once works for all of them.

Compatibility as a feature

I came to this from years of running support on Chatra, so the widget reads the Chatra JavaScript API (Chatra(...), ChatraSetup, ChatraID). A site that moves over keeps its existing code. Small compatibility layers like this one decide whether a migration takes an afternoon or a sprint.

Testing and deploying

Tests run with Vitest and Cloudflare’s Workers pool, which gives each test a real Durable Object with real SQLite in Miniflare. So merge logic and migrations are tested against the same engine that runs in production. The domain core (identity merge, compatibility mapping, webhook shaping) is plain TypeScript with no Cloudflare imports, which keeps it easy to unit test and portable.

A deploy is one guarded command. It refuses to run unless the tree is committed and up to date, takes a lock, runs the tests, builds, deploys, and tags the version. Rollback is wrangler rollback. Durable Object storage has 30 days of point-in-time recovery, so there are no backup jobs to write.

What I would tell someone starting the same thing

Try it

Pong Chat is free for one agent. Premium costs €9 per agent per month, or €7 billed yearly, with a 14-day trial. Installing it takes one script tag, a WordPress plugin or a Google Tag Manager tag. If you are evaluating chat tools or building something similar on Cloudflare, take a look at Pong Chat. I am happy to talk architecture in the comments.

Also noted on fbapp.us/pongchat

Leave a Reply