Decide what happens when a guard is down
The rate limiter, auth cache or feature-flag service is unreachable.
Say it like this
The rate limiter is on every request path, so I decide per endpoint what a Redis outage means: public reads fail open with a local approximate limit, login and OTP fail closed, and the choice is configuration, not an accident.
Basic solution
Fail open (allow) for availability-first features; fail closed (deny) for security-sensitive ones. Decide per endpoint.
Per-endpoint policy when the guard is down
The same Redis outage produces two different outcomes: public reads continue on a local approximation, while login is rejected with a Retry-After.
How it works
- Every request passes through a guard before it reaches the real handler: a rate limiter that asks Redis for a counter, an auth cache that looks up a token, a feature-flag client that fetches the current flags, or a fraud check that scores the request. The guard is called with a short timeout of a few milliseconds, so a slow dependency cannot hold the request for long.
- The call fails: the timeout fires, the connection is refused, or a circuit breaker for that dependency is already open and the guard does not even try. The guard now has no answer and must decide what to do without one.
- The guard looks up the policy configured for this endpoint. There are three possible policies: open (let the request through), closed (reject it), or degraded (let it through with reduced permissions).
- Fail open: the request continues to the handler as if the guard had said yes. Where possible the guard substitutes a local approximation for the missing answer, such as an in-process token bucket that enforces a rough per-instance limit, or the last decision it cached for this user.
- Fail closed: the guard rejects the request with a status the client can act on, a 503 if a dependency is down or a 429 if a limit applies, and a Retry-After header saying when to try again. The handler never runs.
- Whichever policy applied, the guard increments a counter tagged with the policy it took and writes a log line, so a dashboard shows that fallback decisions are happening even while users notice nothing.
Who decides
- The owner of the endpoint, written into the rate-limit or auth config next to the limit itself, and reviewed like any other security setting.
Worked example
Distributed rate limiter at the API gateway
- 20K req/s across 40 gateway instances; each request does one Redis call with a 5 ms timeout.
- Redis is unreachable for 2 minutes = 2.4M requests needing a decision.
- Fail everything closed: 2.4M requests get 503. The product looks down even though the backends are fine.
- Fail everything open: no limits for 2 minutes. A single scraper that was limited to 100 req/min can now send 100K requests, and the OTP endpoint can be brute-forced at line rate.
- Per-endpoint policy: GET /feed and GET /{alias} fail open with a local bucket of limit ÷ 40 per instance, so a 1,000 req/min limit becomes 25 req/min per instance, roughly right. POST /login and POST /otp/verify fail closed. The outcome: 2.39M requests served with approximate limits, about 10K login attempts rejected for 2 minutes, and no security exposure.
Variants and when each wins
Fail open with no fallback
- The guard is skipped entirely and the request proceeds unchecked. This is acceptable only for guards that are optimisations, such as a recommendation filter, never for ones that protect money or accounts.
Fail open with a local approximation
- Each instance runs a degraded local version of the guard: a per-instance token bucket, a cached allow-list, the last known feature flags. It wins for availability-first endpoints, because most of the protection stays in place with no shared dependency.
Fail closed
- The request is rejected with 503 plus Retry-After and the handler never runs. It is the only correct answer for authentication, authorisation, payments, and anything an attacker would like to see disabled.
Fail degraded
- The request is allowed but limited to a narrower set of actions: read-only mode, lower quotas, no exports. It wins for authorisation caches, where you still know who the user is but not their latest permissions.
Recommendation: a per-endpoint policy with local approximation as the default for availability features and fail closed for anything security-sensitive.
Failure modes
Blanket fail-open hides a security hole
- During a Redis incident the login rate limit silently disappears, and a credential-stuffing run, which tries thousands of leaked passwords against accounts, succeeds. It happens because one global fallback applies to every endpoint, including the ones that exist to slow attackers down. Give each endpoint its own policy, with fail closed on auth and payments, and test it in staging by killing Redis on purpose.
Blanket fail-closed takes the product down
- A 30-second blip in the flag service returns 503 to every user. It happens because the flag service is treated as critical when the product works fine on yesterday's flags. Cache the last known good flags with a TTL of hours and fail open for any flag that is not security-related.
Nobody notices the degraded mode
- The system runs in fail-open mode for a week after a config error, and nobody realises until an audit. It happens because the metrics count allows but do not distinguish a real allow from a fallback allow. Count each policy outcome separately and alert when fallback decisions rise above a few percent of traffic.
Fallback is worse than the outage
- The local approximation lets 40 times more traffic through than the limit intended. It happens because every instance applies the full limit locally, so 40 instances each allow the whole quota. Size the local bucket at the limit divided by the instance count, and read the instance count from service discovery so it stays current as the fleet scales.
Fail-closed with no Retry-After
- Clients hammer the gateway with instant retries for as long as the guard is down. It happens because a bare 503 tells them nothing about when to come back. Return Retry-After with jitter, and put a circuit breaker in front of the guard so the gateway stops waiting for the timeout on every single request.
Interviewer follow-ups
Answer out loud before you open each one.
How do you decide which endpoints fail open?
Ask what an attacker gains if the guard vanishes. If the answer is nothing much (a scraper gets more pages), fail open with a local approximation. If the answer is an account, money, or a secret, fail closed. The list should be short and reviewed with security, not left to each developer.
What does fail open look like for an authorisation check?
Usually fail degraded rather than open: trust the cached permissions you already hold, with their age shown in the log, but refuse anything that needs fresh permissions such as role changes or exports. Pure fail open on authorisation means anyone can do anything, which is never acceptable.
How do you test the policy?
Kill the dependency in staging and run the request mix. Assert that fail-open endpoints return 200 with the fallback metric incremented and fail-closed ones return 503 with Retry-After. Put it in CI with a fake that returns timeouts, and run a game day once a quarter against the real thing.
How does this interact with a circuit breaker?
The breaker decides when to stop calling the guard; the fail policy decides what to do instead. Without the breaker every request pays the timeout before falling back; without the policy the breaker has nothing sensible to return. Configure them together per dependency.
Connections
- Pairs with
- Stop calling a failing dependency · Limit requests per client · Degrade instead of failing · Never wait forever
- Pulls against
- Authenticate, then authorise
- Used in
- Distributed Rate Limiter
The same parts on other clouds
The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.
| AWS | Used here as | Google Cloud | Microsoft Azure | Open source and others |
|---|---|---|---|---|
| Amazon API Gateway | API gateway | API Gateway, Apigee | API Management | Kong, Tyk |
| Amazon ElastiCache | Redis | Memorystore | Azure Managed Redis | Redis, Valkey, Memcached |
| Amazon EC2 Auto Scaling | Backend | Compute Engine managed instance groups | Virtual Machine Scale Sets | Kubernetes Deployment with a HorizontalPodAutoscaler, Nomad |