skip to content

build a detection system · lesson 1 of 9 · sources checked 2026-11-22

the decision chain and its latency budget

This lesson builds the stages that turn a request into an action, divides one time budget between them, and joins their results by one contract.

status of this lesson: from a public source

purpose

A detection system must decide on each request before the page is late for a real user. Each check costs time, and the checks give results in different forms. Without a plan for the time and the form of the results, the system is slow, and nobody can explain a block.

objectives

  1. Name the stages of a decision chain and the work of each stage.
  2. Divide one latency budget between the stages, and check a measured stage against its part.
  3. Write a fusion contract with one verdict scale, a confidence, stored evidence, and a combine rule.
  4. Combine probe results with a worst-wins rule and a noisy-OR rule.
  5. Explain which signals of the chain a client cannot see.

new terms

decision chain
The ordered stages that turn a request into an action: rules, features, inference, fusion, and policy.
fusion contract
The shared form of all probe results: one verdict scale, a confidence, stored evidence, and a combine rule.
calibration store
A store that keeps each predicted value next to its measured result, so that "measured" and "modelled" stay apart.

how it works

A decision chain has six stages, in this order:

  1. Edge rules: fixed rules on the request alone, for example a header that is not permitted.
  2. Feature lookup: values from a store that counts many requests of one key.
  3. Model inference: a model gives a score from the feature values.
  4. Fusion: the results of all checks become one verdict.
  5. Policy: the verdict and the context give one action.
  6. Enforcement: the site accepts the request, gives a challenge, or blocks the request.

put each check at the cheapest stage

An edge rule reads only the request, so it costs almost no time. A feature lookup reads a store, and a model must compute. Thus a check goes to the first stage that has the data to decide.

For example, a request with no Host header fails at the edge. The site does not look up its features, and it does not run the model.

A client sees only its own page: the script, the cookies, and the response. The counts over many requests, the model score, and the combine rule stay on the server. Thus a client cannot see the result of these stages before the action.

one budget for the chain

A latency budget is the time that the chain can add to one request. You divide it between the stages, and each stage gets a part.

example The first diagram gives an example budget of 5 ms. The parts are 0.5 ms for the edge rules, 2 ms for the feature lookup, and 1.5 ms for inference. Fusion and the policy get 0.5 ms each. The sum is 5 ms.

Measure each stage at the 99th percentile, not only the median. For example, a stage has a part of 2 ms, a median of 1 ms, and a 99th percentile of 9 ms. It breaks its part for at least one request in a hundred. Then that stage must get faster, or it must move out of the request path.

budgets of public systems

The two charts in the section "Data" give the scale of public budgets. The values are statements of their publishers.

One company stated in 2020 that an edge bot decision had a budget of microseconds, not milliseconds. A different company stated in 2023 that its payment fraud model decided in less than 100 ms, with more than 1,000 features.

the fusion contract

Each check is a probe. Probes give results in different forms: a flag, a count, or a score. The fusion stage can join them only when all results have one form. A fusion contract gives that form:

  • One verdict scale for all probes: human, inconclusive, or bot.
  • A confidence from 0 to 1 for each verdict.
  • The evidence of each result, for example "75 requests in 1 minute, limit 60".
  • A combine rule that makes one verdict from all results.

A probe with a missing input gives inconclusive with a low confidence. It never gives a pass. For example, a script result that did not arrive is not a human verdict.

two combine rules

A worst-wins rule takes the highest verdict on the scale. One bot verdict makes the result bot, and one inconclusive verdict beats a human verdict.

A noisy-OR rule treats each bot verdict as an independent chance. The combined score is 1 minus the product of (1 minus each confidence). For example, three bot verdicts with the confidences 0.5, 0.3, and 0.2 give 1 - (0.5 x 0.7 x 0.8) = 1 - 0.28 = 0.72.

The noisy-OR rule is correct only when the probes are independent. Two probes that read the same signal count it two times.

store the evidence and the result

The fusion stage writes each probe result to an evidence store. Thus an analyst can say which probe fired, and why. The combined score goes to a calibration store, next to the later result of the request, for example the result of a review. Then you can compare each predicted score with what happened.

