📨 System Design · System Building Blocks
Message Queue
Store work to be processed asynchronously.
The user does not always need to wait for slow background work.
After an order is placed, a queue handles email and reporting jobs.
💡 Like dropping a letter in a postbox: you walk away immediately, and the postal workers deliver it in their own time.
💡 Why it matters
Making a user wait for slow jobs like emails or reports makes the app feel sluggish and can fail under load. A queue lets you accept the work quickly and process it in the background at a steady pace. It also smooths out spikes, since the queue holds extra work instead of crushing the workers.
🛠️ How to achieve it
⚠️ Signs of trouble
- •Users wait for emails or reports to finish before a page loads.
- •Traffic spikes overwhelm the app because everything runs inline.
- •A failed background job silently loses the work.
- •Retried jobs cause duplicate emails or double charges.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. Why put slow work on a message queue?
Answer: So the user does not wait for background jobs to finish
The queue lets you respond to the user quickly and process the slow work in the background.
2. Why should queue job handlers be idempotent?
Answer: Messages can be delivered more than once, so retries must be safe
Re-delivery is normal, so a job that runs twice must not send duplicate emails or double charges.
3. What is a good use for a queue after an order is placed?
Answer: Handling email and reporting jobs in the background
Email and reporting are slow and not needed instantly, so they are ideal background queue jobs.
