Skip to content

Releases: benjick/pg-ratelimit

v0.2.0

01 Mar 20:51

Choose a tag to compare

In-memory block strategy

Cache blocked keys in-process to skip DB round trips for repeated rate-limited requests. Enable with inMemoryBlock: true.

  • Significant latency and throughput improvements under load
  • maxBlockedKeys option (default: 10,000) caps cache size with automatic expired-entry sweeping
  • Negative-rate calls and resetUsedTokens() bypass/clear the cache automatically
  • InMemoryBlockConfig and DurableConfig discriminated union types - maxBlockedKeys is a type error unless inMemoryBlock: true
  • Benchmark package comparing both modes

Bug fixes

  • Fixed all internal doc links (absolute paths were missing /pg-ratelimit base, causing 404s)

Full changelog: v0.1.0...v0.2.0

v0.1.0

01 Mar 17:51

Choose a tag to compare

Initial release of pg-ratelimit — PostgreSQL-backed rate limiting for Node.js.

Added

  • Three rate limiting algorithms: fixed window, sliding window, and token bucket
  • limit() - check and consume rate limit tokens
  • blockUntilReady() - poll until success or timeout
  • getRemaining() - read remaining quota without consuming
  • resetUsedTokens() - full reset of a key's quota
  • Two-table design: ephemeral (UNLOGGED) for speed, durable (logged) for crash safety
  • Weighted costs via rate option
  • Negative rate for token refunds
  • Probabilistic inline cleanup of expired rows
  • Injectable clock for deterministic testing
  • TABLE_SQL export for manual migration
  • Auto-migration with CREATE TABLE IF NOT EXISTS (disable via PG_RATELIMIT_DISABLE_AUTO_MIGRATE)
  • synchronousCommit option for durable mode
npm install pg-ratelimit pg