build a detection system · lesson 3 of 9 · sources checked 2026-11-22
features over many requests and the reputation store
This lesson designs the counts that a server keeps over many requests, with keys, windows, a decay, and a state cost for each key.
purpose
One request shows little. Many requests of one address, one network, or one client build show a pattern that no single request shows. An inter-request feature gives that pattern to the model, but each key that you count costs memory and can hurt real users.
objectives
- Select the keys and the windows of a feature pipeline.
- Define aggregates for each key, for example ratios and volume quantiles over one hour.
- Calculate the state cost of a key, and read it from a lab chart.
- Explain why the rotation of one key does not reset the counts of the other keys.
- Join labels to feature values at the label time, and test the join for future values.
new terms
- reputation store
- A store of aggregates and history for each key, with a window and a decay.
- feature store
- A system with an offline store for training and an online store for decisions, with one feature definition.
- point-in-time join
- A join that gives each label only the feature values that existed at the label time.
how it works
An inter-request feature has three parts: a key, a window, and an aggregate. For example, "requests of one address in the last hour" has the key "address", the window "1 hour", and the aggregate "count".
keys
A key is the value that groups the requests. Each key is a signal of a different part of the client:
- Address: the source address of the request.
- Address prefix: the network range of the address.
- Network: the ASN that announces the address.
- TLS fingerprint: a fingerprint of the first TLS message of the client, for example a JA4 value.
- Web session: the cookie of the web session.
- Account: the account of a user who logs in.
Each key resets when the client changes that part, or when the window ends. The first diagram shows this for each key and window.
rotation of one key
A client can get a new address for each request. The address count then stays low. But the new address has the same TLS fingerprint, the same network, and the same request pattern. Thus the new address adds to the same counts of the other keys.
For example, 500 requests come from 500 addresses in one hour. Each address has a count of 1. The TLS fingerprint key has a count of 500 in that hour, and the network key has the same 500.
A client cannot see or reset these counts. They stay on the server, and a change of one key leaves the others in place.
aggregates
A count alone says little. Better aggregates for a key over one hour are:
- Ratios, for example the share of requests with no cookie, or the share of requests to one path.
- Volume quantiles, for example the place of the hourly count of this key against all keys of the same kind.
- Counts of different values, for example the number of different addresses for one TLS fingerprint. An estimate of that number can use much less memory than a list of all values.
the reputation store and the decay
A reputation store keeps the aggregates and the history of each key. Old evidence must count less than new evidence. A decay does this: each count halves after a fixed time.
For example, a key has 40 trap hits, and its count halves each hour. After 2 hours, the decayed count is 40 x 0.5 x 0.5 = 10.
the state cost and the false-positive cost
Each key has two costs. The state cost is the memory that its counts use. It grows with the number of different values in the window.
example For example, a store keeps 30,000 different addresses in 24 hours, at 300 bytes for each entry. That is 30,000 x 300 = 9,000,000 bytes, which is 9 MB (1 MB = 1,000,000 bytes).
The false positive cost is the harm to real users of a decision on the key. An address key hurts all users of one shared address. A TLS fingerprint key collects the volume of all clients of one TLS stack. The real browsers of one TLS stack can share one value.
one definition for training and for decisions
A feature store has an offline store for training and an online store for decisions. The two stores use one feature definition. Thus the model learns the same value that the decision chain later reads.
The online store must answer inside its part of the latency budget. The offline store keeps each value with its time.
A point-in-time join gives each label only the feature values that existed at the label time. For example, a block at 10:30 makes a label. A count from 11:00 is higher because of the attack after the block, so it must not go into the training row. The code example tests this.
the two sides
| automation side | detection side |
|---|---|
| Rotation of one key does not reset the counts of the other keys. A new address with the same TLS fingerprint, network, and request pattern adds to the same counts. A key on the TLS stack changes less often than a key on the address. | Each key has a state cost and a false-positive cost. An address key hurts the users of a shared address. A TLS fingerprint key collects the volume of all clients of one TLS stack. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| Address key | Simple, and it finds a fast source | Resets with each new address, and hurts users of a shared address | As one key of many, never alone |
| Network or prefix key | Survives a new address in the same network | Collects the requests of all real users of that network | For volume against an expected baseline |
| TLS fingerprint key | Survives a new address and a new network | All real browsers of one TLS stack can share one value | With ratios, not with a raw count |
| Web session or account key | One user, low false-positive cost | Resets with a new cookie or a new account | For a site with a login or a stable cookie |
| A long window | Finds slow patterns | Large state | For keys with few different values |
| A short window | Small state | Misses slow patterns | For keys with many different values |
diagram
The first diagram shows what resets each count.
A matrix of six keys against three windows of 1 minute, 1 hour, and 24 hours. Each key resets when the client changes the value of that key, or when the window ends. A change of one key does not reset the other keys.
| key | 1 minute | 1 hour | 24 hours |
|---|---|---|---|
| Address | new address, or 1 minute | new address, or 1 hour | new address, or 24 hours |
| Address prefix | new prefix, or 1 minute | new prefix, or 1 hour | new prefix, or 24 hours |
| Network (ASN) | new network, or 1 minute | new network, or 1 hour | new network, or 24 hours |
| TLS fingerprint | new TLS stack, or 1 minute | new TLS stack, or 1 hour | new TLS stack, or 24 hours |
| Web session | new cookie, or 1 minute | new cookie, or 1 hour | new cookie, or 24 hours |
| Account | new account, or 1 minute | new account, or 1 hour | new account, or 24 hours |
The second diagram shows the feature store.
one feature definition for the offline store and the online store, with a point-in-time join
code example
The example joins two synthetic labels to synthetic feature values. The times are minutes of the day: 630 is 10:30.
Join synthetic labels to feature values in two ways, and test each join for values from after the label time.
// A point-in-time join of labels to feature values, on synthetic records.
type Feature = { key: string; name: string; at: number; value: number }; // at: minute of the day
type Label = { key: string; at: number; label: "bot" | "human" };
type Row = { key: string; labelAt: number; label: string; name: string; value: number; featureAt: number };
const features: Feature[] = [
{ key: "key-a", name: "requests_1h", at: 600, value: 40 },
{ key: "key-a", name: "requests_1h", at: 660, value: 900 }, // after the block of 630
{ key: "key-b", name: "requests_1h", at: 600, value: 12 },
{ key: "key-b", name: "requests_1h", at: 700, value: 15 },
];
const labels: Label[] = [
{ key: "key-a", at: 630, label: "bot" },
{ key: "key-b", at: 650, label: "human" },
];
// A naive join takes the newest value of the key, also from after the label time.
function naiveJoin(ls: Label[], fs: Feature[]): Row[] {
return ls.map((l) => {
const f = fs.filter((x) => x.key === l.key).sort((a, b) => b.at - a.at)[0];
return { key: l.key, labelAt: l.at, label: l.label, name: f.name, value: f.value, featureAt: f.at };
});
}
// A point-in-time join takes the newest value at or before the label time.
function pointInTimeJoin(ls: Label[], fs: Feature[]): Row[] {
return ls.map((l) => {
const f = fs.filter((x) => x.key === l.key && x.at <= l.at).sort((a, b) => b.at - a.at)[0];
return { key: l.key, labelAt: l.at, label: l.label, name: f.name, value: f.value, featureAt: f.at };
});
}
// The test: it fails when a feature value comes from after the label time.
function testNoLeak(name: string, rows: Row[]): void {
const leaks = rows.filter((r) => r.featureAt > r.labelAt);
for (const r of rows) console.log(` ${r.key} label ${r.label} at ${r.labelAt}: ${r.name}=${r.value} from ${r.featureAt}`);
console.log(leaks.length === 0
? `${name}: PASS, no feature value from after the label time`
: `${name}: FAIL, ${leaks.length} value(s) from after the label time: ${leaks.map((r) => r.key).join(", ")}`);
}
console.log("naive join:");
testNoLeak("naive join", naiveJoin(labels, features));
console.log("point-in-time join:");
testNoLeak("point-in-time join", pointInTimeJoin(labels, features));output
The joined rows of each join, and the result of the test for each join.
naive join:
key-a label bot at 630: requests_1h=900 from 660
key-b label human at 650: requests_1h=15 from 700
naive join: FAIL, 2 value(s) from after the label time: key-a, key-b
point-in-time join:
key-a label bot at 630: requests_1h=40 from 600
key-b label human at 650: requests_1h=12 from 600
point-in-time join: PASS, no feature value from after the label timeThe output shows that the naive join gives the bot label the count 900 from after the block. The point-in-time join gives the count 40 from before the label, and its test passes.
data
state size of each key and window in a lab gate, 1,000,000 requests
status of this figure: measured by me
source: Lab result of this course: state size of the counters of a lab gate, simulated request log; date 2026-11-13; sample of 1,000,000; condition: A header-order hash stands in for a TLS key. The request log comes from stated population inputs, so the entry counts are simulated. The bytes are measured.
data table
| series | key | bytes |
|---|---|---|
| 1 minute | session | 125086 |
| 1 minute | address | 101347 |
| 1 minute | client string | 52646 |
| 1 minute | address prefix | 59920 |
| 1 minute | header-order hash | 50535 |
| 1 minute | network | 52678 |
| 1 hour | session | 6081819 |
| 1 hour | address | 4410531 |
| 1 hour | client string | 1026774 |
| 1 hour | address prefix | 1039318 |
| 1 hour | header-order hash | 754164 |
| 1 hour | network | 716162 |
| 24 hours | session | 192343418 |
| 24 hours | address | 26516799 |
| 24 hours | client string | 2914620 |
| 24 hours | address prefix | 1495086 |
| 24 hours | header-order hash | 721004 |
| 24 hours | network | 590102 |
The chart shows that the state cost of a key follows the number of its different values in the window. A key with a new value for almost each visitor, such as the web session, grows fast in a long window.
A key with few values, such as the network, stays small. In the chart, a hash of the header order takes the place of a TLS fingerprint key. The chart has no account key. It adds a key on the client string, the user agent text of each request.
failure modes
| problem | cause | correction |
|---|---|---|
| A source with a new address for each request has low counts. | The pipeline counts the address key only. | Count the TLS fingerprint and network keys too. |
| Real users of one shared address get a block. | A decision acts on the address key alone. | Use the address as one feature of many, not as the decision. |
| The memory of the store grows past its limit. | A key with many different values has a long window. | Give that key a shorter window, or estimate its counts. |
| A model looks good in training, but it is weak on live traffic. | The training rows hold feature values from after the label time. | Use a point-in-time join, and test it for future values. |
| Old trap hits keep a key flagged. | The store has no decay. | Halve each count after a fixed time. |
check questions
A key has a new value for almost each visitor. Which window keeps its state small?
- A window of 24 hours
- A window of 1 minute
- No window, so that the store keeps all values
answer
b. A window of 1 minute
The state cost grows with the number of different values in the window. A short window keeps few values of such a key.
Name two aggregates of a key over one hour that say more than a raw count.
sample answer
A ratio, for example the share of requests with no cookie. A volume quantile, for example the place of the hourly count of this key against all keys of the same kind. A count of different values, for example the number of different addresses for one TLS fingerprint, is also correct.
A key has 50,000 different values in its window, and each entry uses 400 bytes. What is its state cost?
- 20 MB
- 2 MB
- 200 MB
answer
a. 20 MB
50,000 x 400 = 20,000,000 bytes. With 1 MB = 1,000,000 bytes, that is 20 MB.
Explain why a new address for each request does not reset the counts of a source.
sample answer
The new address has the same TLS fingerprint, the same network, and the same request pattern. Thus each request adds to the same counts of these other keys. The counts stay on the server, and a change of one key leaves the other keys in place.
A label has the time 10:30. Which feature value goes into its training row by a point-in-time join?
- The value of 11:00, because it is the newest value
- The mean of the values of 10:00 and 11:00
- The value of 10:00, because it is the newest value at or before the label time
answer
c. The value of 10:00, because it is the newest value at or before the label time
A point-in-time join gives each label only the feature values that existed at the label time. A value from 11:00 is a future value for that label.
exercise
exercise Do this task on paper. Your lab gate keeps a 1-hour window. In one synthetic hour it sees these values:
- 800 requests from 800 different addresses.
- All 800 requests have one TLS fingerprint value.
- All 800 requests come from one network.
- Each entry of the store uses 500 bytes.
- A trap key had 64 hits 3 hours ago, and its count halves each hour.
- Write the count of the address key, the TLS fingerprint key, and the network key for that hour.
- Calculate the state cost of the address key for that hour.
- Calculate the decayed count of the trap key now.
- Write the key that you use as the first feature for this source, and the false-positive cost of that key.
sample answer
The answer uses the synthetic values of the task.
Each address has a count of 1. The TLS fingerprint key and the network key each have a count of 800. The address key has 800 entries, and 800 x 500 = 400,000 bytes, which is 0.4 MB.
The decayed trap count is 64 x 0.5 x 0.5 x 0.5 = 8. The TLS fingerprint key and the network key both show the source. Use the TLS key first, because it also survives a new network, and use it with a ratio, not with a raw count. Its false-positive cost: the real browsers of one TLS stack can share that value.
sources
- My model of keys, windows, aggregates, the decay, the state cost, and the point-in-time join, 2026-11 (not public).