Reserve physical work as well as counting incoming requests
Combine tenant/account request limits, concurrency, token/work reservations and verified cancellation so distributed retries and variable-cost inference cannot bypass the intended budget.
On this page
The question for today
What you’ll understand
- Distinguish request counts from tokens, resource occupancy and external spend.
- Atomically reserve a stated cost bound across concurrent calls.
- Reconcile reservations against actual completed work and verified release.
Ten requests can mean ten short completions or ten long multimodal jobs with tool calls. A request counter alone does not constrain the same work in both cases. Define the resources being protected: concurrent jobs, decoded input, accelerator memory/time, output tokens, external API charges or another measured unit. Reserve the relevant upper budget before expensive work, then reconcile it when the operation actually stops. Model access can be authorized while a particular request is still refused because it cannot fit the caller’s or service’s resource policy.
Choose explicit dimensions and accounting ownership
Apply limits using trusted tenant/account identity, with separate service-wide and dependency-specific budgets where needed. Per-IP counters can be useful for some abuse patterns but do not establish tenant identity or fair shared-account usage. Document burst and sustained limits, concurrent in-flight capacity, and window/refill semantics. A count limit should state whether retries, streaming requests, rejected requests and background tool work consume it. Otherwise a caller can shift expensive work onto an uncounted path without exceeding the advertised request rate.
Use the actual model/tokenizer and generation ceiling for reservations. A simple planning cost can weight prompt tokens, maximum generated tokens and bounded tool calls, but those coefficients must be declared and validated for the intended resource. A financial credit estimate is not a universal FLOP, latency or memory predictor. Physical occupancy can outlive a client connection, so also enforce the scheduler and worker limits required to keep the machine within capacity.
Admit atomically and release only after work is accounted
Concurrent workers must atomically compare-and-reserve against the shared budget. Separate local counters can all pass while the account total exceeds its cap. A retry can create new physical work even when a client reuses an identifier; only an implemented idempotency/result-reuse contract can prevent that duplication. Keep operation identity, reservation ownership and actual usage reconciliation linked so repeated completion events cannot refund twice or lose an unfinished job.
At completion, reconcile measured usage with the reservation under the declared billing and resource policy. A disconnected client or HTTP timeout does not prove the GPU, media decoder or external tool stopped. Release physical capacity only after the relevant work and buffers are actually quiescent or safely transferred to another accounted owner. Retain enough reservation for retries or uncertain external charges as specified; do not convert uncertain completion into unearned spend or capacity headroom.
Test parallel admission, retries and cancellation at the worker
Exercise two requests that each fit independently but exceed the shared cap together. Check the final reservation ledger and actual worker tasks. Include long output ceilings, many attachments, bounded tool fanout, retry races and cancellation during a stream. Verify both authorization and budget rejection on alternate paths. A service-wide upper limit can protect capacity while still producing unfair tenant allocation, so assess fairness and abuse policies separately from the hard resource invariant.
The queue lab makes a limited accepted-work imbalance visible. Reset, set both λ=3,μ=2, predict backlog eight at t=4, then take eight Steps. Reset and set both λ=2,μ=3 predicts zero at t=4 from the initial four. Parameter edits retain time and recompute from that initial state, so use separate fresh runs. This deterministic fluid model has no finite cap, token ledger, tenant identity, spend, cancellation or tail-latency distribution. It illustrates backlog growth, not an implemented limiter.
Work it through
Reserve and reconcile a fictional credit budget
A fictional account cap is 100 credits, with thirty already reserved. A new request counts one hundred input tokens at 0.1 credit/token, at most fifty output tokens at 0.4 credit/token, and at most two tool calls at ten credits/call. Assume these enforced bounds cover this fixture’s charge.
The required reservation is 100×0.1+50×0.4+2×10=10+20+20=50 credits. Existing plus new reservations total eighty, so this request fits the one-hundred-credit cap.
After that atomic reservation, a second identical request would require 80+50=130 credits and must not be admitted under this cap. Independent workers reading the original thirty would miss this race.
If the first request completes with twenty output tokens and one tool call, its confirmed charge is 10+20×0.4+10=28 credits. Release the unused 50−28=22 only through the declared completion/reconciliation path; account separately for the other thirty credits.
The first request reserves fifty credits and fits; the simultaneous second cannot. The confirmed unused reservation is twenty-two credits, not a reason to free still-running physical work.
The living notebook
Explore the model
Interactive lab · queue
Inspect accepted-work backlog with fresh rate pairs
Reset → set both λ=3,μ=2 predicts q(4)=8 after eight Steps; Reset → set both λ=2,μ=3 predicts q(4)=0. Edits retain elapsed time and recompute q from initial four. This fluid toy implements no admission cap, identity, credit ledger, token budget, cancellation or p99 latency.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA rate counter and a bounded physical-work reservation solve different parts of the serving problem.
Pause & reason
Check your understanding
Your turn
Try it yourself
A shared cap is sixty credits with forty-five already reserved. Two concurrent calls each need ten. How many can be newly admitted if comparison and reservation are atomic? If a timeout occurs, may its ten credits of physical-work reservation immediately be reused?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Update the shared total after each admission, then distinguish response timing from actual work completion.
Compare with the solution
One call can reserve ten, raising the total to fifty-five; a second would require sixty-five and is denied or deferred. A timeout alone does not justify releasing physical-work capacity. The service must confirm termination or transfer ownership to another accounted operation. Financial reconciliation may use a distinct policy, but must not silently treat uncertain execution as zero cost.
Keep the idea
Take it with you
- Count variable work and external spend in addition to requests.
- Reserve shared budgets atomically under enforced upper bounds.
- Reconcile retries, cancellation and physical release through an attributable lifecycle.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.