skip to content

reliability engineering for a collection product · lesson 2 of 6 · sources checked 2026-11-30

deadlines, backpressure, and load shed

This lesson shows how a deadline, a bounded queue, and an admission rule stop work that cannot finish before it reaches the target.

purpose

A collector under overload can send requests to a target for work that nobody can use any more. That load reaches a site that is not yours, and it gives the customer nothing. You must stop such work early and give the customer a time to come back.

objectives

  1. Propagate a deadline from the customer request to the browser step.
  2. Refuse work fast with a retry time when the queue is full.
  3. Classify work by criticality, and drop the low classes first under overload.
  4. Explain why an alarm on the wait time of the oldest job is better than an alarm on queue depth.

new terms

deadline propagation
The rule that each hop passes the rest of an absolute deadline to the next hop.
backpressure
A signal from a full component that makes the component before it slow down or refuse work.
criticality class
A class of work that sets the order in which an overloaded system drops work.
load shed
The planned drop of low-criticality work under overload.

how it works

The customer request has an absolute deadline: a time limit after which the system stops the work. After that time, the result has no value. Each level of the collector uses some of that time. The last level, the browser step, gets only what is left.

the deadline on its way down

deadline propagation is the rule that each hop subtracts its own time and passes the rest to the next hop. A hop that cannot finish in the rest stops at once. It does not send a request to the target.

For example, the customer request has 2,000 ms. The API uses 40 ms, the queue 300 ms, and the worker 160 ms. The browser step then gets 1,500 ms. A step that takes 1,800 ms stops before it reaches the target.

The first diagram shows this path. A code example can also pass a deadline down. More detail is in Retry budgets and the retry multiplier.

the timeout of each hop

status of this section: from a public source

claim of a company An article of one cloud company describes how to choose a timeout. The method starts from an acceptable rate of false timeouts, for example 0.1%. The timeout is then the matching latency percentile of the downstream service, in that example p99.9 Amazon Builders' Library, source 1.

The same article does not describe a deadline that passes down a call chain.

the timeout and the rest of the deadline

In my model, the timeout of a hop is the smaller of two values. One is the timeout from the latency percentile, and the other is the rest of the deadline.

backpressure from a bounded queue

backpressure is the push back from a full component to the component before it. A bounded queue gives it. When the queue is full, the API refuses the next job at once, and the answer holds a retry time.

For example, the queue holds 4 jobs, and the workers finish 2 jobs each second. A full queue then gives a retry time of 2 s. A fast refusal keeps the queue short, and the customer knows when to try again.

criticality classes and the drop order

A criticality class sets the order in which an overloaded collector drops work. I use three classes:

  1. Customer work: a customer waits for the result.
  2. Scheduled work: a job that a schedule starts, with a deadline of minutes.
  3. Maintenance work: a job with no customer and a long deadline.

A load shed drops maintenance work first, then scheduled work, then customer work. For example, a customer job arrives at a full queue that holds a maintenance job. The rule drops the maintenance job and admits the customer job. The second diagram shows this admission rule.

alarms on the wait time of work

A queue can look small while its oldest job is too old to be useful. Thus an alarm on the depth of the queue can stay quiet while the jobs expire. An alarm on the wait time of the oldest job of each class sees the wait itself.

With an admission rule, the low classes wait longer by design. For example, an alarm on the oldest wait time of all classes can then fire on maintenance work only. Thus set one wait-time alarm for each criticality class.

The output of the work is an admission rule with the criticality classes and the refusal answer.

the two sides

automation sidedetection side
A deadline stops work that cannot finish, before it reaches the target. A fast refusal keeps the queue short.A collector without a deadline sends requests that it then drops. The target sees web sessions that stop in the middle of a flow.

design decisions

optiongaincostwhen it is correct
A timeout for each hop onlySimple to setA hop can start work that cannot finish before the customer deadline.Only for work with no customer deadline
Deadline propagationWork that cannot finish stops before the target.Each hop must read and pass the rest of the deadline.For each customer request
An unbounded queueNo job gets a refusal.The wait grows with no limit, and old jobs reach the target too late.Never under overload
A bounded queue with a fast refusal and a retry timeThe customer knows at once, and the queue stays short.Some customers get a refusal.As the default
Load shed by criticality classCustomer work goes on under overload.Maintenance work waits or drops.When the classes have different deadlines

diagram

a deadline of 2,000 ms on its way down the levels of a collector, with the stop before the target

