Scrivio Interview library
DebuggingIntermediate7 min read · updated 13 November 2026

An order-processing service reads a Redis Stream with a consumer group. After a deployment, XPENDING reports 120,000 pending entries, some idle for six hours with a delivery count of 1, while new orders flow normally.

What happened, how do you recover the stuck entries, and how do you prevent it?

The 120,000 entries were delivered to consumers of the old pods, which used random names and died before acknowledging them. A consumer reading with XREADGROUP and the > id only ever gets new entries, so nobody looks at the dead consumers' pending lists. We recover them with an XAUTOCLAIM loop that moves long-idle entries to a live consumer, and we prevent a repeat with stable consumer names, a claim loop in every worker, a dead-letter stream for poison entries and alerts on pending age.

Why this question is asked

Redis Streams with consumer groups are often chosen precisely because they promise not to lose messages, so a growing pending count after a deployment is confusing: the messages are not lost, yet nothing processes them. Interviewers like this scenario because it tests whether we know what the pending entries list is, how ownership of an entry works, and which command reads what. In this answer, we will recap how consumer groups track delivered entries, explain why these entries got stuck, recover them with XAUTOCLAIM, make sure it cannot quietly happen again, and add the monitoring that would have caught it within minutes.

1A Quick Recap of Consumer Groups and Pending Entries

A stream is an append-only log of entries, each with an id such as 1731400000000-0. A consumer group is a named reader of that stream that splits the entries among its consumers, each identified by a name the client chooses. XREADGROUP GROUP orders-group worker-1 STREAMS orders > asks for entries never delivered to anyone in the group.

When an entry is delivered, the group records it in the pending entries list, the PEL: entry id, the consumer that owns it, the time of the last delivery and a delivery count. It stays there until the consumer calls XACK. That record is what makes Streams safe against crashes: a delivered but unacknowledged entry is never forgotten. The catch is that the record belongs to one named consumer, and only that consumer's reads or an explicit claim will ever touch it.

2What Happened During the Deployment

The old pods named their consumers with a random value, something like worker-7f3a9c. Each one read a batch of orders, and the deployment terminated it before it acknowledged them. The new pods started with new random names and read with >, which returns only new entries. So the 120,000 entries kept sitting in the PEL under consumer names that will never connect again.

The numbers in the overview tell the story. A delivery count of 1 means each entry was delivered exactly once and never retried. An idle time of six hours matches the time since the deployment. And new orders flow normally because > keeps serving fresh entries to the new consumers. A consumer that wanted its own pending entries back would have to read with the id 0 instead of >, which only works if it comes back under the same name.

Properties
XPENDING orders orders-group
# 1) (integer) 120000 total pending
# 2) "1731380000000-0" oldest pending id
# 3) "1731401600000-5" newest pending id
# 4) 1) 1) "worker-7f3a9c" 2) "40112"
# 2) 1) "worker-c21e04" 2) "39950"
# 3) 1) "worker-9ab001" 2) "39938" all three are pods that no longer exist
XPENDING orders orders-group IDLE 3600000 - + 3
# each row: id, consumer, idle ms (about 21600000 = six hours), delivery count 1

The summary form shows which consumers own the pending entries, and the extended form with IDLE filters to entries idle for over an hour. Seeing consumer names that match no live pod confirms the diagnosis.

3Recovering the Stuck Entries With XAUTOCLAIM

XAUTOCLAIM, available since Redis 6.2, scans the PEL from a starting id and transfers every entry idle for longer than a threshold to the consumer we name. It returns a cursor for the next call, the claimed entries with their data, and, from Redis 7, the ids of entries that were deleted from the stream in the meantime. Claiming also increments the delivery count, which we will use for poison detection.

We run it in a loop from the cursor 0-0 until the cursor comes back as 0-0 again, processing and acknowledging each batch before asking for the next.

Java
String cursor = "0-0";
do {
// XAUTOCLAIM orders orders-group worker-1 60000 <cursor> COUNT 100
AutoClaimResult r = streams.autoClaim("orders", "orders-group", consumerName, 60_000, cursor, 100);
for (StreamEntry e : r.entries()) {
handleOrder(e); // idempotent: may run again after a claim
streams.ack("orders", "orders-group", e.id()); // XACK removes it from the PEL
}
cursor = r.nextCursor(); // "0-0" when the scan is complete
} while (!cursor.equals("0-0"));
Step throughThe claim loop in every worker
  1. XAUTOCLAIM entries idle over 60 sstart from cursor 0-0
  2. Delivery count above 5?
    YesXADD to orders:dead, then XACKNoProcess the order
  3. XACK after successremoves the entry from the PEL
  4. Cursor back to 0-0?
    YesSleep 30 s, start againNoClaim the next batch

