Redis usage
In the application Redis database is currently used for the following purposes:
- As a storage for Sidekiq
- As backend storage for feature flags with Flipper
- As a storage for session data
- As a token bucket rate limiter using ratelimit gem
Current database assignment
In order to avoid key clash between different usages, we use the following database assignment:
| Database | Usage |
|---|---|
| 0 | Sidekiq |
| 2 | Flipper |
| 3 | Session Storage |
| 4 | Rate Limiter |
You can find connection details by searching for REDIS_URL env variable in the project or looking at file config/initializers/redis.rb.
Feature flags are read lazily, not preloaded
Flipper's railtie installs Flipper::Middleware::Memoizer with preloading on by
default, which runs preload_all — SMEMBERS flipper_features plus a pipelined
HGETALL — on every request, before any controller. config/initializers/flipper.rb
turns that off with config.flipper.preload = false.
Memoization itself stays on: a request that reads a flag still pays one round trip no matter how many times it reads it. Only the unconditional up-front fetch is gone, so a request that reads no flag — the probes included — never touches Redis at all.
Two reasons:
- The probes could not report a Redis outage. The middleware is the one
unconditional Redis call in the stack, so an unreachable broker turned every
request into an uncaught exception,
/healthzincluded. Its own providers rescue and answer 503 naming the failed dependency, but the middleware raised before the request ever reached them — which is what made a broker restart show up as a burst of errors and restarted pods rather than a quiet 503. - It bought nothing. The app has seven feature checks, four of them on web paths, and the typical request evaluates none. In production the pair of commands averaged ~2.8ms against a ~15ms median request.
The trade is that a request reading several distinct flags now issues one
HGETALL each instead of a single pipelined fetch. With at most two distinct
flags on any current path that is never the worse deal, but it is worth
re-checking if a code path ever starts reading many flags at once.