All the basics

What is a message queue?

Drop slow work into a line and answer right away. A helper takes jobs from the line and does them later.

Picture a ticket window. People join the line and are served one at a time, so nobody has to stand at the counter while the clerk works.

Press Play to watch it run · 5 steps

A sign-up must send an email. Without a line the customer waits for it. With a line the app answers at once.

A request that does not waitA sign-up must send an email. Without a line the customer waits for it. With a line the app answers at once.CustomerYour appWaiting lineWorkerEmail service

Tap any box to see what it is and what it talks to.

  • Client
  • Service
  • Queue
  • Worker
  • External API
Open in playground
Text description
  1. A customer signs up. Your app must also send a welcome email.
  2. The app calls the email service and waits for it.
  3. The email service is slow today. It takes 3 seconds.
  4. The customer stares at a spinner for the whole 3 seconds.
  5. If the email service is down, the sign-up fails too.
  • The user gets an answer now; the work happens later.
  • A line absorbs bursts that would flatten the slow service.
  • A job may run twice, so doing it twice must be safe.

Reach for it when

When slow work can wait, like sending 10,000 emails after a sale or resizing uploads. Not when the answer is needed now.

The catch

After a crash the line can hand out a job twice, so a customer gets two emails unless repeating is safe.

Say it in an interview“I would put slow, non-urgent work on a queue so the request returns fast and a worker handles it. Workers must be idempotent, because delivery can repeat.”