How Per-Pod Consumer Names Left 1,847 Redis Streams Messages Pending Forever and Dropped Order Confirmations
09:12 UTC, Thursday. A support ticket lands in the channel: "Customer paid yesterday, no confirmation email, can you resend?" By 09:40 there are nine more tickets like it. Payments look fine. The orders exist. The emails do not.
the scramble
Two of us get pulled in, me and someone from support engineering. Order confirmations go through a Redis stream called
orders:confirm. The checkout service appends an entry, and a worker deployment reads it through a consumer group and
calls the email provider.
First theory was the email provider. We check their status page (green) and our send logs. The logs show that the worker sends confirmations normally, about 11 per minute. So it is not "all emails fail". Roughly one order in forty never gets one.
Second theory: checkout stopped publishing for some orders. I compare order IDs from Postgres against entries in the stream
with XRANGE. Every missing-email order has an entry in the stream. The messages were published. Nobody sent them.
the hunt
Dead end one: Redis eviction. The instance runs with maxmemory-policy noeviction and sits at 38% of its limit, so no
entries were dropped. Dead end two: worker crashes. The worker deployment has had 0 restarts in 6 days, though it was
redeployed four times in that window, which turned out to matter.
Then I ask the stream directly how far behind each consumer is:
lag: 0 means the group has read everything. pending: 1847 means 1,847 messages were delivered and
never acknowledged. And there are 9 consumers, though the deployment runs 3 replicas.
Consumer names were built from the pod hostname. Every deploy creates new pod names, which creates new consumers. Old consumers stay in the group forever with whatever they had in flight at the moment their pod received SIGTERM.
the find
The worker loop reads with XREADGROUP ... STREAMS orders:confirm >. The special ID > means "only messages never
delivered to any consumer in this group". A message that was delivered to a consumer and never acknowledged is not new, so
> will never return it again. It stays in that consumer's pending entries list until somebody claims it.
Our workers handled SIGTERM by exiting right away. A pod that was mid-send during a rollout had read a message, started the HTTP call to the
email provider, and been killed before the XACK. Four deploys in six days, a few in-flight messages each time, plus a
couple of crashes during a node drain, adds up to 1,847. The new pods had different names, so nobody was ever going to
retry what the old pods left behind.
The old code:
the fix
Two changes. First, drain the backlog by hand. XAUTOCLAIM transfers ownership of entries idle longer than a threshold to a
consumer of your choosing, so I ran it from a one-off script with a 60-second minimum idle time and processed the result like normal
traffic. Sends are keyed by order ID in the email provider's idempotency header, so reprocessing a message that did go out
is harmless.
Second, make the worker claim abandoned work itself. A sweeper runs every 30 seconds inside each worker:
Also on shutdown: the worker now stops reading on SIGTERM, finishes the batch it holds, acknowledges, and only then exits.
Once the backlog was drained I removed the 6 dead consumers with XGROUP DELCONSUMER. Deleting a consumer that still
has pending entries discards those entries' ownership, so I did it only after XPENDING showed 0 for each of them.
the aftermath
The backlog drain sent 1,847 confirmations over about 14 minutes, the oldest from 6 days earlier. Support closed all the tickets by the afternoon. Because the provider's idempotency key covered us, 212 of those turned out to be messages whose email had already gone out, and the provider deduplicated them.
What changed afterward:
- A Prometheus alert on
pendingfromXINFO GROUPSstaying above 20 for 5 minutes. This would have fired on day one. - A second alert on the oldest pending entry's idle time exceeding 10 minutes.
- The runbook now says: if a stream group shows
lag: 0but work is missing, checkpendingbefore anything else. - Graceful shutdown with a 30-second
terminationGracePeriodSecondson the worker pods.
Every dashboard we had was green because lag was zero. Lag only counts what nobody has read yet. It says nothing about what somebody read and dropped.