Queue vs Pub/Sub vs Log/Streaming
A queue distributes work and deletes on ack (no replay); pub/sub fans a copy to every subscriber; a log retains an ordered stream that many consumer groups read at their own offset and can replay.
Three models hiding under "messaging"
Picking the wrong one is one of the most common design-review mistakes, so learn to name them precisely.
Point-to-point queue (Amazon SQS, RabbitMQ, a Redis list). Producers push messages; a pool of competing consumers pulls them. Each message is delivered to exactly one consumer in the pool, and once that consumer acks, the message is deleted. This is work distribution: add consumers to process faster, and no two workers do the same job. The defining property is that the message is consumed and gone. No replay, no second reader. RabbitMQ adds routing (exchanges, bindings) and per-message DLQs; SQS adds a visibility timeout so an un-acked message reappears for another worker after a crash.
Pub/sub (Amazon SNS, Google Pub/Sub topics, RabbitMQ fanout). A producer publishes to a topic;
every subscriber gets its own copy. This is fan-out: one OrderPlaced reaches email, analytics,
and fraud independently. Classic pub/sub is often fire-and-forget: if a subscriber is down when the
message is published and there is no per-subscriber durable queue, that subscriber misses it. The
common production pattern is SNS-to-SQS fan-out, where the topic delivers a copy into each
subscriber's own durable queue so slow or offline subscribers do not lose messages.
Log / stream (Apache Kafka, Amazon Kinesis, Apache Pulsar). Messages are appended to a durable, ordered, append-only log and retained by time or size (say seven days), regardless of who has read them. Consumers do not delete messages; each consumer group tracks its own offset (a cursor) into the log and reads forward. Because the data stays and each group has an independent cursor, a log gives you both fan-out (many groups) and replay (rewind an offset to reprocess history). A brand-new analytics team can start today and read the last 30 days from offset zero.
The two axes: retention and who tracks delivery
| Model | Delete on consume? | Who tracks position? | Replay? | Fan-out? |
|---|---|---|---|---|
| Queue (SQS) | yes | broker (per-message ack) | no | no (competing consumers) |
| Pub/Sub (SNS) | yes (per subscriber) | broker (per subscriber) | no | yes |
| Log (Kafka) | no | consumer (own offset) | yes | yes (per group) |
A queue's broker tracks per-message delivery and acks; it is push-ish and the broker owns state. A log is pull-based: the consumer owns its offset, which is why one slow consumer group cannot slow another and why replay is just "reset my offset." That consumer-owned-offset design is the whole reason a log scales to many independent readers and supports reprocessing.
Interview nuance: the classic wrong turn is choosing a queue when the requirement is "multiple independent teams, each reading the full stream, some needing to replay 30 days." A queue deletes on consume and serves one consumer per message. The moment you hear "replay," "reprocess," or "N independent consumer groups over the same data," reach for a log.
Recap: a queue distributes work and deletes on ack (no replay); pub/sub fans a copy to every subscriber; a log retains an ordered stream that many consumer groups read at their own offset and can replay.
Name the messaging model each requirement points to.
Apply
Your turn
The task this lesson builds to.
Design the messaging backbone for an order system that needs (a) exactly one worker per order, (b) multiple independent subscribers to 'order placed', and (c) 30-day replay for a new analytics team; map each requirement to a model.
Think about
- How does retention differ between a queue and a log?
- Why does a log support many independent consumer groups and replay?
- What is the difference between broker-tracked delivery and consumer-driven offsets?
Practice
Make it stick
A second problem on the same idea, so it survives past today.
Design the event backbone for DoorDash-scale order events (roughly 100k orders per hour at peak) where the same OrderCreated stream must feed a real-time dispatch matcher, a per-restaurant notification service, a fraud pipeline, and a data-warehouse ingest that reprocesses the last 7 days whenever the ML team ships a new feature. Choose the model(s) and justify retention and consumer topology.
Think about
- Which two requirements structurally disqualify a queue as the backbone?
- What partition key preserves the ordering that actually matters?
- Who sets the retention window: the fastest consumer or the replay need?