Circuit Breaker / Retry / Bulkhead
Use complementary resilience patterns instead of one-size-fits-all retries.
📌 Key IdeaRetries recover transient failures, circuit breakers fail fast on sustained outages, and bulkheads isolate resources so one bad dependency cannot exhaust the whole service.
Problem it solves
- A failing downstream dependency can cascade and take down otherwise healthy services.
- Blind retries during outages often increase load and make recovery slower.
- Circuit breaker + retry + bulkhead split recovery, fail-fast, and isolation concerns cleanly.
Why It Matters
- Resilience patterns prevent one dependency outage from crashing the whole service.
- Correct policies protect latency SLOs during partial failures and traffic spikes.
- They convert random failure behavior into controlled, observable degradation.
Visual
🛡️ Resilience trio in call path
Request -> Retry policy -> Circuit Breaker -> Bulkhead-isolated dependency Retry : handles transient failures Breaker : stops hammering unhealthy dependency Bulkhead : limits blast radius by resource partitioning
When to Use
- Networked microservice calls with dependency failures.
- Critical APIs where cascading failures must be contained.
- Systems with variable downstream latency and intermittent outages.
When NOT to Use
- Blind retries on non-idempotent operations.
- Huge retry counts without jitter/backoff (retry storms).
Code Variations
Resilience4j sketchjava
Supplier<Response> guarded = Decorators.ofSupplier(() -> client.call())
.withRetry(retry)
.withCircuitBreaker(circuitBreaker)
.withBulkhead(bulkhead)
.decorate();Order and policy tuning matter; observe rejection/timeout metrics.
Pattern purpose matrix
| Aspect | Retry | Circuit Breaker | Bulkhead |
|---|---|---|---|
| Primary problem solved | Transient error recovery | Fail-fast during sustained failure | Resource isolation / blast-radius control |
| Main risk | Amplified load under outage | Too aggressive open thresholds | Over-partitioning resources |
| Must pair with | Backoff + jitter + idempotency | Health probes/half-open tuning | Capacity planning + queueing policy |
Interview Q&A
Quick Cheat Sheet
RetryTransient failures only; exponential backoff + jitter.
BreakerOpen on failure threshold; half-open probes for recovery.
BulkheadSeparate pools/queues per dependency path.