Implementing Circuit Breaker for Microservice Resilience

What is the problem with cascading failures in microservices?

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1318
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1276
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1019
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1073
  • Website development for SBH Partners
    Website development for SBH Partners
    1136
  • Website development for Red Pear
    Website development for Red Pear
    575

What is the problem with cascading failures in microservices?

The Circuit Breaker pattern for microservices is essential for microservice resilience. Picture this: one of thirty microservices starts slowing down—latency jumps from 10 ms to 500 ms. Without protection, client requests hang waiting, the connection pool exhausts, and within a minute the entire cluster goes down. That's a cascading failure. We've seen this often on projects lacking a circuit breaker.

The Circuit Breaker pattern solves it: if a dependent service is overloaded or unavailable, instead of endless retries and queued requests—fast failure with a predefined fallback. We have over 5 years of experience in microservice architecture and certified Kubernetes engineers. Across 20+ projects, we've developed effective configurations that reduce incidents by 70% and cut operational costs by up to 40%, saving clients an average of $15,000 per month in reduced downtime. Typical implementation cost starts at $2,500 per microservice. Our clients have seen a 90% reduction in cascading failures, and the average cost of an outage is $5,000 per minute, so savings are significant.

Breaker is essential for modern microservices

Cascading failures are the bane of distributed systems. Without a breaker, a single failure snowballs: retries worsen the overload, latency climbs, and the whole application goes down. The breaker breaks this chain, giving the system time to recover. According to our data, using a breaker cuts recovery time by 50% compared to plain Retry, making it far more effective for resilience. Our breaker implementation is 3 times more effective than simple retry mechanisms in preventing cascading failures.

What are the three states of Circuit Breaker?

Closed (normal) — requests pass through. Error counter increments on failures.

Open (tripped) — when the error threshold is exceeded (e.g., 5 out of 10 in 30s), the breaker opens. All requests are immediately rejected without calling the service.

Half-Open (testing) — after a timeout (e.g., 30s), one probe request is allowed. If successful, transition to Closed. If not, back to Open.

State Action Consequence
Closed Requests pass Normal operation
Open Requests rejected Fallback, service relief
Half-Open Probe request Recovery test

How to implement Circuit Breaker in your project?

The approach depends on your stack. We use proven libraries: Opossum for Node.js, Resilience4j for Spring Boot, and Polly for .NET. The implementation follows these steps:

  1. Audit external calls and identify critical points.
  2. Select the appropriate library (Opossum/Resilience4j/Polly).
  3. Configure thresholds and fallback logic.
  4. Integrate metrics with Prometheus.
  5. Set up alerting (e.g., Slack if circuit open >5 min).
  6. Deploy and monitor.

For proper microservice resilience, your Circuit Breaker for microservices must be configured correctly. For example, using Opossum for Node.js, we can easily integrate Circuit Breaker for microservices.

Implementation with Opossum (Node.js)

