· 4 min read
Postgres is the queue, Redis is only the wire
How TimeUp delivers realtime events without losing them when Redis restarts, and the Postgres test that now runs in CI.
Publishing an event and hoping every connected screen hears it works until there is a gap: a restart, a deploy, a dropped connection. Pub/sub forgets what it did not deliver, and exactly-once delivery to many subscribers is not something I can promise.
Save the event with the change
The event is written to a table inside the same transaction as the change that caused it. If the change rolls back, so does the event; there is a test against a real database that forces that failure.
A relay that claims rows
- It claims batches with FOR UPDATE SKIP LOCKED, so two workers never take the same row.
- A worker that lost its claim cannot finish the row, because every update checks who owns it.
- Failures retry with a growing, jittered delay, and after ten attempts the event is marked dead.
- The event is validated again right before it is sent.
With several workers, order is not guaranteed: two of them can deliver different events at the same time. What is guaranteed is that nothing disappears quietly. An event is delivered, or after ten attempts it is marked dead and stays visible.
What is guaranteed
At least once. Delivered means handed to the transport, not seen by a browser. Redis Streams only carries the messages between server nodes; the database stays the authority.
What the test covers
The claim query that makes this safe across workers has a test against a real PostgreSQL: two workers claim at once and never overlap. It still skips itself when no database is available, but since November 15 a workflow runs it against a real Postgres on every pull request that touches the relay.