System DesignIntermediate15 min

Queues, streams & async work

Decouple producers from consumers so spikes, slow work and failures stop cascading.

See it on the map

A queue lets a fast producer hand work to slower consumers without making the user wait. It absorbs spikes, lets you retry, and lets each side scale independently. Anything slow or unreliable, such as email, image processing or third-party calls, belongs behind one.

A log or stream keeps events in order and lets many consumers read at their own pace and replay history. That fits event-driven designs and rebuilding derived data. A classic queue deletes a message once handled, which fits task distribution.

Delivery is usually at least once, so consumers will see duplicates and must be idempotent. Watch queue depth and age of the oldest message, and apply backpressure or shed load before an unbounded backlog becomes the outage.

Key points

  • Queues turn spikes into latency instead of failures.
  • Assume at-least-once delivery and make handlers idempotent.
  • Monitor depth and oldest-message age, not just throughput.
  • Use a dead-letter queue so poison messages do not block everything.

Trade-offs

ChoiceYou gainYou pay
Task queueSimple work distribution, easy retriesNo replay once consumed
Event logReplay, many independent consumersOrdering and partitioning need care

Answer these out loud

  1. 1Your email worker crashes after sending but before acknowledging. What does the user receive and how do you prevent it?
  2. 2How would you protect a downstream service that can handle 100 requests per second from a queue with a 1M message backlog?

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/queues-and-streams

This unlocks