No Redis, no Kafka: our live updates are one Postgres trigger
EngineeringPostgresSSETanStack Querypg-bossBun
Orders appear on every open staff screen without a refresh, and there's no message broker behind it: one Postgres trigger, one listener and a refetch. Here's where that breaks, and why it's enough for us.
The first thing our staff said about Flair v2 wasn’t about a feature. They noticed orders appearing on the list without refreshing the page. And they noticed it was fast.
That sounds like a small thing. But orders come in from several places at once: a customer confirming on their phone, a payment landing from CHIP, a GoGet driver picking up, me creating an order from Claude. Every open staff tab needs to know.
The usual answer is a message broker. Redis pub/sub, maybe Kafka, a websocket service, and a rule that every piece of code must remember to publish an event. We run one business on one VPS. I didn’t want any of that.
So our live updates are one Postgres trigger. Is that really enough, and where does it break?
The database announces every change
Postgres has a quiet feature called LISTEN/NOTIFY. Any connection can send a short notice on a named channel, and any connection listening on it receives it.
We attach one trigger, notify_change, to the main tables. Whenever a row is inserted, updated or deleted, it sends a notice on a channel called flair_live. The notice holds only the table, the operation, the row id and, for child rows, the parent id. Never the content.
CREATE FUNCTION notify_change() RETURNS trigger AS $$
DECLARE row_json jsonb;
BEGIN
row_json := CASE WHEN TG_OP = 'DELETE' THEN to_jsonb(OLD) ELSE to_jsonb(NEW) END;
-- Ids only, never content. Delivered when the transaction commits.
PERFORM pg_notify('flair_live', jsonb_build_object(
'table', TG_TABLE_NAME,
'operation', lower(TG_OP),
'id', row_json -> 'id'
)::text);
RETURN NULL;
END $$ LANGUAGE plpgsql;Two things make this safer than it looks. First, no customer data travels, so the notice stays tiny and nothing private leaks into a browser by accident. Second, Postgres delivers a notice only when its transaction commits. A write that rolls back never reaches anyone’s screen.
From one connection to every tab
The web process holds one listening connection to Postgres. It collects notices for 250 ms, drops repeats, then hands the batch on. If the same order changes three times in that window, the browser hears about it once.
Each batch goes to every open staff tab over Server-Sent Events, a plain HTTP stream from server to browser. Our API is Hono on Bun. Bun closes a connection that has been idle for 10 seconds, so the stream sends a small heartbeat every 5 seconds. Every 30 seconds it also checks that the person is still signed in and still allowed in. If not, the stream closes.
In the browser, each module says which tables it cares about. For orders it’s deliberately broad: any change to an order, its items, payments, confirmation links or deliveries invalidates the ["orders"] query. TanStack Query then refetches through the normal API, the same way the page loaded in the first place.
That is the part I like most. The browser is told only that something changed, never what. It always gets the real data through one path.
It also means no app code broadcasts anything. A change made from the web app, a background job, an MCP call from Claude or the WhatsApp agent all reach the screen the same way, because the database itself announces it. There’s no “remember to emit the event” for anyone to forget.
Where it breaks
It isn’t free of trade-offs, and I’d rather say them plainly.
Notices are fire-and-forget. If a browser’s stream drops, anything sent while it was down is gone. Postgres doesn’t keep them. So after every reconnect, the browser refetches every active query. Correctness comes from that refetch, not from the notices. On a couple of pages, timed polling stays on as a backstop.
It is also sized for us. One VPS, one business, our staff tabs. One listening connection fanning out to a few streams is nothing. For millions of users I’d design it differently. But we don’t have millions of users, and building for imagined ones is a mistake I’ve made before.
Background jobs follow the same idea. Flair v2 is the first time I’ve used pg-boss, a job queue that lives inside Postgres. Its send(tx, …) takes the same transaction as the write, so a job exists only if the write commits. No order saved without its delivery job, and no job for an order that rolled back. Again, no Redis and no separate queue to run or back up.
So the trade-offs come out in our favour on the three things I care about. Performance: a notice holds only ids, so it’s tiny. Reliability: the browser refetches after every reconnect, so a lost notice never leaves a screen wrong. Cost: there’s no Redis or broker to run, monitor or pay for.
The lessonLet the database announce changes, and let the browser fetch the truth.
What I’d tell anyone building on one server
- Check what your database already does. Postgres can notify and queue. You may not need another service.
- Send ids, not data. A notice that only says which row changed can’t leak anything, and the browser refetches what it’s allowed to see.
- Plan for lost messages. Refetch everything active after a reconnect, and treat live updates as a speed-up, not the source of truth.
- Build for the size you are. One VPS is a real architecture when you’re one business.
Live updates told us the data was right. Whether the screens behaved right on a real device was a different story, and the mockups couldn’t tell us.
