The customer's email was polite but devastating: "On Saturday at 14:20, our vehicle left its permitted zone. We got no alert from your system. This alarm is in our contract." I dug into the logs: the zone violation had been detected, the alarm message had been generated and published to Redis. Even the return value of the PUBLISH command was sitting right there in the log: 0. Zero. In other words, no subscriber had received that message. The message hadn't even been lost; it had died the moment it was born, because nobody was listening. During those minutes, our notification service was restarting for 40 seconds because of a deployment.
We had actually known Redis Pub/Sub's contract all along; we just hadn't accepted it: if the subscriber isn't there at that moment, the message might as well not exist. This post is the story of that refusal to accept it, and of the Redis Streams architecture we eventually arrived at.
The Appeal of Pub/Sub: A Distributed System in Two Lines
When we were building the alerting infrastructure at the end of 2019, the reason we chose Pub/Sub was, quite simply, its elegance. The rules engine finds a violation and says PUBLISH alerts:geofence '{...}'; the notification service listens with SUBSCRIBE and sends the SMS/email/dashboard notification. No broker setup, no queue schema, no offset tracking. Latency under a millisecond. Flawless in the demo environment, trouble-free in production for months. That's exactly how systems earn your trust and then let you down.
The losses came through three channels, and we lived through all three, one by one. One: the deployment window above — if there's no subscriber, the message evaporates. Two: network dropouts; when a subscriber's TCP connection drops, Redis buffers nothing on its behalf, and a subscriber that reconnects only receives future messages. Three, the least known: client-output-buffer-limit. If your subscriber can't consume messages fast enough, Redis grows its output buffer, and when it hits the default pubsub limit (32 MB hard, 8 MB/60 s soft), it cuts the connection. So a slow consumer doesn't just stay slow; it gets disconnected and loses everything in flight at the moment of the disconnect. We discovered this one afternoon when our SMS provider's API slowed down, in a seemingly causeless disconnect-reconnect loop in the notification service.

An Exhibition of Half-Solutions
Our first approach was a band-aid: before publishing alarms, let's also write them to a MySQL table, and have the notification service scan for "unsent alarms from the last 10 minutes" on startup. It worked, but it created two problems. There was a race condition between marking an alarm as sent and publishing it; some alarms went through both the live path and the scan path and sent the SMS twice. (Take note: a customer woken up twice in the night about their vehicle gets angrier than they do about a lost message.) Second, the haggling between the scan interval and the loss window never ended. Keeping two separate sources of truth alive in a system, it turns out, means you can't trust either one.
The second half-solution was to drop Pub/Sub and move to a list-based queue: LPUSH + BRPOP. It genuinely solves the delivery problem — the message sits in the list, and the consumer picks it up when it arrives. But this time we lost broadcasting (fan-out): BRPOP hands a message to a single consumer, whereas the same alarm was being listened to by the SMS service, the dashboard push service, and the audit log. Pushing a separate list for each consumer means making the producer side aware of the list of consumers; independence was gone, and a tangle of wiring took its place.

Streams: The Marriage of Queue and Broadcast
Redis 5's Streams structure was designed for exactly this dilemma, and in the summer of 2020 we finally used it the way it deserves. A stream is an append-only log: you add with XADD, each entry gets a unique, timestamped ID in the format 1692871632123-0, and it stays there until it's deleted. On the read side, the consumer group concept seals the deal: each service (SMS, push, audit) opens its own group, and each group reads the entire stream independently — broadcasting is back. Within a group, messages are distributed among the members — and there's the queue behavior too. And the critical mechanism: a message received with XREADGROUP waits in that consumer's pending list until the consumer says XACK. If the consumer crashes after receiving a message, the message isn't lost; it sits in pending, owned but unacknowledged.
Let's replay our deployment scenario: the notification service is down for 40 seconds. Alarms keep flowing into the stream with XADD. When the service comes back up, XREADGROUP reads from where it left off; all of the alarms from those 40 seconds are processed in order. Loss window: zero. For the half-finished messages of a consumer that crashed, we also have a watchdog task that runs once a minute: it uses XPENDING to find owned messages older than 5 minutes and XCLAIM to hand them over to a healthy consumer. That closes the "received it but died before processing it" case as well.

The Costs and the Fine Print
It isn't free, of course. First, memory: because a stream accumulates, it grows. We use XADD with MAXLEN ~ 100000 (the approximation sign matters — exact trimming costs something on every insert, while approximate trimming is nearly free). At our alarm volume, that means a buffer of a few days; a consumer that falls that far behind needs a postmortem report more than an alarm anyway. Second, the delivery guarantee became at-least-once: a consumer that crashes before it can send XACK will process the message a second time. We made SMS sending idempotent — a "has this SMS already gone out?" check based on the alarm ID sits in front of the sending service. Third, code complexity: instead of the two lines of SUBSCRIBE, there's group creation, an ACK loop, and the pending watchdog. Maybe 300 extra lines of code in total. Next to the cost of a single lost contractual alarm, that's a rounding error.
I've been asked "Why not Kafka or RabbitMQ?" a lot. The honest answer: our alarm volume doesn't exceed a few hundred messages per second, and Redis was already in our stack — location cache, sessions, counters, all of it lives there. Running a Kafka cluster along with its ZooKeeper just for messaging would have been self-serving complexity at our team size in 2020 (effectively two people looking after infrastructure). Streams let us get reliable delivery out of an existing dependency. If one day volume or retention needs justify Kafka, the migration path is clear too: on the producer side, the XADD call sits behind a single interface.
This time we didn't go live without setting up monitoring, either. We hooked lag-like indicators from the XINFO GROUPS output (we calculate the number of entries a group hasn't read from the difference in last IDs) into a per-minute graph; if a consumer group falls more than 5,000 messages behind, an alert goes off. In the first month this alert fired twice, and both times the cause was the same: the SMS provider slowing down. That slowness used to disconnect the subscriber and lose messages; now it's just a peak that swells on the graph and then subsides. The same illness, two different fates in two architectures — and that difference is exactly what infrastructure design buys you.
The balance sheet for the six months after the migration: zero lost alarms, 2-3 duplicate SMS messages a month (all of them reprocessings caught by the idempotency check that never reached the customer), and a memory cost of around 60 MB for the stream. We didn't throw Pub/Sub away, though; there are places we still use it. Location updates going to the live map screen stayed on Pub/Sub, because a missed message there doesn't matter — a more recent one will arrive two seconds later anyway. Where a vehicle is is Pub/Sub data; the fact that it left a zone is a Streams event. Just putting that distinction into a sentence is enough to explain the architecture: data whose value is in its latest state can be lost; an event whose value is in the fact that it happened cannot.
If you'd like to sort out which data in your messaging infrastructure belongs to which class, and work out the bill between at-most-once and at-least-once, get in touch with us; talking before your first lost contractual alarm is much cheaper than talking after it.