How would you set nested organisation, team and key budgets on a model gateway, and where should a spend cap be soft rather than hard?
answer
- every level must have room
- children may sum past the parent
- a hard stop on revenue is an outage
- warn the owner, then a ceiling
- short windows beside the monthly one
basics
~20 sA call must fit every budget above its key, so the tightest level binds. Hard caps suit development keys, batch jobs and agent runs; customer-facing features usually get a soft cap that escalates to an owner, backed by a higher hard ceiling.
solid answer
~50 sI'd treat budgets as a tree: an organisation budget, team budgets under it, keys under teams, and a call is admitted only if its reservation fits at every level, reserved and settled at all of them together, so the tightest one binds. Children may deliberately sum to more than the parent; the parent cap is then the real backstop, and that oversubscription should be an explicit choice. On hard versus soft: a **hard cap** refuses calls, which is right where the worst case is wasted money: development keys, experiments, batch jobs and agent runs. On a customer-facing feature a hard stop is an outage, so I'd use a **soft cap** that notifies the owner and lets calls continue, with a hard ceiling far enough above it to bound a disaster. I'd add daily caps beside monthly ones, so a weekend runaway hits a small wall early.
code
yaml · 13 lines# Illustrative only: invented field names, not one gateway's schema
org:
monthly_usd: 60000
mode: hard
teams:
search:
monthly_usd: 20000
mode: soft # notify the owner at the line
hard_ceiling_usd: 26000
keys:
search-prod: { monthly_usd: 18000, mode: soft, hard_ceiling_usd: 24000 }
search-dev: { monthly_usd: 1000, daily_usd: 100, mode: hard }
agent-runs: { per_run_usd: 25, daily_usd: 200, mode: hard }go deeper
Recall that budgets nest (organisation, team, key) and that a call needs room at every level, not only at its own key.
Explain reserving at every level together and releasing all holds if any level refuses, so the tightest budget binds.
Show where hard caps fit (development keys, batch jobs, agent runs) and why every refusal must name the level that was hit.
Own the trade: a hard stop on a revenue feature buys certainty about money with an outage, so set soft lines with hard ceilings, oversubscription ratios and who may raise a cap.
## Budgets as a tree A large organisation rarely has one spend cap. It has an **organisation budget** (what finance approved), **team budgets** beneath it, and **key budgets** beneath each team: a production key, a development key, a key for agent runs. The gateway's admission rule extends naturally: a call is admitted only if its reservation fits at **every level** from its key up to the organisation. 1. Compute the call's estimated maximum cost. 2. Reserve it at the key, the team and the organisation together. 3. If any level lacks room, release whatever was reserved and refuse, saying **which level** ran out. 4. On completion, settle the actual cost at every level. The holds must be taken all-or-nothing, so that concurrent calls cannot each pass at one level and fail at another; how a shared counter store does that atomically belongs to rate limiting. The effect is that the **tightest ancestor binds**: a key with plenty left is still refused when its team is out. ## Should the children add up to the parent? Not necessarily, and the choice is a policy rather than an accident. - **Exact partition**: team budgets sum to the organisation's. Predictable but wasteful, because teams rarely peak in the same month and idle budget sits locked. - **Oversubscription**: team budgets sum to more than the parent, say 130% of it. Idle budget flows to busy teams, and the organisation cap is the real backstop. - **The cost of oversubscribing**: a team can be refused while under its own cap, because the parent ran out first. The refusal must name the level, and someone must own the ratio. ## Hard and soft caps | Cap kind | At the line | Fits | Risk | |---|---|---|---| | **Hard** | Refuses new calls | Development keys, experiments, batch jobs, agent runs | A refused production feature is an outage | | **Soft** | Admits calls past the line and notifies the owner | Customer-facing features | Without a ceiling, only a parent cap bounds spend | | **Soft with a hard ceiling** | Soft at the line, hard at a higher figure | Most production keys | The gap is money the organisation has agreed in advance to risk | The judgment is what a refusal costs compared with what overspend costs. For a development key the worst case of a hard stop is a blocked experiment, which is cheap, so it is hard. For a customer-facing assistant, a hard stop at the forecast figure turns a busy month into an outage on its busiest day, so many leads choose a soft line that escalates to a person and a hard ceiling that bounds a disaster. The organisation level is usually hard, as the last backstop. ## Choosing windows A **monthly** window matches the invoice but has two weaknesses: a runaway can spend most of a month before it is stopped, and every budget resets on the same day. - Add **daily caps** under the monthly ones on keys that can run unattended, so a weekend loop stops at a day's allowance. - Use **per-run caps** on agent runs and batch jobs, so one job cannot spend a team's month. - Consider **rolling windows** where a fixed reset date invites month-start bursts. ## Who may change a cap A cap only the platform team can raise turns every busy launch into a ticket queue; a cap anyone can raise is decoration. A common middle ground: 1. team owners may move their own soft line within their approved budget; 2. raising a hard ceiling or a team budget needs approval from whoever owns the parent; 3. every change is recorded with who made it and why, and temporary raises expire. ## A default policy to start from 1. Organisation: a hard cap at the approved budget. 2. Teams: a soft line at their allocation, a hard ceiling some margin above it, and any oversubscription stated explicitly. 3. Production keys: soft with a hard ceiling. 4. Development, batch and agent keys: hard, with daily or per-run caps. 5. Every refusal names its level and its reset time. None of this has a single right answer. The ratio, the margin and who signs off are trade-offs between financial certainty and availability that a lead has to own, and revisit as spend grows.
- Should team budgets add up exactly to the organisation budget?Not necessarily. An exact partition wastes headroom, since teams rarely all peak in one month; oversubscribing lets idle budget flow to busy teams, with the organisation cap as the real backstop. The cost is that a team can be refused while still under its own cap, because the parent ran out, so the refusal must say which level was hit and someone must own the ratio.
- Why add a daily cap when the monthly budget is what finance cares about?A monthly cap stops a runaway only once it has spent the month. A daily cap, or a short rolling window, limits a weekend loop to a day's allowance and surfaces it early, while normal usage never touches it. It is a blast-radius control layered under the monthly figure, not a second budget.
- A call only needs to fit its own key's cap; parent budgets are just reports.
- Every cap should be hard, because a soft cap is no cap at all.
- Team budgets must always add up exactly to the organisation budget.
- Monthly caps are enough; shorter windows only add noise.
- Production keys should carry no cap at all, since any refusal there is an outage.