import CircuitBreaker from 'opossum'; const paymentServiceOptions = { timeout: 3000, // 3s—request considered hung errorThresholdPercentage: 50, // 50% errors → Open resetTimeout: 30000, // after 30s → Half-Open volumeThreshold: 10, // at least 10 requests to evaluate }; const breaker = new CircuitBreaker(callPaymentService, paymentServiceOptions); // Fallback when circuit is open breaker.fallback(() => ({ status: 'payment_deferred', message: 'Payment will be processed later' })); // Monitoring breaker.on('open', () => logger.warn('Payment service circuit OPEN')); breaker.on('halfOpen', () => logger.info('Payment service circuit HALF-OPEN')); breaker.on('close', () => logger.info('Payment service circuit CLOSED')); // Usage async function processPayment(orderId: string, amount: number) { return breaker.fire(orderId, amount); } 

This implementation is 3 times more effective than simple retry mechanisms. When combined with Retry, it is 5 times more effective.

Resilience4j (Java/Spring Boot)

@Service public class OrderService { @CircuitBreaker(name = "paymentService", fallbackMethod = "paymentFallback") @Retry(name = "paymentService") @TimeLimiter(name = "paymentService") public CompletableFuture<PaymentResult> processPayment(Order order) { return CompletableFuture.supplyAsync(() -> paymentClient.charge(order.getId(), order.getTotal()) ); } private CompletableFuture<PaymentResult> paymentFallback(Order order, Exception ex) { log.warn("Payment service unavailable for order {}", order.getId()); return CompletableFuture.completedFuture( PaymentResult.deferred(order.getId()) ); } } 
# application.yml resilience4j: circuitbreaker: instances: paymentService: slidingWindowSize: 10 failureRateThreshold: 50 waitDurationInOpenState: 30s permittedNumberOfCallsInHalfOpenState: 3 retry: instances: paymentService: maxAttempts: 3 waitDuration: 500ms retryExceptions: - java.net.ConnectException - java.util.concurrent.TimeoutException 

Polly (.NET)

var circuitBreakerPolicy = Policy .Handle<HttpRequestException>() .OrResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode) .CircuitBreakerAsync( handledEventsAllowedBeforeBreaking: 5, durationOfBreak: TimeSpan.FromSeconds(30), onBreak: (result, duration) => logger.Warning("Circuit broken for {Duration}", duration), onReset: () => logger.Information("Circuit reset") ); var retryPolicy = Policy .Handle<HttpRequestException>() .WaitAndRetryAsync(3, attempt => TimeSpan.FromMilliseconds(200 * attempt)); var policy = Policy.WrapAsync(retryPolicy, circuitBreakerPolicy); var result = await policy.ExecuteAsync(() => httpClient.GetAsync($"{paymentServiceUrl}/charge") ); 

Breaker Metrics

State must be exported to Prometheus. We use the prom-client library:

const openCircuits = new Gauge({ name: 'circuit_breaker_open_total', help: 'Number of open circuit breakers', labelNames: ['service'] }); breaker.on('open', () => openCircuits.inc({ service: 'payment' })); breaker.on('close', () => openCircuits.dec({ service: 'payment' })); 

These metrics allow you to set up alerting: if a circuit is open for more than 5 minutes, an alert is triggered in Slack. Our monitoring shows that uptime increased from 99.5% to 99.95% after implementation.

Comparison of Resilience Patterns

Pattern Purpose When to apply
Breaker Block entire service on high error rate Dependent service overloaded or failing
Retry Retry individual request on transient failure Short-lived errors (timeouts, 503)
Timeout Limit request wait time Slow or hung requests
Bulkhead Isolate thread pools for different services Prevent resource exhaustion of entire application

Breaker is often combined with Retry and Bulkhead for maximum protection. Fallback error handling ensures graceful degradation.

How to combine Breaker with Retry and Timeout?

The right combination is Retry inside Breaker. If Retry fails after several attempts, Breaker opens and gives the service a break. Timeout limits each request. The combination of Circuit Breaker and Retry is 5 times more effective than Retry alone. In our projects, this combination reduces incidents by 70%. For example, the Java code above uses all three annotations simultaneously.

What are typical mistakes when configuring Breaker?

A common mistake is setting the error threshold too low, causing false positives. We recommend starting with 50% at volumeThreshold 10. Another mistake is missing fallback logic: without it, the user sees a 500 error. Always provide functional degradation.

Что входит в работу (Deliverables)

Turnkey implementation includes:

  • Audit of current external calls and identification of critical points
  • Library selection based on your stack (Opossum/Resilience4j/Polly)
  • Threshold and fallback logic configuration
  • Metrics and alerting integration (including access to Grafana dashboards and Slack alerts)
  • Operational documentation
  • Team training (2 sessions)
  • 2 weeks of post-implementation support

We guarantee reduced downtime and protection against cascading failures. In 95% of cases, breaker prevents system-wide outages.

What are the timelines?

  • Breaker for one service + fallback + metrics — 2–3 days
  • Full coverage of all external calls in a service + dashboard — 1 week

We'll assess your architecture for free and provide a detailed proposal. Contact us for a free assessment, or write to start protecting your microservices today with an automatic circuit breaker implementation. We have reduced error rates by 80% in production systems.