The Problem: Serverless and Long-Lived Connections Don't Mix
kansei uses Server-Sent Events for live notifications, user presence, and collaborative editing. But on Vercel, every open SSE connection keeps a function active — and you pay for every second. Five open tabs per studio, five minutes per connection, dozens of studios… the bill grew linearly with how much people liked the app. That is the wrong curve.
Step 1: Durable Objects for SSE
The first Worker moved notification and portal streams to Cloudflare Durable Objects. The edge holds long connections for a fraction of the cost; the Next.js app pushes events through an internal broadcast endpoint. The same object also handles presence — who is looking at a task right now — with a fifteen-second heartbeat expiry.
Step 2: Collaboration Polling
Our Yjs collaboration (documents, canvas, briefs) polls a Redis queue roughly every second per open editor tab. Three Vercel routes serving thousands of cheap requests a day — a perfect edge candidate. The Worker verifies an HMAC token minted by the main app, reads directly from Upstash Redis, and Vercel never hears about the polling. The wire format stayed unchanged, so the client switches between the Worker and the main-app fallback based on a single environment variable.
Step 3: CalDAV Reads at the Edge
The calendar integration for Apple Calendar speaks CalDAV — and 90%+ of its traffic is PROPFIND/REPORT reads. The Worker serves those directly against Postgres via Hyperdrive connection pooling; only writes (PUT/DELETE) get forwarded to the main app, where the smart parser and audit logging live. Reads: zero Vercel invocations.
A Bundler Lesson (Bonus from the Same Era)
The same period taught us a build lesson too: an attempt to force webpack instead of Turbopack ended in an OOM kill after twenty minutes on an 8 GB build machine. And "Turbopack breaks clicking" turned out to be a misdiagnosis — the real culprit was a haptics library that mutated the DOM on every click and raced React's commits. The rule since then: before you blame the tool, find the race condition.
The Result
Five Workers (files, proxies, realtime, collaboration, MCP bridge) now carry traffic that would otherwise flow through serverless functions. The main app does what it is good at — rendering, authorization, business logic — and the edge holds the connections. Bills went down, latency went down, and most importantly: the number of open tabs is no longer directly proportional to cost.