by Samy (Kondasamy Jayaraman)

Module 33 · Queues and background jobs

Beginner · by Samy (Kondasamy Jayaraman)

How an order waits its turn

When you press Buy, the page answers at once, but the parcel is packed later, by a worker taking jobs off a queue. Here you run Larkspur’s sale through a ticket rail, knock a worker over mid-job, and set up the sale day.

Read as

The whole idea in one example

Gil’s order, in the rush

Work at the till

waits

18 min

The page spins while the till does every order ahead of it.

Work on a queue

answered

0 min

The page answers at once. A worker packs the order later.

Waits come from a simulated sale: Larkspur’s own orders and planning-number job times, slowed so you can watch.

How it works

Four ideas carry the module

  1. 1 A ticket, not a wait

    The till answers; a worker does the slow part

    Amazon SQS’s guide says a received message stays in the queue, hidden from other consumers for a visibility timeout (30 seconds by default); if it is not deleted in time, it becomes visible again.

    Source, checked 25 October 2026

  2. 2 The line grows

    More orders arrive than one worker finishes

  3. 3 Try again later

    Backoff and jitter ride out an outage

    Marc Brooker (AWS Architecture Blog, 2015) found that backoff alone still leaves retries in clusters, and that adding jitter spreads them out and more than halves the calls in his simulation.

    Source, checked 25 October 2026

  4. 4 Ran twice

    A crash brings a job back, so jobs must be safe to repeat

    Amazon SQS’s guide says a standard queue may deliver a message copy again, and asks for idempotent apps: ones not harmed by processing the same message more than once.

    Source, checked 25 October 2026

The story

Larkspur’s sale morning

A sale floods Larkspur Supply Co. with orders; the team moves the slow work onto a queue, and learns it keeps work safe while it waits, and any job may run twice. You’re on the team that runs the packing room.

38
orders in Larkspur’s sale morning, the one every chapter runs
60
minutes the morning runs, one step at a time
4
workers at most on the packing benches
3
settings win chapter 7 with the fewest workers

Your path

The chapters

  1. Chapter 1

    Waiting at the till

    What does a customer see when the till does all the work?

  2. Chapter 2

    A ticket and a worker

    What changes for the customer when the work moves to a queue?

  3. Chapter 3

    When the line grows

    What happens when jobs arrive faster than workers finish them?

  4. Chapter 4

    Try again later

    How soon should a failed job try again?

  5. Chapter 5

    Ran twice

    What happens to a job whose worker falls over halfway?

  6. Chapter 6

    The job that never works

    What should a queue do with a job that will never succeed?

  7. Chapter 7

    Run the sale day

    Which settings lose no good order and keep waits short, with the fewest workers?

Who it’s for

  • Engineers
  • Product managers
  • Analysts
  • No code needed

Anyone whose product sends an email, charges a card or packs a parcel after the click, and who wants to know why jobs wait, retry, and sometimes run twice. No background needed.