Skip to content

How it works

A producer pushes a message into the queue; the queue stores it durably; a consumer pulls or receives it and acknowledges completion; the queue deletes it.

The mechanism differs slightly across systems, but the shape is uniform. The producer serializes a message and sends it to a queue endpoint. The queue persists the message and makes it available for consumption. A consumer receives one or more messages, processes them, and acknowledges. On ack, the queue deletes the message. If the consumer fails before acking, the queue makes the message available again after a visibility timeout — that is what "at-least-once delivery" means in practice.

graph LR
  P[Producer] -->|send| Q[Queue]
  Q -->|deliver| C[Consumer]
  C -->|ack| Q
  C -->|nack / timeout| Q
  Q -->|too many retries| DLQ[Dead Letter Queue]

Delivery guarantees define what happens when things go wrong. At-most-once means the message may be lost but is never processed twice. At-least-once means it may be processed twice but is never lost. Exactly-once is the theoretical ideal, but in practice it requires transactional coordination between producer, queue, and consumer, and the cost is usually high enough that most teams settle for at-least-once plus idempotent consumers. The choice is not a preference; it is a design decision driven by what the system can afford to get wrong.

Designing a queue-based pipeline

  1. Pick the delivery guarantee deliberately

    At-least-once with idempotent consumers is the practical default. Exactly-once only when the business genuinely cannot tolerate duplicates, and the cost is justified.

  2. Bound the queue

    Set a maximum queue size, a retention period, and a backlog alert. An unbounded queue is a silent failure waiting to happen.

  3. Configure a dead letter queue

    Every message that fails N times should land in a DLQ, not be retried forever. DLQs are the input to human investigation; without them, poison messages block the pipeline.

  4. Make consumers idempotent

    Given at-least-once delivery, consumers will see duplicates. Design every consumer to tolerate them: dedupe keys, upserts, or explicit state checks.

Horizontal scaling is part of the design. Multiple producers can write to the same queue without coordination. Multiple consumers can read from the same queue, and the queue distributes messages among them (competing consumers pattern). That is what allows the pipeline to absorb load by adding consumers, without touching producers. In partitioned systems like Kafka, the distribution is stricter: messages with the same key go to the same partition, and each partition is consumed by exactly one consumer within a group, which preserves order per key at the cost of a fixed consumer count per topic.