Data5 min read10 interview questions
Message queues: what and why
How apps hand work to each other without waiting.
In one sentenceA queue lets one part of a system drop off a job and carry on, while another part picks it up when it is ready.
Think of it like thisIt is a ticket counter at a bakery: you leave your order and get on with your day, and the kitchen works through the tickets in order.
The big picture
Tap any step to see where to use it, how to use it and an example result.
The problem it solves
If your signup page also sends emails, resizes photos and updates reports, the user waits for all of it. With a queue, the page puts jobs in and answers instantly.
Why it makes systems calmer
Spikes of work are absorbed by the queue and handled at a steady pace. If a worker crashes, the job goes back to the queue instead of being lost. You can add more workers when the queue grows.
Things to plan for
A job may be delivered more than once, so make it safe to repeat. Jobs that keep failing should move to a separate "dead letter" queue for a person to look at. RabbitMQ, Amazon SQS and Cloudflare Queues are examples.
Common mistakes
- Running jobs that cannot safely be repeated, such as charging a card twice.
- Having no plan for jobs that keep failing.
- Using a queue when a simple function call would do.
Quick recap
- Queues let work happen later
- They smooth out sudden bursts
- Workers can be added when needed
- Design jobs so repeating them is safe
Try it yourself
Write a tiny program with a list as a queue: one function adds ten jobs, another takes them one at a time and prints them.
Top 10 interview questions
Ordered from basic to advanced. Try answering out loud first, then open the answer.
What is a message queue?Basic
A system that holds messages between a sender (producer) and a receiver (consumer), so the sender can hand off work without waiting for it to finish.
Why use a queue instead of calling a service directly?Basic
It decouples the two sides, smooths traffic spikes, lets work run in the background, and keeps messages safe if the receiver is down or slow.
What are a producer and a consumer?Basic
A producer creates and sends messages. A consumer receives and processes them, and many consumers can share the work.
Give some everyday uses of queues.Basic
Sending emails, resizing images, processing payments, generating reports and passing events between services.
What is the difference between a queue and publish/subscribe?Intermediate
In a queue each message is handled by one consumer. In publish/subscribe a message is delivered to every subscriber that is interested, such as several services reacting to the same event.
What is an acknowledgement (ack)?Intermediate
The consumer tells the broker it finished the message. If no ack arrives, the broker makes the message available again so it is not lost.
What is a dead-letter queue?Intermediate
A separate queue for messages that keep failing. It stops one bad message from blocking everything and lets you inspect and fix it later.
What do at-most-once, at-least-once and exactly-once delivery mean?Intermediate
At-most-once may lose messages but never repeats. At-least-once never loses but may deliver duplicates. Exactly-once is very hard and is usually approximated by at-least-once plus idempotent handling.
What is idempotency and why do consumers need it?Advanced
An operation is idempotent when doing it twice has the same effect as once. Since messages can be delivered more than once, consumers should detect repeats, for example with a unique message ID.
How do RabbitMQ and Kafka differ?Advanced
RabbitMQ is a traditional broker that routes messages and removes them once consumed. Kafka is a distributed log that keeps events for a set time so many consumers can read and replay them at their own pace.
Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.