12 / 25 · Asynchronous work

Message queues

A message queue holds work until a consumer can process it. It separates accepting work from finishing it. Durability, retries, ordering and duplicate delivery depend on the queue and configuration.

What you will practise

  • Trace publish/process/acknowledge
  • predict duplicates
  • calculate backlog growth

Before you start: Producer, consumer and durable side effect.

About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.

Download MP4Captions

Listen without the videoDownload audio

The same pre-recorded voice as the video. Starting audio pauses the video, and starting the video pauses audio.

Chapters and full transcript

Let us understand message queues. A restaurant writes orders on tickets. The cook takes a ticket when ready instead of making every customer stand at the stove. A ticket can be picked up twice after confusion, so the kitchen needs an order number to avoid preparing and charging the same order twice. A message queue holds work until a consumer can process it. It separates accepting work from finishing it. Durability, retries, ordering and duplicate delivery depend on the queue and configuration.

Follow the normal path. A booking succeeds and records a receipt job reliably. Coordinate this with business storage, for example using an outbox, so a crash does not lose the obligation. The queue stores work while consumers catch up. Stored backlog buys time, but retention, storage and acceptable delay remain finite. SeatSpot sends receipts asynchronously after booking. The booking request should not wait for an email provider, but it must reliably record that a receipt needs to be sent.

Now change one condition. Workers pull jobs at a safe rate. Their combined concurrency must respect email provider quotas and other downstream capacity. A common misunderstanding is this: At-least-once delivery means exactly one business effect. Delivery and the external effect have different failure gaps. Think about this. A worker sends a receipt then crashes before acknowledgment. What can happen next? Pause the video and make your prediction. The job may be delivered again. A stable event ID and appropriate idempotency or reconciliation are needed around the external effect.

Let us reason with a concrete example. Jobs arrive at 90/second and each worker safely processes 20/second. Four workers provide 80/second, so backlog grows by about 10/second. Five provide 100/second and drain only about 10/second of existing backlog in the simplified model. Add safe capacity or shed work, respecting the email provider quota. More consumers are not safe if they collectively exceed the next dependency limit. These figures are teaching examples, not production guarantees.

Turn the idea into a design decision. A worker can send an email and fail before acknowledging its job. The queue may deliver that same logical job again. Use stable job identity and an appropriate idempotency or reconciliation strategy. A delivery guarantee alone does not guarantee exactly one external effect. When you try the practice task, look for this result. At a constant arrival rate, five workers leave only about ten jobs/second to drain the backlog.

Check your understanding. After bounded attempts, move a poison job to a monitored dead-letter path. Investigate and repair before controlled replay instead of retrying forever. Here is a challenge. A worker sends an email then crashes before acknowledging. What happens? Pause before the answer. Redelivery may send another email unless the consumer/provider has an idempotency or deduplication strategy. A durable order/event identity and reconciliation make this case explicit. For an interview, discuss backlog age, retries, poison jobs and idempotency. Say what you would measure, not only which tool you would buy.

Start with an everyday picture

A restaurant writes orders on tickets. The cook takes a ticket when ready instead of making every customer stand at the stove. A ticket can be picked up twice after confusion, so the kitchen needs an order number to avoid preparing and charging the same order twice.

Why SeatSpot needs this

SeatSpot sends receipts asynchronously after booking. The booking request should not wait for an email provider, but it must reliably record that a receipt needs to be sent.

Trace one step at a time

Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.

Booking serviceDurable queueWorkerEmail providerDead-letter queue

Step 1 of 6 · Accepting is not finishing

Record outgoing work

A booking succeeds and records a receipt job reliably. Coordinate this with business storage, for example using an outbox, so a crash does not lose the obligation.

Read all six mechanism steps
  1. Record outgoing work

    A booking succeeds and records a receipt job reliably. Coordinate this with business storage, for example using an outbox, so a crash does not lose the obligation.

  2. Buffer a burst

    The queue stores work while consumers catch up. Stored backlog buys time, but retention, storage and acceptable delay remain finite.

  3. Process within limits

    Workers pull jobs at a safe rate. Their combined concurrency must respect email provider quotas and other downstream capacity.

  4. A worker crashes

    A worker can send an email and fail before acknowledging its job. The queue may deliver that same logical job again.

  5. Protect the effect

    Use stable job identity and an appropriate idempotency or reconciliation strategy. A delivery guarantee alone does not guarantee exactly one external effect.

  6. Handle persistent failure

    After bounded attempts, move a poison job to a monitored dead-letter path. Investigate and repair before controlled replay instead of retrying forever.

Pause and make a prediction

A worker sends a receipt then crashes before acknowledgment. What can happen next?

Answer aloud or write your reasoning in the lesson notes before revealing the explanation.

Correct a common misunderstanding

Claim to question: At-least-once delivery means exactly one business effect.

Better explanation: Delivery and the external effect have different failure gaps.

Calculate a queue backlog

A paper or whiteboard task. No cloud account or paid infrastructure is required.

  1. Use arrivals of 90 jobs/second and four workers at 20 each.
  2. Compute the 10-jobs/second backlog growth.
  3. Add a fifth worker and calculate how slowly the old backlog drains.

Check what you can explain

This is your self-check, not an automated grade. Try again without the diagram tomorrow.

0 of 3 goals checked. Choose one remaining idea to practise next.

These checkboxes reset when you leave. Use your saved lesson notes and completion marker to record lasting progress.

Teach it back

Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.

Try it before viewing the solution

A worker sends an email then crashes before acknowledging. What happens?

Check one key idea

A crash before acknowledgment may cause:

Your explanation and interview notes

Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.

Loading your local notes…

Official references and next reading

The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.