the two sides

automation sidedetection side
A client sees only its own page: the script, the cookies, and the response. It does not see the counts over many requests or the combine rule. A rule that the edge applies before a script runs gets no input from a page.Put each check at the cheapest stage that can decide. Keep each stage inside its part of the budget at the 99th percentile. Store the evidence of each verdict, so that an analyst can explain a block.

design decisions

optiongaincostwhen it is correct
Decide at the edge with rulesAlmost no time, no storeA rule sees one request onlyFor a request that a fixed rule can refuse
A feature lookup in the request pathCounts of many requestsStore time, the largest part of the example budgetWhen the store answers inside its part at the 99th percentile
A model in the request pathA score from many featuresCompute timeWhen inference stays inside its part
Score after the responseNo time in the request pathThe action comes on the next requestFor a check that is too slow for the budget
Worst-wins combine ruleSimple, and easy to explainOne weak probe can decide aloneWhen each probe has a low false-positive rate
Noisy-OR combine ruleWeak results add upWrong when two probes read the same signalWhen the probes are independent

diagram

The first diagram shows the chain with the example budget.

the decision chain with an example latency budget of 5 ms for the whole chain

An edge rule can end the chain at once. Each other request goes through all stages, and the parts of the example budget add up to 5 ms.source: My model of the decision chain, with an example budget

The second diagram shows the fusion contract.

the fusion contract: probe results on one scale, one combine rule, and two stores

A probe with no input still gives a result on the scale. The combine rule writes each result to the evidence store and the score to the calibration store.source: My model of the fusion contract

code example

The example applies a fusion contract to three synthetic requests. Each probe reads one synthetic field.

m37-x01-fusion.tstypescript

Apply three probes with one verdict scale to synthetic requests, combine the results by worst-wins and by noisy-OR, and store the evidence of each result.

// A fusion contract on synthetic probe results. No value comes from a real client.
type Verdict = "human" | "inconclusive" | "bot";
type Result = { probe: string; verdict: Verdict; confidence: number; evidence: string };
type Rec = { id: string; headerOrderKnown?: boolean; requestsLastMinute?: number; scriptOk?: boolean };

// One verdict scale for all probes.
const RANK: Record<Verdict, number> = { human: 0, inconclusive: 1, bot: 2 };

// A missing input gives "inconclusive" with a low confidence, never a pass.
const missing = (probe: string, field: string): Result =>
  ({ probe, verdict: "inconclusive", confidence: 0.1, evidence: `no value for ${field}` });

const probes: ((r: Rec) => Result)[] = [
  (r) => r.headerOrderKnown === undefined ? missing("header order", "headerOrderKnown")
    : r.headerOrderKnown ? { probe: "header order", verdict: "human", confidence: 0.6, evidence: "order is in the known list" }
    : { probe: "header order", verdict: "bot", confidence: 0.5, evidence: "order is not in the known list" },
  (r) => r.requestsLastMinute === undefined ? missing("rate", "requestsLastMinute")
    : r.requestsLastMinute > 60 ? { probe: "rate", verdict: "bot", confidence: 0.3, evidence: `${r.requestsLastMinute} requests in 1 minute, limit 60` }
    : { probe: "rate", verdict: "human", confidence: 0.4, evidence: `${r.requestsLastMinute} requests in 1 minute, limit 60` },
  (r) => r.scriptOk === undefined ? missing("script result", "scriptOk")
    : r.scriptOk ? { probe: "script result", verdict: "human", confidence: 0.5, evidence: "script result is present and valid" }
    : { probe: "script result", verdict: "bot", confidence: 0.2, evidence: "script result is not valid" },
];

// Worst-wins: the highest verdict on the scale wins.
const worstWins = (rs: Result[]): Verdict =>
  rs.reduce<Verdict>((w, x) => (RANK[x.verdict] > RANK[w] ? x.verdict : w), "human");

