Message Queues
Some work is slow, like sending an email or making an invoice. A message queue lets your app say "I will do it soon" and reply at once. Workers then finish the slow work in the background.
New words
- Synchronous
- You wait until the work is finished before you get a reply.
- Asynchronous
- You get a reply at once and the work finishes later.
- Producer
- The part of the app that adds a job to the queue.
- Queue
- A line of jobs. The first job in is the first job out.
- Consumer (worker)
- A program that takes jobs from the queue and does them.
- Retry
- Trying a failed job again after a short wait.
- Dead-letter queue
- A separate queue that keeps jobs that failed again and again.
What you will learn
- The problem: a busy dosa counter
- Synchronous and asynchronous work
- Producer, queue and consumer
- A sudden rush: the queue grows and nothing is lost
- Try it: the dosa counter in your browser
- When a job fails: retries and the dead-letter queue
- When not to use a queue
- Trade-offs
- In a real system
- Interview tip
- Key takeaways
10 quiz questions at the end.
The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.