teluzia.Cloud Engineer · Day 143
CHAPTER 21 · CLOUD SYSTEM DESIGN

Queues and asynchronous processing

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Queues is today's starting point. A producer adds 120 jobs/minute and consumers finish 100. Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue. You will connect this with delivery and idempotency and retries and dead-letter queues. The lesson's artifact brings these decisions together: Trace five order messages including a duplicate and poison message through acknowledgement, retry and dead-letter states using a table.

Think of it this way

A queue is a numbered service line: repeated tickets need duplicate detection, and a broken ticket needs a separate handling desk.

TOPIC 01 / 03Step by step

Queues

A queue decouples producers from consumers and absorbs bursts. Track message age and backlog, not only depth; arrival rate exceeding processing capacity produces growing delay. A producer adds 120 jobs/minute and consumers finish 100. Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue.

WORKED EXAMPLE
A producer adds 120 jobs/minute and consumers finish 100. Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue.

An arrival rate counts produced messages; a service rate counts completed messages; backlog age measures waiting time. Imagine a queue briefly fills during a scheduled import but drains before the promised processing deadline. Depth alone might suggest an incident, while age and completion rate show the buffer is doing its job. Conversely, a small queue of stuck old items can harm users despite low depth. Track inflow, outflow and oldest-item age together, and include the work duration distribution. A queue decouples timing but does not create unlimited processing capacity. Longer buffering smooths bursts at the expense of latency and expired work. Define a processing deadline and scaling or rejection decision around the user contract rather than choosing a depth threshold with no workload context.

Why this matters

Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue.

A common trap

Queue depth alone reveals how long the oldest message has waited.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Queues

A queue decouples producers from consumers and absorbs bursts. Track message age and backlog, not only depth; arrival rate exceeding processing capacity produces growing delay. A producer adds 120 jobs/minute and consumers finish 100. Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue.

WORKED EXAMPLE
A producer adds 120 jobs/minute and consumers finish 100. Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue.

An arrival rate counts produced messages; a service rate counts completed messages; backlog age measures waiting time. Imagine a queue briefly fills during a scheduled import but drains before the promised processing deadline. Depth alone might suggest an incident, while age and completion rate show the buffer is doing its job. Conversely, a small queue of stuck old items can harm users despite low depth. Track inflow, outflow and oldest-item age together, and include the work duration distribution. A queue decouples timing but does not create unlimited processing capacity. Longer buffering smooths bursts at the expense of latency and expired work. Define a processing deadline and scaling or rejection decision around the user contract rather than choosing a depth threshold with no workload context.

Why this matters

Backlog grows by 20/minute; oldest-message age tells you whether customer delay is becoming unacceptable despite a seemingly small queue.

A common trap

Queue depth alone reveals how long the oldest message has waited.

Delivery and idempotency

At-least-once delivery can repeat a message. An idempotency key and durable processing record prevent repeated business effects; deleting a message too early risks losing unfinished work. Process order o17, save its durable completion marker, then acknowledge the message. If delivery repeats o17, consult the marker and skip the second charge; acknowledge only after the safe effect is recorded.

WORKED EXAMPLE
Process order o17, save its durable completion marker, then acknowledge the message. If delivery repeats o17, consult the marker and skip the second charge; acknowledge only after the safe effect is recorded.

Acknowledgement removes or completes a delivered item; visibility timeout temporarily hides an in-progress item; idempotency prevents repeated business effects. Imagine processing takes longer than the visibility interval. Another worker can receive the same item while the first is still working, so timeout choice and duplicate protection both matter. Persist the intended effect and completion identity using a design that handles crashes at each boundary. Acknowledge after the successful durable result, and make repeated delivery consult that result. 'Exactly once' should not be casually inferred from a queue setting. Duplicate handling adds storage and logic, but protects orders, payments and notifications against retries and worker failure. Walk through a crash before and after acknowledgement to confirm the operation remains recoverable without silently losing or duplicating work.

Why this matters

If delivery repeats o17, consult the marker and skip the second charge; acknowledge only after the safe effect is recorded.

A common trap

At-least-once delivery guarantees every business action happens exactly once.

Retries and dead-letter queues

Retry transient failures with bounded attempts and backoff. A dead-letter queue isolates repeated failures but still needs ownership, inspection and a safe replay procedure. A malformed job fails three bounded attempts and moves to a dead-letter queue. Fix its data or consumer first, then replay using the same idempotency protection so replay cannot duplicate effects.

WORKED EXAMPLE
A malformed job fails three bounded attempts and moves to a dead-letter queue. Fix its data or consumer first, then replay using the same idempotency protection so replay cannot duplicate effects.

A transient failure may succeed on retry; a poison message repeatedly fails for stable reasons; a dead-letter queue isolates exhausted attempts. Imagine a malformed schema passes through the producer and fails every consumer attempt. More rapid retries consume capacity without changing the input. Bound attempts, use backoff for plausible transient failures and send exhausted items to an owned inspection path. Preserve enough metadata to identify source, reason and attempts without retaining unnecessary private payloads. Repair the producer or consumer before replay, then replay a small synthetic sample with idempotency protection. Isolation helps healthy traffic continue but can hide unfinished customer work if nobody reviews the dead-letter queue. Set an age or count signal and a responsible owner rather than treating transfer to that queue as resolution.

Why this matters

Fix its data or consumer first, then replay using the same idempotency protection so replay cannot duplicate effects.

A common trap

A dead-letter queue automatically fixes and replays poison messages.

KEEP THESE WITH YOU

Today’s takeaways

Queues: A queue decouples producers from consumers and absorbs bursts.

Delivery and idempotency: At-least-once delivery can repeat a message.

Retries and dead-letter queues: Retry transient failures with bounded attempts and backoff.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed