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
- Propagate a deadline from the customer request to the browser step.
- Refuse work fast with a retry time when the queue is full.
- Classify work by criticality, and drop the low classes first under overload.
- 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 sourceclaim 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:
- Customer work: a customer waits for the result.
- Scheduled work: a job that a schedule starts, with a deadline of minutes.
- 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 side | detection 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
| option | gain | cost | when it is correct |
|---|---|---|---|
| A timeout for each hop only | Simple to set | A hop can start work that cannot finish before the customer deadline. | Only for work with no customer deadline |
| Deadline propagation | Work that cannot finish stops before the target. | Each hop must read and pass the rest of the deadline. | For each customer request |
| An unbounded queue | No 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 time | The customer knows at once, and the queue stays short. | Some customers get a refusal. | As the default |
| Load shed by criticality class | Customer 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
The second diagram shows the admission rule.
the admission rule: bounded queue, criticality classes, drop order, and the fast refusal with a retry time
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.
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, c4The 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
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
| series | second | ms |
|---|---|---|
| no admission rule | 1 s | 3.749 |
| no admission rule | 3 s | 0 |
| no admission rule | 5 s | 334.9 |
| no admission rule | 7 s | 1108 |
| no admission rule | 9 s | 1841 |
| no admission rule | 11 s | 2598 |
| no admission rule | 13 s | 3417 |
| no admission rule | 15 s | 4248 |
| no admission rule | 17 s | 5027 |
| no admission rule | 19 s | 5791 |
| no admission rule | 21 s | 6175 |
| no admission rule | 23 s | 4807 |
| no admission rule | 25 s | 3321 |
| no admission rule | 27 s | 1635 |
| no admission rule | 29 s | 258.5 |
| admission rule | 1 s | 7.921 |
| admission rule | 3 s | 0.1214 |
| admission rule | 5 s | 21.04 |
| admission rule | 7 s | 17.9 |
| admission rule | 9 s | 27.88 |
| admission rule | 11 s | 19.39 |
| admission rule | 13 s | 22.67 |
| admission rule | 15 s | 8.813 |
| admission rule | 17 s | 1.725 |
| admission rule | 19 s | 6.795 |
| admission rule | 21 s | 0 |
| admission rule | 23 s | 8.805 |
| admission rule | 25 s | 9.746 |
| admission rule | 27 s | 5.495 |
| admission rule | 29 s | 0 |
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
| problem | cause | correction |
|---|---|---|
| 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
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?
- It starts the step, because the deadline is 1,000 ms.
- It retries the step at a second level.
- 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.
The bounded queue is full and holds only customer jobs. A new customer job arrives. What does the API send?
- A refusal at once, with a retry time
- No answer until a slot is free
- 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.
The queue is full and holds customer, scheduled, and maintenance jobs. Which job does the load shed drop first?
- The oldest customer job
- A maintenance job
- A scheduled job
answer
b. A maintenance job
The drop order is maintenance work first, then scheduled work, then customer work.
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.
- Compute the time that is left for the browser step.
- Write if the browser step can start.
- Write the action of the admission rule for the first new customer job.
- 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
- Timeouts, retries, and backoff with jitter, Amazon Builders' Library, article, read 2026-11-22
- My model of deadline propagation, the admission rule, and the criticality classes of a collector, 2026-11 (not public).