Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AmeyaBorkar/throttlekit/llms.txt
Use this file to discover all available pages before exploring further.
twoTier constructs a limiter that fronts a distributed (L2) store with an in-process (L1) local
tier. The coordination mode controls the consistency/throughput trade-off: strict is exactly
equivalent to a plain rateLimit over L2; cached-deny eliminates round trips for already-blocked
keys; and leased drives steady-state network cost toward approximately one round trip per batch
requests, with a proven bounded global overshoot.
Signature
Options
The algorithm enforced at L2 (and, in leased mode, the unit of the leased budget). Any built-in
strategy works; custom strategies work in
strict and cached-deny modes.The distributed backing store. Typically a
RedisStore or PostgresStore. The caller owns
this store — close() on the returned limiter does not close it.Coordination mode. One of
"strict", "cached-deny", or "leased". See details below.Required when
mode is "leased". Controls the batch size and window-coupling behavior.Local-tier tuning.
Injected time source. Defaults to the system clock.
Key namespace prepended to every store key as
prefix:key.Coordination Modes
"strict"
Every check consults L2 directly. Globally exact (one round trip per request). Under the hood this
is equivalent to rateLimit({ strategy, store: l2, clock, prefix }).
"cached-deny"
Allowed traffic flows through L2 unmodified. When L2 issues a denial, its retryAfterMs is cached
locally and served directly for subsequent checks within that window, eliminating L2 load from
repeated blocked requests. Globally exact for allowed traffic.
"leased"
Each node leases a batch-sized budget from L2 and serves requests locally until the budget is
exhausted. Steady-state network cost is approximately one round trip per batch requests. Concurrent
misses on the same key are coalesced onto a single in-flight lease to prevent L2 stampedes.
The global overshoot bound is ≤ L × batch (where L is the live node count). With
windowCoupled: true the bound tightens to exactly Limit independent of node count.
Return Value
Returns aLimiter with the same interface as rateLimit. Note that checkSync and
checkManySync are not available on a twoTier limiter in cached-deny or leased mode
(L2 access is inherently asynchronous) — they throw a ThrottleKitError if called.
Helper Functions
eoqOptimum(orderCost, strandPenalty, demand)
√(2 · orderCost · demand / strandPenalty). The
target the adaptive lease sizer descends toward. Pure math, no state.
leaseSizer(options)
observe(demand)) and read back the batch for the next window (size()). @experimental.
predictiveLeaseSizer(options)
leaseSizer via a Hedge meta-learner. @experimental.
regionFairPool(options)
federatedWeightedFairEscrow. @experimental.
weightedFairEscrow(options)
@experimental.
federatedWeightedFairEscrow(options)
weightedFairEscrow across regions: per-region tenant WFE composed with a shared
cross-region regionFairPool into a global weighted-max-min guarantee. @experimental.