Resilience & Service PatternsCircuit Breaker PatternMedium⏱️ ~3 min

Circuit Breaker Placement: Client Side, Service Mesh, or Gateway

Client Side Placement

Circuit breakers embedded in the calling service code. Each service instance maintains its own breaker state and failure counts. Advantages: no additional infrastructure, fine grained control per caller, works with any protocol. Disadvantages: inconsistent state across instances (one instance may have open breaker while others are closed), requires library support in each language, configuration scattered across services.

Service Mesh Placement

Circuit breakers in sidecar proxies (the separate container that handles all network traffic for a service). Each service pod has a proxy that handles circuit breaking transparently. Advantages: language agnostic, consistent behavior across services, centralized configuration, no code changes needed. Disadvantages: adds 1-2ms latency per hop, operational complexity of managing the mesh, still per instance state unless using mesh control plane.

Gateway Placement

Single circuit breaker at the API gateway protecting all callers. One breaker instance means consistent state: if the downstream service fails, all callers see the open state simultaneously. Advantages: single point of configuration, consistent protection, global view of downstream health. Disadvantages: single point of failure, coarse grained (cannot differentiate callers), may not protect internal service to service calls.

🎯 When To Use: Client side for fine control over specific dependencies. Service mesh when you need consistent cross cutting concerns without code changes. Gateway when protecting external traffic and you need a global view.

Combining Placements

Production systems often layer circuit breakers. Gateway breakers protect against external traffic spikes. Service mesh breakers handle internal service communication. Client side breakers add application specific logic like custom fallbacks. The key is avoiding conflicting thresholds where one breaker trips before another can help.

💡 Key Takeaways
Client side: fine grained control but inconsistent state across instances and requires per language library support
Service mesh: language agnostic with centralized config but adds 1-2ms latency and operational complexity
Gateway: global consistent state but coarse grained and does not protect internal service to service calls
📌 Interview Tips
1When discussing placement, explain the trade off between consistency (gateway) and granularity (client side)
2Mention service mesh as the modern approach when language heterogeneity or no code changes are requirements
3Note that production systems often layer breakers: gateway for external traffic, mesh for internal, client for custom fallbacks
← Back to Circuit Breaker Pattern Overview
Circuit Breaker Placement: Client Side, Service Mesh, or Gateway | Circuit Breaker Pattern - System Overflow