// Noisy-OR: each bot verdict is an independent chance of a bot.
const noisyOr = (rs: Result[]): number =>
  1 - rs.filter((x) => x.verdict === "bot").reduce((p, x) => p * (1 - x.confidence), 1);

const records: Rec[] = [
  { id: "req-1", headerOrderKnown: false, requestsLastMinute: 75, scriptOk: false },
  { id: "req-2", headerOrderKnown: true, requestsLastMinute: 12, scriptOk: true },
  { id: "req-3", headerOrderKnown: true, requestsLastMinute: 12 },
];

const evidenceStore: string[] = [];
for (const r of records) {
  const rs = probes.map((p) => p(r));
  for (const x of rs) evidenceStore.push(`${r.id} | ${x.probe} | ${x.verdict} ${x.confidence} | ${x.evidence}`);
  console.log(`${r.id}: worst-wins=${worstWins(rs)} noisy-OR=${noisyOr(rs).toFixed(2)}`);
}
console.log("evidence store:");
for (const line of evidenceStore) console.log(`  ${line}`);

output

The two combined results for each request, then the evidence store with one line for each probe result.

req-1: worst-wins=bot noisy-OR=0.72
req-2: worst-wins=human noisy-OR=0.00
req-3: worst-wins=inconclusive noisy-OR=0.00
evidence store:
  req-1 | header order | bot 0.5 | order is not in the known list
  req-1 | rate | bot 0.3 | 75 requests in 1 minute, limit 60
  req-1 | script result | bot 0.2 | script result is not valid
  req-2 | header order | human 0.6 | order is in the known list
  req-2 | rate | human 0.4 | 12 requests in 1 minute, limit 60
  req-2 | script result | human 0.5 | script result is present and valid
  req-3 | header order | human 0.6 | order is in the known list
  req-3 | rate | human 0.4 | 12 requests in 1 minute, limit 60
  req-3 | script result | inconclusive 0.1 | no value for scriptOk

The output shows that the request with a missing script result gets inconclusive, not human. The noisy-OR score of the first request is 0.72, as in the calculation above.

data

time budget of one edge bot decision, 2020

status of this figure: from a public source

time budget of one edge bot decision, 2020budget for one request100model inference, less than50heuristics, about20unit: µs

