Reservations and settlements

Reservations are the spend. Services make them with their API keys; people and agents only read them, through budgets.

Reserving

Before a paid call, a service reserves its estimated cost: quantities for one or more meters, and the labels budgets match on. The reservation is the app's that the service's key belongs to, if it belongs to one, and in the key's environment. Tidegate checks every budget the reservation touches and, if all of them have room, charges it to all of them at once. Otherwise it denies the reservation, names the budget that refused it, and charges nothing.

The service chooses each reservation's id. Reserving again with the same id returns the first grant instead of charging twice, so a service can safely retry after a lost response. The same id with other quantities or labels, or from another app's or environment's key, is refused. A denial records nothing, so retrying a denied id checks the budgets again.

Reservations never expire.

Settling

Settling is optional. Once the call is done, the service can settle the reservation with what the call actually used, for exactly the meters it reserved. The actual quantities replace the estimate in the window the reservation was made in, even if that window has since ended.

A reservation settles at most once; settling again with the same quantities returns the first settlement. A settlement can come in above the estimate, which can push a budget past its limit; later reservations against that budget are then denied until its next window.

Estimating

Reserve what you expect the call to cost at most, then settle with the real figure. Estimating high briefly holds budget the call won't use; estimating low lets a budget overshoot, which the settlement then reveals.