Under heavy development
StitchAPI
GuidesState & stores

Distributed throttle

Share one rate budget across workers 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 — 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 Redis- or Postgres-backed store, shared across workers — 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 scope — 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 as a fixed-window count every worker increments, so the whole fleet shares one 10/s budget. (Concurrency stays in-process; only the rate limit is distributed.)

scope 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 scope, 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.

See also

On this page