Describe a scenario where a microservice might fail. How would you implement the Circuit Breaker pattern to handle failures and maintain system resilience?

A microservice can fail when a downstream dependency, like a Payment service, becomes slow or unavailable, and the Circuit Breaker pattern handles this by monitoring failures and temporarily blocking further calls to give the failing service time to recover.

Key Points

Example

If the Payment service starts timing out under load, the circuit breaker around it opens after five consecutive failures, and the Order service immediately returns a "payment temporarily unavailable, please retry" response instead of hanging on every checkout request until it times out.

@CircuitBreaker(name = "paymentService", fallbackMethod = "paymentFallback")
public PaymentResponse charge(PaymentRequest request) {
    return paymentClient.charge(request);
}

public PaymentResponse paymentFallback(PaymentRequest request, Throwable t) {
    return PaymentResponse.unavailable();
}

Interview Tip

A concise interview answer is

If a dependency like Payment starts failing, I'd wrap calls to it in a circuit breaker that opens once failures cross a threshold, failing fast with a fallback instead of piling up timeouts. After a cooldown it tests recovery with a few trial requests before fully closing again, which keeps one failing service from cascading into the whole order flow.

Last updated: 16 July 2026

Previous question: How would you implement service discovery in a microservices environment? Discuss the differences between client-side and server-side discovery approaches.

Next question: What monitoring and logging strategies would you employ in a microservices architecture? How would you centralize logs and metrics for better observability?

More Microservices - Level II interview questions

All Microservices - Level II questions