Backend & Node.js · APIs, data and failure
Why use a message queue and what are the delivery guarantees?
Short answer
A queue decouples producers from consumers, buffers bursts and enables retries and background processing. Most brokers provide at-least-once delivery, so consumers must be idempotent; exactly-once is usually an end-to-end design, not a broker switch.
A queue lets a producer acknowledge work without waiting for every downstream step. That improves latency and resilience, but it introduces asynchronous state, ordering questions and duplicate delivery. The system must tolerate a message being processed more than once or not immediately.
await channel.publish(
"orders",
Buffer.from(JSON.stringify({ type: "order.created", id: order.id })),
{ persistent: true },
);What to design for
- At-least-once delivery means duplicates are normal
- Ordering is usually guaranteed per partition or queue, not globally
- A dead-letter queue captures messages that repeatedly fail
- Visibility timeouts and acknowledgements determine when a message is retried
- The transactional outbox avoids losing a message between the database commit and the publish
- Backpressure matters: an unbounded queue hides a slow consumer until it becomes an outage
The outbox pattern writes the business change and the outgoing event in the same database transaction, then a relay publishes the event. That closes the dual-write gap. Consumers should deduplicate by message id or by a business key and make side effects idempotent.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does at-least-once delivery imply for consumers?
- 2How does the transactional outbox work?
- 3When would you choose a queue over a direct call?
- 4How do you handle poison messages?
Say it in the interview
A queue decouples services, absorbs bursts and enables retries and background work. Most brokers give at-least-once delivery, so I design consumers to be idempotent and expect duplicates. I use an outbox when a database write and a publish must not diverge, and a dead-letter queue for poison messages. Ordering and backpressure are design decisions, not assumptions.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Backend & Node.js mock interview and get scored feedback on depth, clarity and confidence.