← System Design
Core Concepts

What is a Message Queue?

Watch: "Message Queues in System Design Interviews w/ Meta Staff Engineer" — Hello Interview

A message queue is a buffer between services: producers put messages (tasks or events) in, and consumers take them out and process them later, at their own pace. The producer doesn't wait for the work to be done. Examples: RabbitMQ, Amazon SQS, Apache Kafka (a log rather than a classic queue), Google Pub/Sub.

In simple words

A restaurant's order rail. Waiters clip order tickets on the rail and go back to customers; cooks take tickets off the rail at their own pace. A rush of orders doesn't crash the kitchen, it just makes the rail longer for a while.

Producer, queue and consumersAPI server(producer)QueueWorker 1Worker 2Dead-letterqueuepublish, return202deliverdeliverafter N failures
The producer answers immediately; workers process at their own pace and failed messages are set aside.

Why It Exists

How It Works

API server --publish--> [ queue: m5 m4 m3 m2 m1 ] --> worker 1
  (returns 202                                     --> worker 2
   immediately)                                     --> worker 3

worker: receive m1 -> process -> ACK -> queue deletes m1
        crash before ACK -> after a visibility timeout m1 is redelivered
        fails N times -> m1 moves to a dead-letter queue (DLQ) for inspection

Types

Delivery Guarantees

Key Pointers

Follow-up Questions

RabbitMQ/SQS vs Kafka?
Classic queues delete messages once acknowledged and suit task distribution with per-message acks and routing. Kafka keeps an ordered, replayable log per partition with very high throughput, suiting event streaming, multiple independent consumers and reprocessing history.
How do you keep order for one user's events?
Use a partition/message-group key such as user_id: all of that user's messages go to one partition and are consumed in order, while different users are processed in parallel.
Consumers fall behind and the queue keeps growing. What do you do?
Scale consumers (up to the partition count for Kafka), make processing faster or batched, shed or defer low-priority work, and apply backpressure upstream if needed.

Related