Synchronous service calls couple a caller’s response time and availability to downstream services. Resiliency patterns limit the impact of downstream failures or high latency, helping callers fail fast, preserve resources, and, where possible, return useful responses. section 8.2.4 section 12.3.3
Choose mechanisms that address the failure or load at hand:
- Bulkhead limits outstanding calls; rate limiter limits call frequency. section 8.2.4
- Time limiter bounds how long a caller waits; retry attempts a failed call again. section 8.2.4
- Circuit breaker fails fast after repeated failures, then permits a test request after a timeout. section 8.2.4
- Fallback returns a degraded but useful response, such as default or cached data; caching can also reduce load and latency. section 8.2.4
For API composition, apply protections at provider proxies. A fallback can let the composer return a usable result when a provider is unavailable; concurrent provider calls can also improve performance. Choose fallbacks carefully: cached or hardwired values may be preferable to failing the whole query. section 12.3.3
Order details with unavailable delivery data
An API gateway serving GET /orders/{orderId} can return empty or cached delivery information when the Delivery Service is unavailable, instead of losing the entire response. section 8.2.4
Figure 8.7 A circuit breaker implements a state machine. Initially it is in the closed state, which allows requests. But if there are too many errors, it transitions to the open state, which fails requests. After a timeout period, it then transitions to a half-open state, which allows a test request to be made. If the test request succeeds, the circuit breaker transitions to the closed state, otherwise it goes back to the open state.
The circuit-breaker diagram shows its closed, open, and half-open states and the test request that determines whether calls resume. section 8.2.4
In Spring Boot, Resilience4j can wrap client proxy methods through annotations and Spring AOP; an authorization example combines circuit breaker, time limiter, retry, and a fallback. section 8.2.4
