Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Asynchronous and Event-Driven Systems
Lesson 2 of 20

Queues and background work

Take slow, bursty or unreliable work off the request path.

15 min read

Do less while the user waits

Some work is slow (resizing images), bursty (sending a newsletter) or depends on unreliable third parties (SMS providers). Doing it inside the request makes users wait and lets one slow dependency take down your API.

Producers, queues and consumers

Instead, the API writes a job to a durable queue and returns immediately. Workers pull jobs from the queue at their own pace. The queue absorbs bursts, and you scale workers independently of the API.

  • The producer only waits for the queue to acknowledge the job
  • Workers can be added when the backlog grows
  • If workers crash, jobs stay in the queue

Retries, idempotency and dead letters

Jobs fail, so workers retry. Retrying means a job may run twice, so make handlers idempotent: processing the same job again has no extra effect. After a few failed attempts, move the job to a dead-letter queue so one poison message cannot block the rest.

Key takeaways

  • A queue turns a slow synchronous call into a fast acknowledgement
  • Make every consumer idempotent because retries cause duplicates
  • Use a dead-letter queue to park messages that keep failing

Sign in to track lessons and earn badges.

Synchronous vs asynchronous communicationPub/sub and fan-out

Challenge checkpoint

Course: 0/20 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 1/10Design an Image Thumbnail ServiceMove CPU-heavy resizing to queue workers so uploads return immediately and poison images get parked.Easy
All 10 challenges →