tollgate-client
The instance-side runtime of Tollgate: the background tasks that keep a service's admission layer supplied and its usage accounted, all off the request path.
InstanceRuntimeowns account discovery, lease slots, supervised lease managers, and the usage writer. Its cloneableRuntimeHandleprovides staged admission, readiness, and reports.LeaseManagerkeeps an account's lease slot stocked from aLeaseAllocator, refilling at a low-water mark and consolidating a drained tail lease into its replacement.UsageWriterdrains a bounded channel of usage events into aUsageSinkin idempotent batches. When the channel is full, admission sheds before work is accepted, so committed work always has somewhere to be billed.KeyManagerrefreshes customer credentials from a read-onlyKeySource, bounding cached evidence by feed freshness and key expiry.PeriodRollerfunds budget schedules and rolls due periods, for applications that talk to a store directly.
The request path only loads published state and reserves channel permits.
Timestamps come from a Clock, so every behaviour is testable with a manual
clock.
Topologies
- Direct store: the runtime talks to a
tollgate-storebackend, such astollgate-store-postgres. - Via server: with the
httpfeature,HttpStoreimplements the store traits against atollgate-serverover authenticated TLS.
Shutdown
The runtime enforces one total shutdown deadline: it closes accounting admission, pauses refills, drains issued permits and guards, and releases account leases. Stop admitting, quiesce in-flight requests, then await the writer, so no committed usage is lost; undelivered events are counted rather than dropped silently.
Features
http: theHttpStoretransport to atollgate-server. Off by default; the direct-store topology needs none of it.
Getting started
docs/EMBEDDING.md
gives the supported request order and shutdown sequence, and
examples/pricing-api in the repository is a complete embedding. Credential
distribution is in
docs/CREDENTIAL_PROJECTION.md;
the contract is
INVARIANTS.md.
License
MIT OR Apache-2.0, at your option. Tollgate is a product of MorphIQ Labs, a trade name of Prophetizo LLC.