Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 21/ 31
Distributed Systems & Architecture

Message Queues & Event Streaming

Decouple producers from consumers, absorb traffic spikes, and guarantee reliable delivery.

IntermediateKafka · Competing Consumers · DLQ3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Kafka Partitions, Consumer Groups & Ordering

Scale parallel consumption while preserving per-key event ordering.

Intermediate
Delivery Guarantees & Dead-Letter Queues (DLQ)

Build idempotent consumers and handle poison-pill messages safely.

Intermediate

In plain words

A message queue is a to-do list between services: one service drops a task in, another picks it up when it’s ready. Neither has to wait for the other.

Think of it like…

A traditional queue is a customer service ticket machine (one agent handles each ticket and throws it away); Kafka is a shared DVR log that multiple teams can watch and rewind independently.

Where you’ve seen it

When you place an order, the shop puts "send confirmation email" on a queue. The email service handles it a moment later, so checkout stays fast.

Words you’ll hear

Producer / consumer
The producer sends messages; the consumer processes them.
Queue vs log
A queue removes messages once handled; a log (Kafka) keeps them for replay.
At-least-once
A message may be delivered more than once, so consumers must handle duplicates.
Dead-letter queue
Where messages go after failing too many times.

Visual diagram

Loading interactive diagram
Loading interactive exercise

Theory & deep dive

Why async decoupling protects user latency

When a user uploads a video or completes checkout, they want an instant "Success!" response in 100 ms - they shouldn’t wait 30 seconds for video transcoding, push notifications, and invoice PDFs. Dropping an event onto a queue lets your API return fast while workers process smoothly at their own pace.

Queues also absorb traffic spikes ("load leveling"): if 50,000 events arrive in 1 second, Kafka/SQS buffers them safely so downstream databases never crash.

Key takeaway: Use queues to decouple slow work, smooth bursty spikes, and isolate failures.

How it works, step by step

Step 1 of 4
Producer → Broker

1. Buffer bursty writes asynchronously

The API validates the request, appends an event/job to the broker, and returns 202 Accepted immediately without waiting for slow workers.

Peak flattening protects downstream DBs and third-party APIs
Key numbers at this step
API Latency
<10 ms
Spike Cushion
Queue depth absorbs

When to use it & trade-offs

What it is

Message queues (SQS, RabbitMQ) distribute discrete tasks across competing workers, while event streaming logs (Kafka, Pulsar) persist ordered, replayable partitions of events for multiple independent consumers.

Why it matters: Synchronous calls fail under spikes or slow downstream work (emails, video encoding, fan-out); queues smooth bursts and isolate failures.

When to reach for it

  • Decoupling slow work (email, push notifications, billing PDFs, media transcoding)
  • Streaming user activity/CDC events to search indexes, warehouses, and fraud engines
  • Rate-smoothing bursty traffic before hitting fixed-capacity downstream services

When to avoid or be careful

  • Making a user wait synchronously on an HTTP call that triggers 5 serial worker queues
  • Running 20 Kafka consumers in one group on a topic with only 4 partitions (16 sit idle)

Work Queue vs. Event Log

Work Queue (SQS / RabbitMQ)
Best for: Background jobs (emails, PDFs, webhooks, transcoding)

Strengths: Per-message ack, built-in visibility timeouts, easy horizontal worker scaling.

Watch out: Messages are deleted once acked; no multi-consumer replay history.

Distributed Log (Kafka / Kinesis / Pulsar)
Best for: Event-driven pipelines, CDC, analytics, multiple subscribers

Strengths: Retains ordered log for days/weeks; multiple consumer groups read independently & rewind.

Watch out: Scaling consumers beyond partition count is idle; requires partition-key planning.

Dead-Letter Queue (DLQ)
Best for: Isolating corrupt or failing messages without blocking queues

Strengths: Preserves failing payloads for inspection and replay.

Watch out: Needs monitoring alerts so silent DLQ growth does not go unnoticed.

Interview signals & numbers to know

When this topic comes up

  • async processing
  • traffic spike smoothing
  • fan-out to multiple services
  • Kafka
  • DLQ

Benchmarks & rules of thumb

Kafka partition throughput -
~10–50 MB/s per partition
Consumer group rule -
Active consumers ≤ partitions
Typical retention -
7–30 days (Kafka)
Max retries before DLQ -
3–5 attempts

Common mistakes & follow-ups

Common interview mistakes

  • Assuming Kafka guarantees global ordering across all partitions (it only orders within each partition)
  • Acking a message before saving its result to the DB (loses data on worker crash)
  • Skipping idempotency on consumers - at-least-once delivery WILL deliver duplicates during rebalances

Likely interviewer follow-ups

  • What happens if a Kafka topic has 6 partitions and you scale the consumer group to 12 instances?
  • How do you prevent a single corrupt “poison pill” message from stalling a Kafka partition?
  • Explain how consumer offsets and consumer groups work in Kafka.
Interview tip: Always pair “at-least-once delivery” with “idempotent consumers + DLQ” - it shows production maturity immediately.

Knowledge check

Loading quiz

Put it into practice

Design full architectures with AI feedback

Apply Message Queues & Event Streaming inside real High-Level Design prompts or review Q&A flashcards.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Microservices & Service Mesh
Next topic
Stream & Batch Processing