The 30 second answer
I put a timeout on every remote call so threads never hang. A circuit breaker fails fast once the error rate crosses a threshold, and a bulkhead caps concurrent calls so one dependency can't take every thread. I retry only idempotent calls, with capped backoff and jitter, because retries add load to a struggling service. And I add a fallback, like cached data or a degraded response.
Timeouts on every call, so threads aren't stuck. A circuit breaker (Resilience4j: CLOSED, OPEN, HALF_OPEN) fails fast once the error rate crosses a threshold. A bulkhead caps concurrent calls to that dependency so it can't use all threads. Retries only for idempotent calls, with capped backoff and jitter. Plus a fallback, such as cached data or a degraded response. Follow-up: Why can retries make it worse? (They multiply load on a struggling service; the Builders' Library says to cap them.)
Alternate interview scenarios
"A microservice goes down while the other services are healthy. How should your system handle it?"
The goal is that one failure stays one degraded feature. Callers find out quickly through timeouts and an open circuit breaker, then return a fallback or a partial response instead of an error page. Work that does not need an immediate answer goes through a queue, so the queue buffers it until the service comes back. On the platform side, readiness probes remove failing instances from traffic and liveness probes restart stuck ones. A liveness check must not depend on other services. Otherwise one service going down marks every caller unhealthy and the platform restarts the healthy fleet.
"A retry mechanism is making a downstream outage worse. Why?"
Retries add load at exactly the moment the downstream has the least capacity left. They also multiply: if three layers each try three times, one user request can become 27 calls. Without jitter, clients retry at the same moments, so the load arrives in waves. I retry at one layer only, use capped exponential backoff with jitter and a retry budget, and retry only idempotent calls. I also let the open circuit breaker stop retries completely.
"You receive 10K requests per second, but a downstream service can handle only 1K. How do you design it?"
Here the downstream is healthy but permanently smaller, so a circuit breaker alone does not solve it. That only protects you after the downstream starts failing. I first cut the demand that actually reaches it. I cache responses that are read often, collapse identical in-flight requests into one call, and batch many items into one request when the API supports it. For the rest I put a client-side rate limiter in front of the call at a little under 1K per second, so the downstream never sees more than it can handle. Then I decide what happens to the excess. If the caller needs an immediate answer, I reject quickly with 429 or 503 and a Retry-After header, or return a degraded response. If the work can wait, I accept it with 202 and put it in a queue that workers drain at the downstream's rate. The queue needs a maximum size and an age limit. Otherwise a long spike becomes a backlog that the system can never catch up on.
"Implement a circuit breaker around a downstream call."
In a Spring Boot service I reuse one breaker per dependency/configuration, rather than constructing it inside each request. A minimal programmatic example with Resilience4j is:
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import java.time.Duration;
import java.util.function.Supplier;
CircuitBreakerConfig config = CircuitBreakerConfig.custom()
.slidingWindowSize(20)
.minimumNumberOfCalls(10)
.failureRateThreshold(50)
.waitDurationInOpenState(Duration.ofSeconds(10))
.permittedNumberOfCallsInHalfOpenState(3)
.build();
CircuitBreaker breaker = CircuitBreaker.of("inventory", config);
// Create these once at component initialization; inventoryClient is injected.
Supplier<Inventory> guarded = CircuitBreaker.decorateSupplier(
breaker, () -> inventoryClient.fetch());
// In the request path:
Inventory result = guarded.get();This is a wiring fragment: Inventory and inventoryClient represent the application's DTO/client. The protected supplier must expose the relevant failure to the breaker; catching every exception inside it and returning success hides failures from the metrics. Classify expected business rejections separately from dependency failures. Handle CallNotPermittedException and a permitted fallback outside the protected call, without inventing successful inventory or payment state. The sample's minimum-call count prevents one initial failure from opening the circuit; thresholds are illustrative, not universal production settings. An OPEN breaker rejects calls, then HALF_OPEN allows a limited number of probes before recovery or reopening. Test success, threshold failures, rejection while OPEN and the bounded recovery probes using a fake dependency and controlled time/test hooks.
Implementation traps.
A sliding-window size is not a concurrency cap; use a bulkhead for that. A slow-call threshold records slow calls, but does not cancel an HTTP request: configure connect/read/overall deadlines in the actual client separately. Decide decorator ordering and count physical attempts when combining retries, because retrying a rejected or non-idempotent operation can defeat the protection. Keep failure-state metrics visible and ensure an exception-to-fallback conversion does not make an outage look healthy.
"The circuit breaker never opens, or opens on the wrong errors. Why?"
Check three settings. First, what counts as a failure: by default every exception is recorded, so business errors such as validation failures or 404s can open the breaker; ignoreExceptions excludes them and recordExceptions limits counting to real dependency failures. Second, minimumNumberOfCalls: with the default of 100 and a default window of 100 calls, a low-traffic endpoint may never reach enough calls to evaluate the 50% failure-rate threshold. Third, fallbacks: if the fallback turns every exception into a cached or empty response, dashboards show success while the dependency is down. I expose the breaker state and the fallback rate as metrics and alert on them.
Sources (9)
- Resilience4j: CircuitBreakerresilience4j.readme.io
- Resilience4j: Bulkheadresilience4j.readme.io
- AWS Builders' Library: Timeouts, retries and backoff with jitteraws.amazon.com
- Using load shedding to avoid overloadaws.amazon.com
- Kubernetes: Liveness, readiness and startup probeskubernetes.io
- Spring Boot: Kubernetes probes and external systemsdocs.spring.io
- Resilience4j: Retryresilience4j.readme.io
- Resilience4j: RateLimiterresilience4j.readme.io
- AWS Builders' Library: Avoiding insurmountable queue backlogsaws.amazon.com