Skip to main content

On This Page

Why Circuit Breakers Alone Won't Save Your Database

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

A Circuit Breaker Alone Won’t Save Your Database

Daksh Gargas warns that circuit breakers alone don’t protect databases. Without a DB rate limiter, a Redis crash can route 100K RPS directly to the database, overwhelming it.

Why This Matters

A common misconception is that a circuit breaker protects your database—it only protects your app from repeated calls to a failing dependency. When Redis crashes and 100K RPS of traffic falls back to the database without a rate limiter, the database gets overwhelmed and the entire system collapses. The circuit breaker alone doesn’t decide the fallback; it only decides whether to try Redis in the first place.

Key Insights

  • Circuit breaker protects app from calling an unhealthy dependency, not the database itself.
  • If Redis (500ms timeout) fails, every request wastes time and eventually hits the database anyway.
  • DB rate limiter must live in the service, not the gateway, since only the service knows when it’s about to query the database.
  • Circuit breaker decides ‘should I even try Redis’; rate limiter decides ‘should I allow this request to the DB’.
  • Production systems combine local cache + circuit breaker + DB rate limiter for resilience.

Working Examples

Example of circuit breaker with DB rate limiter in Go

if circuitBreaker.IsOpen() {
    if localCache.Has(key) {
        return localCache.Get(key)
    }
    if !dbRateLimiter.Allow() {
        return 503
    }
    return db.Get(key)
}

Practical Applications

  • Use case: Normal traffic scenario: Redis serves 99K RPS, DB handles 1K RPS. Pitfall: Without rate limiter, Redis failure sends 100K RPS to DB, causing collapse.
  • Use case: Circuit breaker opens after repeated Redis failures. Pitfall: Assuming fallback to DB is safe—without rate limiting, the DB becomes the new bottleneck.
  • Use case: Service-level rate limiter decides which requests hit the database during fallback. Pitfall: Placing rate limiter in API gateway misses context of internal dependencies (Redis, Postgres, Elasticsearch, Kafka).

References:

Continue reading

Next article

AI Coding Agents Create a New Attack Surface: Autonomous Repo Execution Bypasses Human Vigilance

Related Content