Queues & streams
medium 30 minA message queue stores work between the program that asks for it and the program that does it.
Check yourself
One question at a time. Each answer explains why.
Question 1 of 10
What is the primary purpose of a message queue?
What does at-least-once delivery mean?
Why does message ordering matter?
What is a dead letter queue?
Which guarantee is the hardest to achieve?
A topic has 6 partitions and a consumer group has 8 workers. How many of them consume data?
A payment worker crashes halfway through a charge, before it acknowledges. Delivery is at least once. What happens?
Work takes 40 seconds and the visibility timeout is 30. What do you see?
30 messages a second arrive and 20 a second are handled, for one hour. How many are waiting?
A new analytics service needs the events of the last week. Which design already has them?
Pick an answer to see why.
Not quite. Both sides can work independently and at different speeds.
Not quite. The message is delivered, but again if the acknowledgement does not arrive.
Not quite. A payment must not be handled before its order exists. Order keeps cause before effect.
Not quite. It keeps them for inspection and lets the rest continue.
Not quite. It needs the producer, the queue and the consumer's effect to work together.
Not quite. Inside a consumer group each partition is assigned to exactly one member. Surplus members wait.
Not quite. Without an acknowledgement the message returns. Only an idempotent handler prevents a second charge.
Not quite. The message becomes visible while the first worker is still busy. Extend the timeout.
Not quite. (30 - 20) x 3,600 = 36,000.
Not quite. A log keeps messages after they were read, so a new group can start from an older offset.
Flashcards
Say your answer, then reveal it.
Card 1 of 11
What does receiving a message do to it?
It is hidden for the visibility timeout. Only the acknowledgement removes it.
Say your answer, then reveal it.
When must a consumer acknowledge?
After the work is done and saved.
Say your answer, then reveal it.
Why count receives and not reported failures?
A worker that crashes reports nothing.
Say your answer, then reveal it.
What is a dead letter queue for?
Messages that failed too often, kept for inspection and replay, with an alert.
Say your answer, then reveal it.
At least once, in one sentence?
Not lost, but it may be delivered more than once.
Say your answer, then reveal it.
How do you get the effect exactly once?
At-least-once delivery plus an idempotent handler, with the id and the effect in one transaction.
Say your answer, then reveal it.
What defines the maximum parallelism of one consumer group?
The number of partitions. Each partition belongs to at most one member of the group.
Say your answer, then reveal it.
High watermark and log end offset?
The log end offset is the end of the leader's log. The high watermark is the point that all in-sync replicas have reached. Consumers read only up to the high watermark.
Say your answer, then reveal it.
Why is an append-only log fast to write?
It writes in sequence without page splits, and uses the page cache and read-ahead well.
Say your answer, then reveal it.
Workers needed?
Peak rate x seconds for each message / target use. 30 x 0.5 / 0.8 = 19.
Say your answer, then reveal it.
What does QUEUE stand for?
Quality of delivery, Uncouple, Enable async work, Use buffering, Ensure order within a scope.
Say your answer, then reveal it.

These cards come back in Today, just before you would forget them.