Stores Overview

Stores are the backend that hitlimit uses to track request counts. Choose the right store based on your deployment needs.

Available Stores

StorePersistenceMulti-instanceBest For
MemoryNoNoDevelopment, single instance
SQLiteYesNoSingle server, persistence needed
RedisYesYesDistributed systems, high traffic

Quick Comparison

import { hitlimit, memoryStore } from '@joint-ops/hitlimit'
import { sqliteStore } from '@joint-ops/hitlimit/stores/sqlite'
import { redisStore } from '@joint-ops/hitlimit/stores/redis'

// Memory - default, no config needed
hitlimit({ limit: 100, window: '1m' })

// SQLite - persistent storage
hitlimit({
  limit: 100,
  window: '1m',
  store: sqliteStore({ path: './limits.db' })
})

// Redis - distributed
hitlimit({
  limit: 100,
  window: '1m',
  store: redisStore({ url: 'redis://localhost:6379' })
})

Choosing a Store

  • Development: Use the default memory store for simplicity
  • Single server production: SQLite provides persistence without external dependencies
  • Multiple servers: Redis ensures consistent rate limiting across all instances
  • Custom requirements: Create your own store

Store Interface

All stores implement the same interface:

interface Store {
  increment(key: string, window: number): Promise<{
    count: number
    resetAt: number
  }>
  reset(key: string): Promise<void>
}