Skip to the guide

Why async: queues as shock absorbers

BeginnerConcept3 pages

Some work has to finish before the user gets an answer, and some doesn't: nobody needs to wait for the confirmation email or the resized photo. Moving that work onto a queue keeps responses fast and lets a burst wait its turn. Interviewers expect you to spot which work can wait, and to say what happens when the queue grows.

The dry cleaner's counter

At a dry cleaner, you hand your shirt to the clerk at the counter. She writes it in the book, gives you a numbered ticket, and you leave instead of standing there while it's pressed. The shirts hang on a rack behind the counter, and the pressers in the back work through them at their own steady pace. On Monday morning everyone drops off a week's shirts and the rack fills up; by Wednesday it's empty again. Nobody is turned away, and the shop doesn't hire ten pressers for one busy morning.

  • handing the shirt to the clerk → a request to the checkout server, answered once the order is written down in the orders database
  • the ticket → a job ID the user can check later
  • the rack → the queue, holding jobs that are waiting
  • the pressers → workers (also called consumers) taking jobs at their own pace
  • Monday's pile → a burst, absorbed by the queue and worked off later