Backend & Node.js · APIs, data and failure

Why use a message queue and what are the delivery guarantees?

Mediummessage queuesasyncdistributed systemsUpdated Oct 2026
Quiz this track

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.

js
await channel.publish(
  "orders",
  Buffer.from(JSON.stringify({ type: "order.created", id: order.id })),
  { persistent: true },
);
The publish is fast, but the consumer runs later. The message must carry enough data or a reliable reference to act on.

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.

A queue is not a database. Do not use it as the only record of critical state, and set retention and replay policies deliberately.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What does at-least-once delivery imply for consumers?
  2. 2How does the transactional outbox work?
  3. 3When would you choose a queue over a direct call?
  4. 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.