SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
  • Message Queues
  • Pub/Sub
  • Message Brokers
  • Delivery Semantics
  • Dead Letter Queues
  • Kafka Deep Dive
  • Retries with Backoff
  • RabbitMQ and SQS
  • Event Streaming vs Message Queues
  • Message Ordering
  • Task Queues, Workers and Scheduled Jobs
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/APIs and Communication/Asynchronous Communication

Event Streaming vs Message Queues

A log you can replay, or a queue that hands out each task once? How to choose.

⏱ 13 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A message queue hands each message to one consumer and then usually deletes it. An event stream is a log that keeps every event for a while, so many readers can read it, and read it again.

  • Queue: a to-do list. Workers share the tasks. Once a task is done, it is gone.
  • Stream: a diary. Events are written in order and stay. Each reader keeps its own bookmark (an offset).
  • Pick a queue to share out work. Pick a stream when many systems need the same events, or you may need to replay them.

02Concept: What is it?

Both move messages from producers to consumers, so they look alike. The big difference is what happens after a message is read.

Message queue: read it and it is gone

In a queue (RabbitMQ, SQS) several workers compete for messages. Each message goes to one worker. After the worker acknowledges it, the queue deletes it. The queue is a waiting list, not a history. (See Message Queues and RabbitMQ and SQS.)

Event stream: read it and it stays

In a stream (Kafka, Kinesis) events are appended to a log and kept for a retention period, such as days, or until a size limit. Reading does not delete anything. Each consumer group remembers its own offset (its position), so groups read independently and can move the offset back to replay. (See Kafka Deep Dive.)

Queue vs stream
Message queue
✉️m4
✉️m5
✉️m6
↓each to ONE worker, then deleted
⚙️Worker 1
⚙️Worker 2
Event stream
📜0
📜1
📜2
📜3
↓EVERY group reads all, at its own offset
📊Analyticsoffset 3
🔎Searchoffset 1
The queue shrinks as work is done. The log only grows (until retention removes the old part).
🧠Two questions to ask

1. Does each message need to be handled by one worker (a task), or seen by many systems (a fact that happened)?

2. Might I need to read old messages again? If yes, you want a log.

03Real-Life Example

🍵The Ticket Counter and the Newspaper Archive
A bakery has a ticket counter. Orders are written on slips and put on a spike. Each baker takes a slip, bakes the order, and throws the slip away. No one cares about a slip after it is done. That is a queue. A newspaper keeps an archive of every edition. The sports desk, the finance desk and a new intern can all read the same editions, each at their own page. If the finance desk finds a mistake last week, it can go back and read last week again. That is a stream.
Bakery and newspaper
Messaging
Order slip on a spike
A message in a queue
A baker takes the slip and throws it away
A consumer acks, and the message is deleted
Several bakers share the slips
Competing consumers
The archive of every edition
The log of a stream
Each desk's bookmark
A consumer group's offset
Going back to read last week
Replay from an older offset
Throwing out editions older than a year
Retention
Same event, two outcomes
🧾OrderPlaced
→↓queue
⚙️One workerthen deleted
🧾OrderPlaced
→↓stream
💳Billing
📊Analytics
🔎Search

04Why Do We Need It?

🎯Choose the right tool
Using a queue for a history-keeping job, or a stream for a simple task list, creates pain later.
🔁Replay after a bug
A log lets you fix a consumer and read the events again, rebuilding its data.
👥Many readers
A stream serves many independent consumer groups. A queue shares work between workers.
🧰Simple work sharing
A queue gives you retries, delays, per-message acknowledgement and dead letters for free.
📈Throughput
Logs are built for very high volumes with sequential writes and reads.
💸Cost and effort
A managed queue can be much simpler to run than a streaming platform.
Queues are for sharing out tasks. Streams are for sharing out facts. Ask whether you will ever need to read the same thing twice.

05Where Do We Use It?

Queues fit

📧Background jobs
Send an email, make a thumbnail, run a report.
🏭Load levelling
Let workers drain a burst at a safe speed.
🔔Task distribution
Spread work across a pool of identical workers.