4 steps in order. Play them, or step through them one at a time.

The client calls in this snippet are illustrative, because Lettuce, Jedis and Spring Data Redis each name them differently; the Redis command in the comment is what matters. Notice the idle threshold of 60 seconds. It must be longer than our slowest normal processing time, otherwise a worker would steal an entry that a healthy colleague is still working on.

4Preventing It From Happening Again

The first change is to run the claim loop continuously in every worker, every 30 seconds or so, not as a one-off fix. Then any consumer that dies, for whatever reason, has its entries picked up within a minute or two, and a deployment becomes a non-event.

The second change is stable consumer names tied to pod identity, such as the StatefulSet pod name orders-worker-2 or the pod name from the downward API. A restarted pod with the same name can first read its own PEL with id 0 and finish what it started. Names still change when pods are replaced, so once a dead consumer's entries have been claimed we remove it with XGROUP DELCONSUMER orders orders-group worker-7f3a9c. Order matters here: DELCONSUMER discards that consumer's pending entries, so we delete a consumer only after XPENDING shows it owns nothing.

The third change handles poison messages. If an order makes the handler throw every time, claiming would bounce it between workers forever. When the delivery count passes a limit, for example 5, we copy the entry to a dead-letter stream with XADD orders:dead and then XACK the original, so a person can inspect it without blocking the rest.

5Monitoring That Would Have Caught It

This incident lasted six hours only because nobody was looking. Three numbers would have shown it within minutes: the pending count of the group, the idle time of the oldest pending entry, and the lag, which is how many entries in the stream the group has not yet read. XINFO GROUPS reports pending and, from Redis 7, lag directly, and XPENDING with IDLE gives the oldest idle time.

A sensible alert is 'oldest pending entry idle for more than five minutes'. Pending count alone can be large during a busy period and still be healthy, but an entry that nobody has touched for five minutes is always a problem.

6Follow-up questions

Why must processing stay idempotent when claims move entries between consumers?

Because a claim cannot know whether the original consumer did the work. A consumer may have charged the card and written the order, then died just before XACK; the entry looks exactly like one that was never started. After the claim, a second consumer processes it again. If handling an order twice would ship twice, we need an idempotency key such as the order id with a unique constraint, so the second run notices the work is done and simply acknowledges.

What is the difference between XCLAIM and XAUTOCLAIM?

XCLAIM transfers specific entry ids that we already know, usually from a previous XPENDING call, so recovery takes two steps. XAUTOCLAIM combines the scan and the transfer: it walks the PEL from a cursor and claims whatever is idle long enough, which is simpler and safer to run as a periodic loop.

Should we just reset the group with XGROUP SETID to skip the old entries?

Not for orders. SETID moves the group's last-delivered id but does not process anything, and the pending entries would still need to be claimed or acknowledged. Skipping 120,000 orders is a business decision, not a recovery step; claiming them processes every order at least once.

7Conclusion

In this answer, we saw that the stuck entries were delivered to consumers with random names that disappeared in the deployment, and that XREADGROUP with > never returns pending entries, so nobody touched them. An XAUTOCLAIM loop moves entries idle beyond a safe threshold to a live consumer, which processes and acknowledges them. To prevent a repeat we run that loop continuously, use stable consumer names and delete dead consumers only after their entries are claimed, send poison entries to a dead-letter stream, and alert on the age of the oldest pending entry and on lag.

What to say in the interviewAbout 90 seconds aloud

Open with

The entries were delivered but never acknowledged. Each delivered entry goes into the group's pending entries list under the consumer that received it, and stays there until XACK.

Then, if they want more

The old pods had random consumer names, the deployment killed them mid-batch, and the new pods read with the greater-than id, which only returns new entries. So nobody ever looks at the dead consumers' pending lists, which matches what we see: delivery count 1, idle for six hours, new orders flowing fine.

To recover, I run XAUTOCLAIM orders orders-group worker-1 60000 0-0 COUNT 100 in a loop following the returned cursor. It moves entries idle for more than 60 seconds to a live consumer, which processes them idempotently and XACKs them.

To prevent it, every worker runs that claim loop continuously, consumer names are stable and tied to pod identity, and once a dead consumer owns nothing I remove it with XGROUP DELCONSUMER, never before, because that drops its pending entries.

If an entry's delivery count goes above something like five, I copy it to a dead-letter stream with XADD and acknowledge the original. And I alert on pending count, the oldest pending idle time and the lag that XINFO GROUPS reports from Redis 7, so this would show up in minutes rather than six hours.

About this answer

Last updated
13 November 2026
Versions it names
Redis 7, Redis 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What happened, how do you recover the stuck entries, and how do you prevent it?": https://scrivio-interview-library.netlify.app/databases/redis-patterns/9b38c50428/