Skip to Content

Ratelock

Engines

Storage Engines

Choose the right storage engine for your rate limiting needs.

RateLock storage engines provide the storage layer for rate limit state. Each engine implements all 4 strategies and supports the same API.

Available Engines

EnginePackageBest For
Local@ratelock/localSingle-process apps, zero dependencies
Redis@ratelock/redisDistributed systems, high traffic
Upstash Redis@ratelock/upstashEdge and serverless deployments
PostgreSQL@ratelock/postgresApps already using Postgres

Same API, Different Backends

All storage engines expose the same interface. Their runtime support depends on the transport used by the adapter; see the runtime matrix.

// All engines support these methods
const limiter = await fixedWindow({ ... })

await limiter.check('user:123')        // Check single identifier
await limiter.checkBatch(['a', 'b'])   // Check multiple identifiers
await limiter.destroy()                // Clean up resources when needed

Choosing an Engine

  • Start with Local if you're running a single process or developing locally
  • Use Upstash Redis for Edge/serverless handlers or an HTTP-only deployment
  • Use Redis if you have multiple servers or need the highest performance over TCP
  • Use PostgreSQL if you already have Postgres and don't want to add Redis

Using Multiple Engines

You can mix engines in the same application:

import { fixedWindow as localFixedWindow } from '@ratelock/local'
import { fixedWindow as redisFixedWindow } from '@ratelock/redis'

// Lightweight in-memory limiter for health checks
const healthLimiter = await localFixedWindow({ limit: 1000, windowMs: 60_000 })

// Distributed Redis-backed limiter for API endpoints
const apiLimiter = await redisFixedWindow({
    url: 'redis://localhost:6379',
    limit: 100,
    windowMs: 60_000,
})

How is this guide?

Last updated on

On this page