Distributed throttle
Share one rate budget across workers by pointing the throttle at a shared store.
Share one rate limit across every worker or server by pointing the throttle at a
shared store. By default a stitch keeps its throttle counters in the in-memory
store, so the rate budget is per process: with pool: 'host' every stitch in
that process already pools into one budget per host (see
Throttle), but the in-memory store keeps that
pooling within a single process — each worker gets its own. Point the throttle at
a shared store and one budget spans every worker that uses it.
Example
import { } from 'stitchapi';
import type { StitchStore } from 'stitchapi';
// A shared store — e.g. @stitchapi/redis's redisStore() — see The pluggable store.
declare const : StitchStore;
const = ({
: 'https://api.example.com',
: '/search',
: { : '10/s', : 'host' },
: , // the budget now spans all workers using this store
});Options
throttle sets the limits — rate (e.g. '10/s'), concurrency, and
pool — while store decides where the counters live. The default in-memory
store is single-process, so each worker enforces 10/s on its own and the fleet
runs at 10/s × workers. A shared store holds the rate counter every worker
increments, so the whole fleet shares one 10/s budget — and grants are
even-spaced (about one every 100ms, i.e. window / limit), the same pacing
the in-process limiter uses, so attaching a store doesn't turn a smooth limit into
boundary bursts. (Concurrency stays in-process; only the rate limit is distributed.)
Even-spacing holds for load up to the limit. Under sustained overload — more than the budget, for longer than one window — distributed pacing is approximate at the window edges: a per-window counter can't carry a continuous backlog across processes the way the single-process limiter does. The budget itself still holds.
pool decides what shares a budget: 'stitch' (the default) gives each stitch
its own counter keyed by name, while 'host' keys by origin so every stitch
hitting api.example.com draws from one budget. Workers share a budget only when
they point at the same store and resolve to the same key — same pool, same
stitch name or host.
The same shared store also backs auth sessions, so one store gives you both a fleet-wide rate budget and a shared session — see Shared sessions.