Why Circuit Breakers Alone Won't Save Your Database
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
Database Rate Limiting: The Missing Piece After a Circuit Breaker — Keep Your DB Alive Under Load
When Redis fails, a circuit breaker won't protect your database. Add a DB rate limiter to cap traffic at 5,000 QPS and prevent cascading outages.
Optimizing API Rate Limiters: Reducing Latency from 200ms to 3ms with B-Tree Indexing
Implementing a B-tree index on a Postgres rate-limiter table reduced average latency from 182.34ms to 3.12ms and increased throughput to 3120 RPS.
Mastering System Design for Backend Engineers: Scalability, APIs, and Architecture
A comprehensive technical guide to building scalable backend systems for 10 million users, covering microservices, API protocols like gRPC and GraphQL, and database optimization strategies for high-performance backend engineering and Laravel applications.