Skip to content

OPEN SOURCE · TYPESCRIPT

throttlekit

An open-source TypeScript rate-limiting library implementing fixed window, sliding window log and token bucket behind a single API surface.

See it on GitHub
  • TypeScript
  • Jest
  • GitHub Actions

01The name is taken, and that is worth saying here

There is a `throttlekit` on npm and it is not this one. It belongs to Ameya Borkar, it is at 1.7.0, and it is a more built-out library than this: a machine-checked overshoot bound, one atomic store across in-memory, Redis and Postgres, a sync API measured in nanoseconds.

This is a GitHub repository under the MIT licence and has never been published to the registry, so anyone who installs the name gets that project rather than this one. Saying so costs nothing. Leaving a reader to discover it is how the rest of the figures on this site stop being believed.

02Why three algorithms

Fixed window is cheap and fine until traffic clusters at a boundary and you serve double your limit in a two-second span. Sliding window log fixes that and costs memory. Token bucket handles bursts gracefully and is the wrong mental model for a hard quota.

They are different trade-offs rather than better and worse, so the library ships all three behind one interface and lets the caller choose.

03The tests are the point

A Jest suite built around the cases that actually bite in production: boundary conditions at window edges, clock skew, and concurrent consumption of the same bucket. GitHub Actions runs it on every push.

04Built with

  • TypeScript
  • Jest
  • GitHub Actions

More work