Running on multiple instances
By default, every strategy keeps its state in the process. With several instances of your app, such as pods, workers, or serverless functions, each instance has its own rate limits, locks, and circuits. A limit of 100 calls per minute becomes 100 calls per minute and per instance.
The strategies that have a state shared between calls take a backend. Point that backend at Redis, a database, or DynamoDB, and the instances share the state.
What can be shared
Section titled “What can be shared”| Strategy | Default | Shared between instances |
|---|---|---|
| Rate limit | in memory | Yes, with a store. See Shared rate limits. |
| Lock | in memory | Yes, with a provider. See Distributed locks. |
| Cache | provider required | Yes, with a provider. See Shared cache. |
| Circuit breaker | in memory | With a store you write. See Custom backends. |
| Bulkhead | in memory | No. The limit applies per instance. |
| Dedupe | in memory | No. Each instance shares its own in-flight calls. |
| Stale fallback | in memory | No. Each instance serves the values it stored. |
| Retry budget | in memory | No. The budget applies per instance. |
| Timeout, retry, fallback, chaos | no state | Nothing to share. |
A bulkhead or a retry budget per instance is usually what you want: it protects the instance itself. Divide the limit by the number of instances when it must hold for the whole fleet.
Backends
Section titled “Backends”Tenace does not talk to Redis or a database itself. It calls a small interface, and ships adapters for three libraries that implement it on many backends:
| For | Adapter | Backends |
|---|---|---|
| Rate limits | rate-limiter-flexible |
Redis, Valkey, Memcached, Postgres, MySQL, SQLite, MongoDB, DynamoDB, etc. |
| Locks | Verrou | Redis, Postgres, MySQL, SQLite, DynamoDB |
| Cache | BentoCache | Redis, Postgres, MySQL, SQLite, DynamoDB, files |
The adapters are structural. They describe the part of each library that Tenace calls, and they import nothing at runtime. Install the library yourself, and only the ones you use.
To use another backend, implement the interface. See Custom backends.
Keys are shared too
Section titled “Keys are shared too”With a shared backend, the key of an execution names the value in the backend. Two instances that run with the key user:42 share one rate limit, one lock, or one cached value. Prefix the keys when several apps use the same Redis, or use the prefix option of the library.