Handling failures gracefully in microservices relies on a set of established resilience patterns that each address a different way a service call can go wrong.
A call from the Order Service to a Shipping Rate API might have a 2-second timeout, be wrapped in a circuit breaker, retried once with backoff on transient failure, and fall back to a flat shipping estimate if all else fails — layering multiple patterns around a single dependency.
// Resilience4j (resilience4j-spring-boot3): timeout, retry, circuit breaker, fallback
@Service
public class ShippingRateService {
@TimeLimiter(name = "shipping")
@CircuitBreaker(name = "shipping", fallbackMethod = "defaultRate")
@Retry(name = "shipping")
public CompletableFuture<Rate> rate(String pincode) {
return CompletableFuture.supplyAsync(() -> shippingClient.rate(pincode));
}
private CompletableFuture<Rate> defaultRate(String pincode, Throwable ex) {
return CompletableFuture.completedFuture(Rate.flat(49)); // degrade gracefully
}
}
# application.yml
resilience4j:
timelimiter:
instances:
shipping:
timeout-duration: 2s
retry:
instances:
shipping:
max-attempts: 2
wait-duration: 300ms
circuitbreaker:
instances:
shipping:
sliding-window-size: 20
failure-rate-threshold: 50
wait-duration-in-open-state: 30sA concise interview answer is
I typically layer several patterns together — timeouts so a slow call doesn't hang forever, retries with backoff for transient failures, a circuit breaker to stop calling a service that's clearly down, bulkheads to isolate resources per dependency, and fallback methods so the caller degrades gracefully instead of failing outright. Each pattern covers a different failure mode, and together they make the system resilient.
Last updated: 11 November 2026
Previous question: What are the implications of service-specific databases on security?
Next question: What is the Circuit Breaker pattern?