22. Message Queues
1
The picture to keep in your head2
22.1 What are producers and consumers?3
22.2 Why go async?4
22.3 What are the delivery guarantees?5
22.4 How do acks and visibility timeouts work?6
22.5 What are retries and dead-letter queues?7
22.6 What is an idempotent consumer?8
22.7 How does ordering work?9
22.8 What is backpressure?10
22.9 How do you scale consumers?11
22.10 Log (Kafka) vs queue (RabbitMQ, SQS): what's the difference?12
22.11 How do delayed and scheduled jobs work?13
Memory card and where the analogy breaks14
Practice: five levels15
Interview questions16
Solutions17
Sources18
Code lab22. Message Queues
Memory card and where the analogy breaks
3 min read+10 XP
The memory card (tear this page out)
| # | Question | Memory code |
|---|---|---|
| 22.1 | Producers and consumers? | Leave the job on the board; whoever's free picks it up |
| 22.2 | Why async? | Do now what they must see; queue what can wait a moment |
| 22.3 | Delivery guarantees? | Ack first and maybe lose it; ack last and maybe repeat it; make repeats harmless |
| 22.4 | Acks and visibility timeouts? | Taken off the board while you work; put back if you don't finish |
| 22.5 | Retries and DLQs? | Try again with growing pauses; after a few, send it to the manager's desk |
| 22.6 | Idempotent consumers? | Stamp the passbook, so a second call pays nothing |
| 22.7 | Ordering? | Same key, same line, same clerk: order kept where it matters |
| 22.8 | Backpressure? | A queue turns a rush into a wait; backpressure stops the wait from growing forever |
| 22.9 | Scaling consumers? | Counters needed = customers per minute × minutes each |
| 22.10 | Log vs queue? | A queue hands out slips and bins them; a log keeps the ledger for every reader |
| 22.11 | Delayed jobs? | A token for later: when it's called, check it still needs doing |
The whole chapter in one line: Queue what can wait, ack only after the work is done, make every consumer safe to run twice, keep order only per key, and watch the backlog.
Where the analogy breaks
- A bank customer notices if they're served twice. A message doesn't: duplicates are silent unless the consumer checks.
- A bank's tokens are gone at closing time. A log keeps every message for days, and readers can rewind and replay.
- A clerk who faints is obvious. A stuck worker isn't: the broker only knows it didn't hear an ack in time.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz