Question presented to candidate:
"What is a message queue, and why would you put one between two services instead of having one call the other? Tell me what happens when a consumer crashes halfway through a message, and what can go wrong."
What a strong answer should cover:
A queue is a durable buffer between producers and consumers: the producer hands off work and returns; consumers pull at their own pace
The reasons: asynchronous work (fast user response), absorbing traffic spikes (load levelling), independent scaling and failure of each side, and competing consumers for parallelism
The delivery mechanics: receive, process, acknowledge/delete; an unacknowledged message comes back after a visibility timeout; repeated failures go to a dead-letter queue
The consequence: delivery is usually at-least-once, so consumers must be idempotent; FIFO ordering costs throughput and is usually per group
The costs: queue depth and consumer lag to monitor, eventual rather than immediate results, one more system to run, and a real product example (SQS defaults, RabbitMQ acks, Kafka)
Code / implementation expected: Optional β explanation first; the example simulates a burst, a crashed consumer, a poison message and a duplicate delivery.
message-queue
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Beginners to system design who have built an API that does all its work inside the request.
Difficulty: Medium
Verified with: Node 22.22 and Python 3.12 (both print identical output). Amazon SQS and Kafka facts are cited from AWS and Apache announcements and docs.
How to read this doc: Every idea is explained in plain language first, then tagged with π Interview term: so you also learn the vocabulary an interviewer expects. Behaviour claims come from running the example; the Verified section quotes the full output.
1. Why This Even Matters β A Story First
A busy restaurant does not make the waiter stand in the kitchen until the dish is cooked. The waiter writes the order on a ticket, clips it to the rail and goes back to the tables. Cooks take tickets from the rail one by one. At 8 pm, when twenty tables order at once, the rail fills up β b