source: Cloudflare blog post, 2020: bot management at the edge (public source, https://blog.cloudflare.com/cloudflare-bot-management-machine-learning-and-more/, read 2026-11-13); date 2020-05-06; condition: The vendor gives the budget at more than 10 million requests each second. The limit and the about value are the words of the post.

data table
time budget of one edge bot decision, 2020
part of the decisionµs
budget for one request100
model inference, less than50
heuristics, about20
A vendor statement of 2020, not my measurement. One decision has 100 µs. Model inference uses less than 50 µs. Hundreds of heuristics use about 20 µs.

The first chart shows how one edge decision divides its budget between a model and many fixed rules. The model part is an upper limit, and the rule part is an about value.

decision time and feature count of two public systems

status of this figure: from a public source

decision time and feature count of two public systemsdecision timeedge bot score, 2020, budget100payment fraud, 2023, lessthan100000unit: µs, logfeatures per decisionpayment fraud, 2023, morethan1000unit: features, log

source: Cloudflare blog post, 2020 (edge bot score), and Stripe blog post, 2023 (payment fraud model) (public source, https://blog.cloudflare.com/cloudflare-bot-management-machine-learning-and-more/, read 2026-11-13); period 2020-05-06 to 2023-03-29; condition: The vendors do not state the feature count of the edge score. The source link is for the first post. The second post is from Stripe, 2023.

data table
decision time and feature count of two public systems
seriessystem and yearvalueunit
decision timeedge bot score, 2020, budget100µs
decision timepayment fraud, 2023, less than100000µs
features per decisionpayment fraud, 2023, more than1000features
Two vendor statements, 2020 and 2023. The two systems do different work, so this is not a ranking. The first value is a budget. The others are limits. The scale is logarithmic.

The second chart shows that a decision at the edge and a decision on a payment have time limits of different sizes. The edge publisher gives no feature count, so the feature panel has one bar.

failure modes

problemcausecorrection
Pages are slow for one request in a hundred.A stage keeps its median part, but not its part at the 99th percentile.Measure each stage at the 99th percentile, and move a slow check out of the request path.
A request with a missing input passes.The probe reads a missing value as a pass.Give inconclusive with a low confidence for a missing input.
An analyst cannot say why a user got a block.The chain stores only the final verdict.Store each probe result with its evidence.
Two weak probes block a real user.Noisy-OR counts one signal two times, because two probes read it.Use noisy-OR only for independent probes, or merge the two probes.
A model score looks correct, but nobody can prove it.The predicted scores are not next to the later results.Write each score and its later result to the calibration store.

check questions

  1. Name the six stages of a decision chain in their order, and write the work of each stage in one sentence.

    sample answer

    Edge rules apply fixed rules to the request alone. The feature lookup reads values from a store that counts many requests of one key. Model inference gives a score from the feature values. Fusion makes one verdict from the results of all checks. The policy gives one action from the verdict and the context. Enforcement accepts, challenges, or blocks the request.

  2. A stage has a part of 2 ms in the latency budget. Its median is 1 ms, and its 99th percentile is 9 ms. What is the correct statement?

    1. The stage keeps its part, because the median is less than 2 ms.
    2. The stage breaks its part for at least one request in a hundred, so it must get faster or move out of the request path.
    3. The stage keeps its part, because the budget applies to the whole chain only.
    answer

    b. The stage breaks its part for at least one request in a hundred, so it must get faster or move out of the request path.

    You measure each stage at the 99th percentile, not only at the median. A 99th percentile of 9 ms is more than the part of 2 ms.

  3. A probe must read a script result, but the result did not arrive. What does the probe give by the fusion contract?

    1. The verdict human, because no problem was found
    2. No result, so that the combine rule ignores the probe
    3. The verdict inconclusive with a low confidence
    answer

    c. The verdict inconclusive with a low confidence

    A missing input is never a pass. The probe gives inconclusive with a low confidence, and the evidence says which input is missing.

  4. Two independent probes give bot verdicts with the confidences 0.5 and 0.5. What is the noisy-OR score?

    1. 0.25
    2. 0.75
    3. 1.0
    4. 0.5
    answer

    b. 0.75

    The score is 1 minus the product of (1 minus each confidence): 1 - (0.5 x 0.5) = 0.75.

  5. Explain which parts of the decision chain a client cannot see.

    sample answer

    A client sees only its own page: the script, the cookies, and the response. The counts over many requests, the model score, and the combine rule stay on the server. Thus the client cannot see the result of these stages before the action.

exercise

exercise Do this task on paper. The chain has an example latency budget of 5 ms, with the parts of the first diagram. The measured values of your lab gate are synthetic:

  • Edge rules: median 0.2 ms, 99th percentile 0.4 ms.
  • Feature lookup: median 1.2 ms, 99th percentile 3.5 ms.
  • Model inference: median 0.9 ms, 99th percentile 1.3 ms.
  • Fusion: median 0.1 ms, 99th percentile 0.2 ms.
  • Policy: median 0.1 ms, 99th percentile 0.3 ms.

A request has three probe results: bot with confidence 0.4, bot with confidence 0.5, and inconclusive with confidence 0.1. The probes are independent.

  1. For each stage, compare the 99th percentile with its part of the budget.
  2. Write the stage that breaks its part, and one correction.
  3. Write the worst-wins verdict of the request.
  4. Calculate the noisy-OR score of the request.
sample answer

The answer uses the synthetic values of the task.

The feature lookup breaks its part: 3.5 ms is more than 2 ms. All other stages stay inside their parts. A correction is a faster store, or a move of the slow lookups out of the request path.

The worst-wins verdict is bot, because bot is the highest verdict on the scale. The noisy-OR score uses only the two bot verdicts: 1 - (0.6 x 0.5) = 1 - 0.3 = 0.7.

sources

  1. My model of the decision chain, the example latency budget, and the fusion contract, 2026-11 (not public).