Each hop subtracts its own time. The worker stops a step that takes more time than is left, and the target gets no request.source: My model of deadline propagation in a collector

The second diagram shows the admission rule.

the admission rule: bounded queue, criticality classes, drop order, and the fast refusal with a retry time

The rule refuses a job that cannot meet its deadline, and drops the lowest class first when the queue is full.source: My model of an admission rule with criticality classes

code example

The example applies the admission rule to ten synthetic jobs of three classes. The queue holds 4 jobs, and the workers finish 2 jobs each second.

m56-x03-admission.tstypescript

Apply an admission rule with a bounded queue, criticality classes, a drop order, and a refusal with a retry time.

// An admission rule: a bounded queue, criticality classes, a drop order,
// and a fast refusal with a retry time. All jobs are synthetic.
type Class = "customer" | "scheduled" | "maintenance";
const RANK: Record<Class, number> = { customer: 0, scheduled: 1, maintenance: 2 };
type Job = { id: string; cls: Class; deadlineMs: number };

const CAPACITY = 4;      // the bound of the queue
const FINISH_PER_S = 2;  // jobs that the workers finish each second
const queue: Job[] = [];

function retryAfterS(): number {
  return Math.ceil(queue.length / FINISH_PER_S);
}

function admit(job: Job, nowMs: number): string {
  // A job that cannot finish before its deadline stops here, not at the target.
  const waitMs = (queue.length / FINISH_PER_S) * 1000;
  if (nowMs + waitMs > job.deadlineMs) return `${job.id}: refuse, deadline cannot be met`;
  if (queue.length < CAPACITY) {
    queue.push(job);
    return `${job.id}: admit`;
  }
  // The queue is full: shed the job of the lowest class, if it is lower than the new job.
  let low = 0;
  for (let i = 1; i < queue.length; i++) if (RANK[queue[i].cls] > RANK[queue[low].cls]) low = i;
  if (RANK[queue[low].cls] > RANK[job.cls]) {
    const [shed] = queue.splice(low, 1);
    queue.push(job);
    return `${job.id}: admit, shed ${shed.id} (${shed.cls})`;
  }
  return `${job.id}: refuse, retry after ${retryAfterS()} s`;
}

const arrivals: Job[] = [
  { id: "m1", cls: "maintenance", deadlineMs: 60_000 },
  { id: "s1", cls: "scheduled", deadlineMs: 30_000 },
  { id: "m2", cls: "maintenance", deadlineMs: 60_000 },
  { id: "c1", cls: "customer", deadlineMs: 2_000 },
  { id: "c2", cls: "customer", deadlineMs: 2_000 },
  { id: "s2", cls: "scheduled", deadlineMs: 30_000 },
  { id: "c3", cls: "customer", deadlineMs: 2_000 },
  { id: "c4", cls: "customer", deadlineMs: 2_000 },
  { id: "c5", cls: "customer", deadlineMs: 1_500 },
  { id: "c6", cls: "customer", deadlineMs: 5_000 },
];
for (const job of arrivals) console.log(admit(job, 0));
console.log(`queue: ${queue.map((j) => j.id).join(", ")}`);

output

One line for each job: admit, admit with a drop, or refuse. The last line gives the jobs in the queue.

m1: admit
s1: admit
m2: admit
c1: admit
c2: admit, shed m1 (maintenance)
s2: admit, shed m2 (maintenance)
c3: admit, shed s1 (scheduled)
c4: admit, shed s2 (scheduled)
c5: refuse, deadline cannot be met
c6: refuse, retry after 2 s
queue: c1, c2, c3, c4

The output shows the drop order: the two maintenance jobs go first, then the two scheduled jobs. It also shows the two refusals. Job c5 cannot meet its deadline, and job c6 gets a retry time of 2 s.

data

wait time of the oldest customer job under a step of overload, with and without an admission rule

status of this figure: measured by me

wait time of the oldest customer job under a step of overload, with and without an admission rule3.749258.57.9210ref 11 s3 s5 s7 s9 s11 s13 s15 s17 s19 s21 s23 s25 s27 s29 sms1. no admission rule2. admission ruleref 1: customer deadline 2000

source: Lab result of this course: overload step on a lab API with and without an admission rule; date 2026-11-13; sample of 10; condition: Lab API, 70 to 200 jobs/s from 5 s to 15 s. Local processes. Clients do not retry a refusal. One shared host. Lab teaching values.

