skip to content

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

  1. Explain why a budget for each tenant does not limit the total load on one target.
  2. Set one politeness budget and one pool-heat budget for a shared target.
  3. Divide a shared target budget between tenants with a fair-share rule, and record each wait.
  4. 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 sidedetection 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

optiongaincostwhen it is correct
A budget for each tenant onlySimple to bill and to explainThe total load on one target is the sum of all tenants.Never alone
One shared target budgetThe 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 workerNo shared storeEach worker sends up to its own limit.Only with one worker
A bucket in a shared storeOne count for all workersThe store is a dependency of each request.Always, with more than one worker
A fair-share rule with weightsEach 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

All tenants take tokens from the same budget. A request with no token waits and gets a wait record.source: My model of a shared target budget with a fair-share rule

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.

m51-x06-shared-budget.tstypescript

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 queue

The 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

pass rate of tenant b against the request rate of tenant a on one shared lab target100%100%100%100%64.5%29.5%100%100%100%100%100%100%5 per second10 per second20 per second30 per second40 per second60 per second%1. no shared budget2. shared budget

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
pass rate of tenant b against the request rate of tenant a on one shared lab target
seriesrequest rate of tenant a%interval
no shared budget5 per second10098.12 to 100 (level 0.95)
no shared budget10 per second10098.12 to 100 (level 0.95)
no shared budget20 per second10098.12 to 100 (level 0.95)
no shared budget30 per second10098.12 to 100 (level 0.95)
no shared budget40 per second64.557.65 to 70.8 (level 0.95)
no shared budget60 per second29.523.61 to 36.16 (level 0.95)
shared budget5 per second10098.12 to 100 (level 0.95)
shared budget10 per second10098.12 to 100 (level 0.95)
shared budget20 per second10098.12 to 100 (level 0.95)
shared budget30 per second10098.12 to 100 (level 0.95)
shared budget40 per second10098.12 to 100 (level 0.95)
shared budget60 per second10098.12 to 100 (level 0.95)
Two tenants send requests to one lab target. Tenant B sends 10 requests each second. Each point has 5 runs of 4 s and a 95% interval. Tenant B falls to 29.5% at 60 requests each second with no shared budget.

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

problemcausecorrection
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

  1. 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.

  2. Where must the token bucket of a shared target budget be when the service has many workers?

    1. In the memory of each worker
    2. In a store that all workers share
    3. 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.

  3. 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?

    1. Tenant A 2 and tenant B 2
    2. Tenant A 4 and tenant B 0
    3. 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.

  4. What does a wait record of the shared target budget hold?

    1. The tick, the tenant, and the count of work items that wait
    2. The status that the site gave to the request
    3. 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.

  5. 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:

tenantweightrequests asked for in this tick
Tenant A28
Tenant B11
  1. Calculate the weighted share of each tenant.
  2. Give the unused share to the other tenant.
  3. 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

  1. My model of a shared target budget for each target, with a politeness budget and a pool-heat budget, 2026-11 (not public).
  2. My model of the fair-share rule and the wait record, 2026-11 (not public).