LESSON 05 · Backpressure

Decide what happens when the queue is full

A queue absorbs bursts but not sustained overload, so it needs a limit and a deliberate rule for what happens at that limit.

SYSTEM VIEW

The failure path

Diagram view
Arrivals—
Backlog—
New job waits—

Watch a queue fill when jobs arrive faster than workers finish, then choose what happens at its limit.

  1. The Batch importer sends 1,200 jobs a second into the Job queue, and the Workers finish 1,000. A queue smooths a burst only if arrivals stay below the service rate on average. Here the backlog grows by 200 every second.

    In
    1,200 jobs/s
    Out
    1,000 jobs/s

    What changed

    • 1,200 jobs/s arrive
    • Workers finish 1,000/s
    • Backlog grows 200/s
  2. The Job queue has no limit. After 10 minutes it holds 120,000 jobs, and a new job waits 2 minutes. This goes on until memory runs out or every job is too old to matter: the queue hides the overload rather than fixing it.

    After 10 min
    200/s × 600 s = 120,000
    New job waits
    120,000 ÷ 1,000/s = 2 min

    What changed

    • 10 minutes pass
    • 120,000 jobs queued
    • New job waits 2 min
  3. Instead, a limit makes the overload visible. Size it from the wait you can accept: at 1,000 a second, a limit of 5,000 jobs means about 5 seconds of waiting at most. Now the Job queue is full, and 200 jobs a second don’t fit.

    Workers finish
    1,000/s
    Limit
    5,000 jobs
    Longest wait
    about 5 s

    What changed

    • Limit: 5,000 jobs
    • Longest wait about 5 s
    • 200 jobs/s don’t fit
  4. Backpressure is a signal telling producers to slow down. The Batch importer reads a file, so it can wait: it drops to 1,000 jobs a second and nothing is lost. Block the producer like this when it can wait and the data matters.

    Signal
    slow down
    Use when
    the producer can wait

    What changed

    • Slow-down signal
    • Importer sends 1,000/s
    • Nothing lost
  5. API callers are people on HTTP, who can’t be slowed without holding their connections open until they give up. So the Job queue rejects the 200 a second that don’t fit with an explicit error, and each caller decides what to do next.

    Rejected
    200/s, explicit error
    Use when
    the caller can decide

    What changed

    • Batch importer
    • API callers, 1,200 req/s
    • Error: queue full, 200/s
  6. Phones send live locations, and fresh data replaces stale data. So at the limit the Job queue drops its oldest location to make room for the newest, 200 a second. The Workers spend their time on the newest positions.

    Dropped
    oldest, 200/s
    Use when
    fresh replaces stale

    What changed

    • API callers
    • Phones: live locations
    • Oldest dropped, 200/s
  7. The Order service’s work must survive, so jobs past the limit spill to the Disk queue, 200 a second. Disk is a larger queue with its own limit and a backlog to repay. Depth still reads 5,000, so watch the oldest job’s age.

    Spilled
    200 jobs/s to disk
    Disk
    its own limit
    Watch
    oldest-job age

    What changed

    • Phones
    • Order service
    • Disk queue: +200 jobs/s

Space plays · ← → step · Home resets

THE IDEA

How it works

A queue smooths a burst only if the average arrival rate stays below the service rate. As an example, 1,200 jobs arrive per second and workers finish 1,000. The backlog grows by 200 per second. After 10 minutes it holds 120,000 jobs, and a new job waits 2 minutes. With no limit, this continues until memory runs out or every job is too old to matter. The queue has not fixed the overload, only hidden it.

A bound makes this visible, and you can size it from the wait you can accept: at 1,000 per second, a limit of 5,000 jobs means about 5 seconds of waiting at most. Backpressure is a signal telling producers to slow down. It works only when a producer can, such as a batch importer reading a file. A person waiting on an HTTP response cannot be slowed without holding their connection open until they give up.

So choose by the work. Block the producer when it can wait and the data matters. Reject new work with an explicit error when the caller can decide what to do next, as with API requests. Drop the oldest when fresh data replaces stale data, as with live locations. Spill to disk when work must survive, remembering that disk is a larger queue with its own limit and a backlog to repay. Watch the age of the oldest item, not only depth.

Chat System limits each gateway’s outbound queues, Notification System reserves capacity so a campaign cannot delay receipts, and News Feed bounds fanout with backpressure.

DECISION POINT

One service has two full queues. One holds live driver locations, sent every 4 seconds per driver. The other holds payment capture jobs. What should each queue do at its limit?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • A queue hides sustained overload until memory or latency exposes it.
  • Size the bound from the longest wait the work can tolerate.
  • Backpressure needs a producer that can slow down; otherwise reject or drop.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

Workers finish 500 jobs per second, and each job should wait no more than 4 seconds. What is a sensible queue limit?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.