Streams fit

📜Event sourcing and CDC
Keep every change as an ordered record that others can read.
📊Analytics and monitoring
Feed live and batch jobs from the same events.
🔎Many downstream systems
Search, cache, warehouse and alerts all read the same stream.

06Types / Parts / How It Works

Head to head

Message queue
RabbitMQ, SQS, ActiveMQ
  • Each message goes to one consumer
  • Deleted after the ack
  • No replay of old messages
  • Smart per-message handling: retry, delay, dead letter
  • Order is limited when workers compete
Event stream
Kafka, Kinesis, Redpanda, Pulsar
  • Every consumer group gets every event
  • Kept for the retention period
  • Replay by moving the offset
  • Order per partition, high throughput
  • Consumers track offsets themselves
QuestionMessage queueEvent stream
After a message is readRemoved from the queueStays in the log
Several independent readersNeeds extra setup (fan-out to more queues)Built in: one consumer group each
ReplayNot possibleYes, within retention
OrderingBest effort, or per group in FIFO queuesStrict inside one partition
Scaling consumersAdd workers on the same queueUp to the number of partitions per group
Failed message handlingRetry, delay and dead-letter per messageYou manage offsets and build retry topics yourself
Who tracks progressThe brokerThe consumer (an offset)
Best forTasksFacts and history
📝Note
Products blur the line. Some queues offer streams or replay features, and some stream platforms offer queue-like consumption. Judge by the model you need, not by the product name.
VisualizerQueue or stream: who sees what, and what is still storedDeliver the events one by one in each mode. Then let a new consumer join late, and try a replay from offset 0.
How is the broker built?
The queue: delivered and acknowledged messages are removed.
e1
waiting
e2
waiting
e3
waiting
e4
waiting
e5
waiting
e6
waiting
C1 (odd)nothing yet
C2 (even)nothing yet
C3 (late)not joined
Still stored
6
waiting in the queue
C1 received
0
C2 received
0
C3 can read
0
Six events are waiting. Press Deliver next event to see who receives each one.

Simplified teaching model with fixed events. In a real stream, a new consumer group chooses where to start (the beginning or only new events), and events are deleted when the retention time or size limit is reached.

07How to Use It / Steps / Implementation

Choosing between them

  1. 1
    Is it a task or a fact?
    A task ("resize this image") is for one worker. A fact ("order 42 was placed") may matter to many systems.
  2. 2
    Do you need to replay?
    Rebuilding a search index or fixing a bug in a consumer needs the old events. That means a log.
  3. 3
    How many consumers will there be over time?
    If new teams will keep subscribing, a stream makes that easy. A queue needs a new queue per team.
  4. 4
    What per-message features do you need?
    Delays, per-message retries and dead letters are natural in queues. In a stream you build them with extra topics.
  5. 5
    What order do you need?
    A stream gives order inside a partition. Decide the key (such as the order id) that must stay in order.
  6. 6
    What can your team run?
    A managed queue is the smallest thing to operate. A streaming cluster takes more care.
  7. 7
    Can you combine them?
    Often yes: events flow through a stream, and a consumer turns some of them into tasks in a queue.
💡A common hybrid
Write facts to a stream as the source of truth. A small consumer reads the stream and puts tasks (send email, charge card) on a queue, where workers get retries and dead letters. You get history and easy task handling.

08Key Terms to Know

TermMeaning in easy words
QueueA line of messages where each one is handled by one consumer and then removed
Stream / logAn ordered, append-only record of events that is kept for a while
OffsetA position in the log. A consumer group remembers its own
Consumer groupA set of consumers that share the reading of a stream. Each group sees every event
Competing consumersSeveral workers reading one queue, each taking different messages
RetentionHow long (or how much) the log keeps events before deleting the oldest
ReplayReading old events again by moving the offset back
PartitionOne ordered slice of a stream. Order is kept inside a partition
AcknowledgementA consumer's note that a message is done, so a queue can delete it
Fan-outDelivering one event to many separate consumers
Log compactionKeeping only the latest event per key in a stream, instead of all of them

