Redis requirements
A single gateway instance keeps its counters and caches in memory and does not need Redis. As soon as you run more than one instance, or more than one worker per instance, Redis becomes the shared state that keeps rate limits, budgets and routing decisions consistent across all of them. The gateway can use one Redis for everything or a separate coordination Redis for counters and locks, kept away from the response cache. Both are part of the free gateway.
A real-world scenario
A team runs three gateway replicas behind a load balancer and gives a customer key a limit of 60 requests per minute. Without Redis each replica counts on its own, so the customer can make 180 requests a minute. The admin configures a coordination Redis on the Response Cache page and restarts the replicas. The counters are now shared, the limit is 60 across the fleet, cooldowns of a failing deployment are seen by every replica at once, and the scheduled jobs run on one replica instead of three.
Step by step
In the Admin UI
- Open
/ui/cachingas a proxy admin and pick the Coordination Redis tab. The badge next to the heading says where coordination comes from today, Configured here, Borrowed from response cache, From REDIS_ environment* or Not configured. - Choose the Redis Type, Node (Single Instance), Cluster or Sentinel, and fill in Connection Settings, or paste a Redis URL. Turn on SSL under SSL Settings when the server requires TLS.
- Click Test Connection and wait for Coordination Redis connection test successful!.
- Click Save Changes. The tab reads Saved changes take effect on proxy restart., so restart the replicas.
- After the restart the badge reads Configured here, and the start up log no longer warns that limits are enforced per replica.
With curl
Router state uses the Redis given in router_settings, and the response cache uses cache_params. You can point both at the same server.
router_settings:
redis_host: os.environ/REDIS_HOST
redis_port: os.environ/REDIS_PORT
redis_password: os.environ/REDIS_PASSWORD
spanway_settings:
cache: true
cache_params:
type: redis
host: os.environ/REDIS_HOST
port: os.environ/REDIS_PORT
password: os.environ/REDIS_PASSWORD
To keep coordination traffic (rate limit counters, spend tracking, pod locks and shared health checks) away from the response cache, configure a separate coordination Redis. It takes precedence over the cache Redis and the REDIS_* environment fallback for those features.
general_settings:
coordination_redis:
host: redis-coordination.internal
port: 6379
password: os.environ/COORDINATION_REDIS_PASSWORD
ssl: true
For a cluster, list the nodes with startup_nodes, each with a host and port. Test and save the same settings over the API.
curl -X POST http://localhost:4000/coordination_redis/settings/test \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"settings": {"host": "redis-coordination.internal", "port": 6379, "password": "os.environ/COORDINATION_REDIS_PASSWORD", "ssl": true}}'
curl -X POST http://localhost:4000/coordination_redis/settings \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"settings": {"host": "redis-coordination.internal", "port": 6379, "password": "os.environ/COORDINATION_REDIS_PASSWORD", "ssl": true}}'
curl http://localhost:4000/coordination_redis/settings -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result
The test answers {"status": "healthy", "error": null}. The save answers Coordination Redis settings updated successfully. Restart the proxy to apply them. and writes an audit log row. GET /coordination_redis/settings returns the saved values with the password redacted and "source": "coordination_redis". After the restart a key with a 60 request per minute limit gets 429 on its 61st request in a minute no matter which replica it hits, a deployment cooled down on one replica is skipped by all of them, and only one replica runs each scheduled job.
Features that use Redis
| Feature | Without Redis | With Redis |
|---|---|---|
| RPM, TPM and parallel request limits | Enforced per worker, so the effective limit is multiplied by the number of workers | Enforced across the whole fleet |
| Router cooldowns and usage based routing | Each instance tracks deployment health and usage on its own | Shared view of failures and usage |
| Response caching | In-memory cache per instance | Shared cache, see caching |
| Key and user cache | Per instance | Optional shared auth cache with enable_redis_auth_cache |
| Spend update buffering | Each instance writes spend to Postgres | Buffered in Redis with general_settings.use_redis_transaction_buffer, which reduces database lock contention |
| Shared health checks and pod locks | Every instance runs scheduled jobs | One instance takes the lock |
| Provider budgets and shared latency measurements | Per instance | Shared, see provider budget routing and provider preferences |
Connecting with environment variables
The gateway reads standard connection variables for any Redis it needs.
| Variable | Purpose |
|---|---|
REDIS_HOST, REDIS_PORT | Host and port of a standalone Redis. |
REDIS_URL | Full connection URL, for example redis://:password@host:6379/0. Used instead of host and port. |
REDIS_PASSWORD, REDIS_USERNAME | Credentials. |
REDIS_SSL | Connect over TLS. |
REDIS_CLUSTER_NODES | JSON list of cluster startup nodes. |
REDIS_SENTINEL_NODES, REDIS_SERVICE_NAME, REDIS_SENTINEL_PASSWORD | Redis Sentinel deployments. |
REDIS_AZURE_AD_TOKEN | Microsoft Entra ID token for Azure Cache for Redis. |
REDIS_GCP_SERVICE_ACCOUNT, REDIS_GCP_SSL_CA_CERTS | IAM auth for Google Cloud Memorystore. |
Sizing and settings
Redis load is proportional to request rate, not payload size, except for response caching. Disable eviction for the coordination instance (maxmemory-policy noeviction) so counters are never dropped, and place it in the same region as the gateway, because rate limit checks sit on the request path.
When Redis is unreachable
Redis is required for exact rate limits across replicas. Without any Redis configured the gateway keeps counting in memory, so each replica enforces every limit on its own, and it logs a warning at startup that limits are per replica.
When Redis is configured but a counter cannot be read or updated, the gateway fails closed by default. Requests that carry an RPM, TPM, parallel request, max iterations or per session budget limit get a 503 that says the counters could not be verified, and requests without such a limit are not affected. This keeps a Redis outage from letting traffic past the limits you set.
If you would rather keep serving during an outage and accept that each replica enforces the limits on its own until Redis recovers, turn this off explicitly.
general_settings:
fail_closed_rate_limit_enforcement: false
Budgets follow the same default. When a key, team, user, org or model budget cannot be verified because Redis or the database is unavailable, the request gets a 503, and fail_closed_budget_enforcement: false is the only setting that admits it anyway.
Errors
| What you see | Why | Fix |
|---|---|---|
503 saying rate limit counters could not be verified | Redis is configured but unreachable, and the gateway fails closed. | Fix the connection, or set fail_closed_rate_limit_enforcement: false to serve during the outage. |
503 saying a budget could not be verified | Redis or the database is down. | Same as above, with fail_closed_budget_enforcement: false. |
| A start up warning that limits are enforced per replica | No Redis is configured. | Configure the coordination Redis. |
status: unhealthy, Connection timed out after 5.0s from the test | The gateway cannot reach the host within five seconds. | Check the address, port, security groups and TLS. |
| The badge still reads Borrowed from response cache after saving | Coordination settings apply at the next restart. | Restart the replicas. |
500 Set STORE_MODEL_IN_DB=True on save | Saved settings live in the database. | Set the variable, connect a database and restart. The config file works without it. |
| Counters reset unexpectedly | The Redis evicts keys under memory pressure. | Set maxmemory-policy noeviction on the coordination instance and size it for the key count. |
Related
- Testing a Redis connection walks through the test routes for both Redis roles.
- Caching on the gateway covers the response cache.
- Response Cache page documents the Coordination Redis tab.
- Reliability explains the fail closed behaviour in the context of outages.
- Production deployment lists Redis among the production checklist items.