data table
wait time of the oldest customer job under a step of overload, with and without an admission rule
seriessecondms
no admission rule1 s3.749
no admission rule3 s0
no admission rule5 s334.9
no admission rule7 s1108
no admission rule9 s1841
no admission rule11 s2598
no admission rule13 s3417
no admission rule15 s4248
no admission rule17 s5027
no admission rule19 s5791
no admission rule21 s6175
no admission rule23 s4807
no admission rule25 s3321
no admission rule27 s1635
no admission rule29 s258.5
admission rule1 s7.921
admission rule3 s0.1214
admission rule5 s21.04
admission rule7 s17.9
admission rule9 s27.88
admission rule11 s19.39
admission rule13 s22.67
admission rule15 s8.813
admission rule17 s1.725
admission rule19 s6.795
admission rule21 s0
admission rule23 s8.805
admission rule25 s9.746
admission rule27 s5.495
admission rule29 s0
Each point is the median of 5 runs, at each second with an odd number. The load steps up from 5 s to 15 s. The rule keeps customer jobs far under their 2 s deadline.

The chart is a lab result of this course, from a lab API in local processes on one host. It shows the mechanism of this page: with no admission rule, customer jobs wait behind all other work and pass their deadline. With the rule, customer work goes first.

failure modes

problemcausecorrection
The queue of maintenance work does not get shorter.Jobs arrive faster than the workers finish them, and no rule refuses old work.Drop a job when its deadline passes, and bound the queue.
Jobs wait under the alarm threshold and then expire.The alarm reads the depth of the queue, not the wait time of the oldest job.Set an alarm on the wait time of the oldest job, and a drop rule for old work.
The target gets requests for results that nobody uses.No hop reads the deadline of the customer.Pass the rest of the deadline down, and stop the step before the target.
The wait-time alarm fires on maintenance work during each overload.One alarm reads the oldest wait time of all classes.Set one wait-time alarm for each criticality class.

check questions

  1. A customer request has a deadline of 1,000 ms. The API uses 100 ms and the queue 400 ms. The browser step takes 600 ms. What does the worker do?

    1. It starts the step, because the deadline is 1,000 ms.
    2. It retries the step at a second level.
    3. It stops the step before the target, because only 500 ms are left.
    answer

    c. It stops the step before the target, because only 500 ms are left.

    Each hop subtracts its own time and passes the rest down. 1,000 - 100 - 400 = 500 ms, which is less than the 600 ms that the step takes.

  2. The bounded queue is full and holds only customer jobs. A new customer job arrives. What does the API send?

    1. A refusal at once, with a retry time
    2. No answer until a slot is free
    3. An admit, and the queue grows past its bound
    answer

    a. A refusal at once, with a retry time

    A full bounded queue gives backpressure. The API refuses the job at once, and the answer holds a retry time.

  3. The queue is full and holds customer, scheduled, and maintenance jobs. Which job does the load shed drop first?

    1. The oldest customer job
    2. A maintenance job
    3. A scheduled job
    answer

    b. A maintenance job

    The drop order is maintenance work first, then scheduled work, then customer work.

  4. Explain why an alarm on the wait time of the oldest job is better than an alarm on the depth of the queue.

    sample answer

    A queue can look small while its oldest job is too old to be useful. An alarm on the depth can stay quiet while the jobs expire. An alarm on the wait time of the oldest job of each class sees the wait itself.

exercise

exercise Do this task on paper, with the synthetic values below. Do not send a request to a site.

  • The customer deadline is 3,000 ms.
  • The API uses 50 ms, the queue 900 ms, and the worker 250 ms.
  • The browser step takes 2,000 ms.
  • The bounded queue holds 6 jobs, and the workers finish 3 jobs each second.
  • The full queue holds 4 customer jobs and 2 scheduled jobs. A new customer job arrives, and then a second new customer job.
  1. Compute the time that is left for the browser step.
  2. Write if the browser step can start.
  3. Write the action of the admission rule for the first new customer job.
  4. Write the action of the admission rule for the second new customer job.
sample answer

The answer uses the synthetic values of the task.

The browser step gets 3,000 - 50 - 900 - 250 = 1,800 ms. The step takes 2,000 ms, thus it stops before it reaches the target.

The first new customer job finds a full queue with a scheduled job. The rule drops one scheduled job and admits the customer job. The second new customer job also finds a scheduled job, and the rule drops it.

sources

  1. Timeouts, retries, and backoff with jitter, Amazon Builders' Library, article, read 2026-11-22
  2. My model of deadline propagation, the admission rule, and the criticality classes of a collector, 2026-11 (not public).