Video in progress
How does a consumer group work in Redis Streams, and what happens to a message if the worker takes it and crashes?
Within a group each message goes to one consumer, and it sits in the Pending Entries List (PEL) until that consumer calls XACK. If the worker crashes, the message stays in the PEL; another consumer takes it over with XAUTOCLAIM and processes it.
📖 Answer
XADD orders * orderId 77 status PAID
XGROUP CREATE orders billing $ MKSTREAM
XREADGROUP GROUP billing w1 COUNT 10 BLOCK 5000 STREAMS orders >
XACK orders billing 1730600000000-0
> means "new messages not yet delivered to anyone". Several groups read one stream independently (similar to consumer groups in Kafka), while the workers inside a group share the load.
When a worker crashes:
XPENDING orders billing - + 10 # who holds what, and since when
XAUTOCLAIM orders billing w2 60000 0-0 # w2 takes everything unacked for more than 60 s
The rules that follow from this:
- delivery is at-least-once, so the handler must be idempotent;
- every message has a
delivery count; if it goes over, say, 5, move the message to a separate "dead letter" stream, otherwise a poison message circulates forever; - a stream doesn't shrink on its own, so cap it with
XADD ... MAXLEN ~ 1000000orXTRIM.
Spring Data Redis has StreamMessageListenerContainer, but you still write the claim logic yourself. If you need long retention, replay and large volume, Kafka is stronger.
Sign up to mark studied questions and save your progress.