09Pros, Cons and Trade-offs

✅ Pros
  • Queue: simple, great per-message control
  • Queue: easy to share work across workers
  • Stream: replay and history
  • Stream: many independent readers and very high throughput
  • Stream: strict order inside a partition
⚠️ Cons
  • Queue: no history and no replay
  • Queue: fan-out needs extra queues
  • Stream: more to learn and run
  • Stream: per-message retry and delay are DIY
  • Stream: parallelism is capped by the number of partitions

Trade-offs

ChoiceWe gainWe lose
QueueSimplicity and per-message toolsHistory, replay and easy fan-out
StreamReplay, many readers, throughputSimplicity and per-message control
Long retentionMore room to replay and recoverMore storage cost
More partitionsMore parallel consumersMore overhead, and order only per partition
HybridHistory plus easy task handlingTwo systems to run

10Common Problems and Mistakes

Common mistakes

  1. Using a queue as an event history. Once read, the messages are gone, so you cannot rebuild or audit.
  2. Using a stream as a task list. You end up rebuilding retries, delays and dead letters by hand.
  3. Forgetting retention. Old events vanish, and a consumer that was down too long cannot catch up.
  4. Expecting global order in a stream. Order holds inside one partition only.
  5. More consumers than partitions. In one group the extra consumers sit idle.
  6. One slow message blocking a partition. A stuck event holds back everything behind it, unless you move it aside.
  7. Non-idempotent consumers. Replays and retries mean the same event can arrive again.

Things to watch

⏳Consumer lag
How far a group is behind the end of the log. Growing lag means trouble.
🗑️Retention versus slowest consumer
Keep the log long enough for the slowest reader to recover.
☠️Poison events
Plan where an event that always fails will go.
💾Storage growth
Long retention on a busy stream needs real disk.

11Real-World Examples

🛒E-commerce
Order events go on a stream for search, analytics and billing, while an email worker pulls tasks from a queue.
📊Data pipelines
Change events from a database flow through a stream into a warehouse and a cache.
🖼️Media processing
Uploads create tasks on a queue, so a pool of workers can share the heavy work.
🔔Notifications
A queue buffers sends and retries failures with a delay.
🕵️Fraud and monitoring
Streams feed live detectors, and the same events can be replayed to test a new rule.
🔄Data sync
A stream lets a new service load history before it goes live.
📝Note
These are common patterns, not claims about specific companies. Product features and limits change, so check the current documentation.
Mini case: a stream feeding a queue
🧾Order service
→↓append
📜Event streamkept for days
→↓read
🔀Routermakes tasks
→↓enqueue
📬Task queue
Stream (facts) Queue (tasks)
History lives in the stream. Tasks that need retries go to a queue.

12Related Topics to Read Next

Message Queues→

The basic idea of the queue side.

Kafka Deep Dive→

The most common stream platform.

RabbitMQ and SQS→

Two queues to compare against.

Pub/Sub→

Fan-out to many subscribers.

Event-Driven Architecture→

The style that makes heavy use of streams and queues.

Event Sourcing→

Keeps every change as an event, which is a natural fit for a log.

Delivery Semantics→

Both sides give at-least-once in practice, so replays must be safe.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔Queue: one consumer per message, deleted after the ack. For tasks.
  • ✔Stream: append-only log, kept for retention. For facts and history.
  • ✔Offsets: each consumer group tracks its own position, so replay is easy.
  • ✔Fan-out: built in for streams, extra queues for queues.
  • ✔Order: per partition in a stream. Not guaranteed in a standard queue.
  • ✔Retries and dead letters: natural in queues, DIY in streams.
  • ✔Both: make consumers idempotent, and watch lag or depth.
  • ✔One line: “A queue shares out tasks and forgets them. A stream shares out facts and remembers them.”
← Previous
RabbitMQ and SQS
Next →
Message Ordering