the target as configuration · lesson 6 of 6 · sources checked 2026-11-22
one target and many tenants
This lesson keeps one shared budget for each target, so that the load of all tenants together stays under one cap.
purpose
A collection service can do work for many tenants, and two of them can ask for records from the same site. The site then gets the sum of their requests. Thus a limit for each tenant does not cap the total load on the site.
objectives
- Explain why a budget for each tenant does not limit the total load on one target.
- Set one politeness budget and one pool-heat budget for a shared target.
- Divide a shared target budget between tenants with a fair-share rule, and record each wait.
- State what the defender sees when many tenants collect from one target.
new terms
- shared target budget
- One politeness budget and one pool-heat budget for one target, for all tenants together.
- fair-share rule
- The rule that divides a shared target budget between tenants.
how it works
A tenant is one role: a user of the collection service with its own work and its own quota. A target is a site that the service reads under the rules that the site declares. Here, all names and values are synthetic.
the site sees one operator
When two tenants collect from one target, the target can see one operator. The requests come from one network and one tool set. Thus the site counts them together, not by tenant.
For example, tenant A sends 3 requests each second and tenant B sends 2. Each tenant is under its own limit of 3. The site gets 5 requests each second from one operator.
one budget for each target
The shared target budget holds two limits for one target, for all tenants together:
- a politeness budget: the requests that the target gets in a period;
- a pool heat budget: the requests that go through one shared pool to this target in a period.
The operator sets both budgets under the cap of the target profile. A tick is one step of the clock of the budget. For example, the cap is 4 requests for each tick, and the politeness budget is 4 tokens for each tick.
Each work item of each tenant must get a token from the same budget before it goes to the target. No path of work goes around it, also not a test or a repeat.
a shared store for the budget
The budget is a token bucket for each target in a store that all workers share. For example, the bucket of a target adds 4 tokens at each tick, up to a burst of 4. Each request takes one token. When no token is left, the request waits.
A bucket in the memory of one worker does not work. Each worker then has its own bucket, and the total load is the sum of all buckets.
the fair-share rule
The fair-share rule divides the tokens of the shared budget between the tenants. Each tenant has a weight. In each tick, each tenant gets its weighted share of the tokens. A share that a tenant does not use goes to the tenants that want more.
For example, the bucket has 4 tokens, and two tenants have the same weight. Tenant A asks for 6 and tenant B asks for 1. Tenant B gets 1, and tenant A gets 3. The total stays at 4.
The division of quotas and costs between tenants is a different topic. More detail is in Quotas and fairness (not yet published).
record each wait
When a tenant gets fewer tokens than it asked for, the service writes a wait record. The record holds the tick, the tenant, and the count of work items that wait. For example: tick 2, tenant A, 3 work items wait. The wait comes from the shared target budget, not from the site.
With these records, the operator can see which tenant uses the most of the budget. A tenant that uses too much of the budget cannot heat the pool for other tenants.
rules for a shared service
My model uses three rules for a service that many customers share:
- The service defines quotas for each customer.
- In a global overload, the service gives error responses only to the customers that misbehave.
- In client-side throttling, each client task keeps a history of the last two minutes. It counts the requests that the application attempted and the requests that the backend accepted.
My model maps two of these ideas to the target, from the other side. The service of the operator counts all of its traffic by target. It caps that traffic before the site must refuse it.
the two sides
| automation side | detection side |
|---|---|
| One budget for each target keeps the total load of all tenants under the cap of the target. A tenant that uses too much of the budget cannot heat the pool for other tenants. Each wait of the shared target budget has a record. | The defender counts all tenants as one operator, from one network and one tool set. One budget for each target is the rule that agrees with what the defender counts. The defender sees one steady pace, not a sum of separate tenants. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| A budget for each tenant only | Simple to bill and to explain | The total load on one target is the sum of all tenants. | Never alone |
| One shared target budget | The total load stays under one cap. | A busy tenant can wait. | Always, when two or more tenants share a target |
| A bucket in the memory of each worker | No shared store | Each worker sends up to its own limit. | Only with one worker |
| A bucket in a shared store | One count for all workers | The store is a dependency of each request. | Always, with more than one worker |
| A fair-share rule with weights | Each tenant gets its share, and unused tokens go to others. | The weights must have an owner. | When tenants have different volumes of work |
diagram
many tenants on one target: one fair-share rule and one shared target budget
code example
The sample has one target with a bucket of 4 tokens, two tenants with the same weight, and four ticks of synthetic demand. The Map stands in for a shared store.
One token bucket for each target, shared by all tenants, with a fair-share rule and a wait record.
// One token bucket for each target, shared by all tenants, with a fair-share rule.
// All values are synthetic. The Map stands in for a shared store.
type Bucket = { tokens: number; ratePerTick: number; burst: number };
const store = new Map<string, Bucket>();
store.set("shop.example", { tokens: 4, ratePerTick: 4, burst: 4 });
const weights: Record<string, number> = { "tenant-a": 1, "tenant-b": 1 };
const waits: { tick: number; tenant: string; held: number }[] = [];
// Fair-share rule: each tenant gets its weighted share of the tokens.
// A share that a tenant does not use goes to the tenants that want more.
function divide(tokens: number, demand: Record<string, number>): Record<string, number> {
const grant: Record<string, number> = {};
let left = tokens;
let open = Object.keys(demand).filter((t) => demand[t] > 0);
for (const t of Object.keys(demand)) grant[t] = 0;
while (left > 0 && open.length > 0) {
const sum = open.reduce((s, t) => s + weights[t], 0);
let used = 0;
for (const t of open) {
const share = Math.floor((left * weights[t]) / sum) || 1;
const give = Math.min(share, demand[t] - grant[t], left - used);
grant[t] += give;
used += give;
}
left -= used;
open = open.filter((t) => grant[t] < demand[t]);
if (used === 0) break;
}
return grant;
}
function tick(n: number, target: string, demand: Record<string, number>): void {
const b = store.get(target)!;
b.tokens = Math.min(b.burst, b.tokens + b.ratePerTick);
const grant = divide(b.tokens, demand);
let sent = 0;
for (const t of Object.keys(demand)) {
sent += grant[t];
const held = demand[t] - grant[t];
if (held > 0) waits.push({ tick: n, tenant: t, held });
}
b.tokens -= sent;
const parts = Object.keys(demand).map((t) => `${t} ${grant[t]}/${demand[t]}`).join(", ");
console.log(`tick ${n}: ${parts}; sent to target ${sent} of cap ${b.ratePerTick}`);
}
tick(1, "shop.example", { "tenant-a": 1, "tenant-b": 1 });
tick(2, "shop.example", { "tenant-a": 6, "tenant-b": 1 });
tick(3, "shop.example", { "tenant-a": 6, "tenant-b": 3 });
tick(4, "shop.example", { "tenant-a": 0, "tenant-b": 3 });
for (const r of waits) console.log(`wait record: tick ${r.tick}, ${r.tenant}, ${r.held} held in the queue`);output
One line for each tick with the tokens that each tenant got and the total sent to the target, then the wait records.
tick 1: tenant-a 1/1, tenant-b 1/1; sent to target 2 of cap 4
tick 2: tenant-a 3/6, tenant-b 1/1; sent to target 4 of cap 4
tick 3: tenant-a 2/6, tenant-b 2/3; sent to target 4 of cap 4
tick 4: tenant-a 0/0, tenant-b 3/3; sent to target 3 of cap 4
wait record: tick 2, tenant-a, 3 held in the queue
wait record: tick 3, tenant-a, 4 held in the queue
wait record: tick 3, tenant-b, 1 held in the queueThe output shows that the target never gets more than 4 requests in a tick. In tick 2, tenant B gets all that it asks for, and tenant A gets the rest. In tick 3, the two tenants share the tokens equally. Each held work item has a wait record.
data
pass rate of tenant b against the request rate of tenant a on one shared lab target
status of this figure: measured by me
band: interval, level 0.95
source: Lab result of this course: two tenants on one shared lab target, 5 runs for each point; date 2026-11-13; sample of 200; condition: One invented target rule and my own lab gate on one shared lab host. The count is the 200 requests of tenant B at each point. Teaching values.
data table
| series | request rate of tenant a | % | interval |
|---|---|---|---|
| no shared budget | 5 per second | 100 | 98.12 to 100 (level 0.95) |
| no shared budget | 10 per second | 100 | 98.12 to 100 (level 0.95) |
| no shared budget | 20 per second | 100 | 98.12 to 100 (level 0.95) |
| no shared budget | 30 per second | 100 | 98.12 to 100 (level 0.95) |
| no shared budget | 40 per second | 64.5 | 57.65 to 70.8 (level 0.95) |
| no shared budget | 60 per second | 29.5 | 23.61 to 36.16 (level 0.95) |
| shared budget | 5 per second | 100 | 98.12 to 100 (level 0.95) |
| shared budget | 10 per second | 100 | 98.12 to 100 (level 0.95) |
| shared budget | 20 per second | 100 | 98.12 to 100 (level 0.95) |
| shared budget | 30 per second | 100 | 98.12 to 100 (level 0.95) |
| shared budget | 40 per second | 100 | 98.12 to 100 (level 0.95) |
| shared budget | 60 per second | 100 | 98.12 to 100 (level 0.95) |
These are measured values from my own lab, with one invented target rule on one shared lab host. With no shared budget, the pass rate of tenant B falls when tenant A sends faster. With one shared budget and a fair-share rule, tenant B keeps its pass rate at each rate of tenant A.
failure modes
| problem | cause | correction |
|---|---|---|
| The load on a target is more than its cap, and each tenant is under its limit. | Each tenant has its own budget, and no budget is for the target. | Keep one shared target budget for each target. |
| One busy tenant makes the target refuse the other tenants. | No fair-share rule divides the shared budget. | Give each tenant a weighted share, and give unused tokens to the others. |
| The total load is the sum of the workers. | Each worker has its own bucket in memory. | Keep the bucket in a store that all workers share. |
| A test or a repeat goes to the target outside the budget. | A path of work does not take a token. | Make each path of work take a token from the same budget. |
| Nobody can say which tenant used the budget. | The service writes no wait record. | Record the tick, the tenant, and the count of waiting work items. |
check questions
Each of two tenants is under its own limit of 3 requests each second. Explain why the site can still get too much load.
sample answer
The site counts the requests of both tenants together, because they come from one operator, one network, and one tool set. Tenant A at 3 requests each second and tenant B at 2 give 5 requests each second on one site. A budget for each tenant does not limit that sum. Only one shared target budget does.
Where must the token bucket of a shared target budget be when the service has many workers?
- In the memory of each worker
- In a store that all workers share
- In the queue of each tenant
answer
b. In a store that all workers share
A bucket in the memory of each worker gives each worker its own limit, so the total load is the sum of all buckets. One bucket in a shared store gives one count for all workers.
A target budget has 4 tokens. Two tenants have the same weight. Tenant A asks for 5 and tenant B asks for 1. What does the fair-share rule give?
- Tenant A 2 and tenant B 2
- Tenant A 4 and tenant B 0
- Tenant A 3 and tenant B 1
answer
c. Tenant A 3 and tenant B 1
Each tenant has a share of 2. Tenant B uses 1, and its unused token goes to tenant A. Tenant A gets 3, and the total stays at 4. Tenant A gets a wait record for 2 work items.
What does a wait record of the shared target budget hold?
- The tick, the tenant, and the count of work items that wait
- The status that the site gave to the request
- A new exit for the work items that wait
answer
a. The tick, the tenant, and the count of work items that wait
The wait comes from the shared target budget, not from the site. The record holds the tick, the tenant, and the count of waiting work items.
What does the defender of a site see when many tenants of one service collect from it?
sample answer
The defender sees one operator, from one network and one tool set, and counts all tenants together. With one shared target budget, the defender sees one steady pace under one cap, not a sum of separate tenants.
exercise
exercise Do this task on paper. A synthetic target has a shared budget of 6 tokens for each tick. The tenants are:
| tenant | weight | requests asked for in this tick |
|---|---|---|
| Tenant A | 2 | 8 |
| Tenant B | 1 | 1 |
- Calculate the weighted share of each tenant.
- Give the unused share to the other tenant.
- Write the tokens of each tenant and the wait record.
sample answer
The answer uses the two synthetic tenants of the task.
The weighted shares are 4 tokens for tenant A and 2 tokens for tenant B. Tenant B asks for 1, so it uses 1, and 1 token is unused. That token goes to tenant A, which gets 5. The total is 6, at the cap of the target. The wait record is: tenant A, 3 work items wait.
sources
- My model of a shared target budget for each target, with a politeness budget and a pool-heat budget, 2026-11 (not public).
- My model of the fair-share rule and the wait record, 2026-11 (not public).