Messaging: recap and quiz
The module in six sentences
Section titled “The module in six sentences”- Queues and pub/sub. A queue lets the producer hand work over without waiting: a work queue gives each message to one consumer and pub/sub gives it to every subscriber, and the backlog grows by the producer rate minus the consumers’ combined rate.
- Backpressure. A bounded queue refuses what it cannot hold, which moves the overload to the producers, who must wait, drop or send fewer.
- Retries and dead letters. An unacknowledged message returns after the visibility timeout, and a limit on attempts plus a dead-letter queue keep a poison message from circulating for ever.
- Delivery semantics. When the acknowledgement happens chooses between a lost message and a repeated one, and at-least-once with a consumer that copes gives an effectively-once result.
- Partitions and consumer groups. A log broker keeps order inside a partition, and a group reads each partition with one consumer, so partitions cap the parallelism and a hot key makes one lane long.
- Offsets and replay. The group’s committed offset is where a new owner starts, so a crash repeats the work since the last commit.
How each one breaks
Section titled “How each one breaks”| Idea | What breaks | What you see | What helps |
|---|---|---|---|
| Queue | Producers outpace consumers | A backlog that only grows, and a longer wait | More consumers than the rate needs, or fewer messages |
| Backpressure | A full queue refuses, and the producer ignores it | Lost or repeated messages upstream | Make the producer wait, shed or slow, deliberately |
| Retries | A message that never works | Capacity spent on the same message | A limit on attempts and a dead-letter queue someone watches |
| Delivery | The acknowledgement is lost, or comes first | Repeated work, or lost work | Acknowledge after the work and make the handler safe to repeat |
| Partitions | Too few partitions, or one hot key | Idle consumers, one partition far behind | More partitions, a better key, a split hot key |
| Offsets | A crash between two commits | The same messages processed again | A shorter commit interval, a consumer safe to repeat |
A checklist for a design with queues
Section titled “A checklist for a design with queues”Each question points back to the lesson that answers it.
- Does the work need to be done before you answer? If not, a queue lets you answer first and do it later. (Queues and pub/sub)
- Should one worker or every reader get each message? Work queue, or publish/subscribe. (Queues and pub/sub)
- Is the consumers’ combined rate above the producers’ average? If not, the backlog grows without end. (Queues and pub/sub)
- What happens when the queue is full? Choose the limit and what the producer does with a refusal. (Backpressure)
- How many attempts, how long between them, and who looks at the dead letters? (Retries and dead letters)
- When do you acknowledge, and is the handler safe to run twice? (Delivery semantics)
- How do you publish an event and save a row without losing one? Write both in one transaction and publish from an outbox. (Delivery semantics)
- What must stay in order, and what is its key? Order only holds inside a partition. (Partitions and consumer groups)
- How many partitions will the busiest group need, and which key could be hot? (Partitions and consumer groups)
- How often do you commit, and what is a repeat worth? (Offsets and replay)
Check your understanding
Section titled “Check your understanding”Nine questions cover the whole module. Every option is explained, whether it is right or wrong.
Messaging: module quiz
This quiz needs JavaScript to check your answers.
Where this goes next
Section titled “Where this goes next”A broker moves messages, and something has to process them. The next modules look at stream and batch processing, which read these logs and queues to compute over time, and at idempotency, which is how a consumer or an API survives the repeats that this module said cannot be avoided. Ask this module’s questions first when you meet them: who gets each message, what happens when a consumer is slow or dead, and what a repeat costs.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.