A fallback supplies a degraded but useful result when a primary operation or dependency fails. In synchronous service calls, it can preserve a usable response during a downstream disruption rather than failing the entire request. section 8.2.4 section 12.3.3
Fallback is especially useful in API composition, where a query depends on multiple provider services. A circuit breaker can fail fast when a provider is unavailable; a fallback can then supply replacement data so the composer can still respond. section 12.2.4 section 12.3.3
Choose a replacement that still supports a meaningful result:
- Return previously cached data. This requires a meaningful cache key, and the data may be stale. section 12.3.3
- Return a hardwired value. An empty value or fixed list can work when the remaining response still gives users a useful experience. section 12.3.3
Degraded order query
An API gateway composing an order response can return empty or cached delivery information when the Delivery Service is unavailable. The response remains useful, but the delivery information is missing or potentially stale. section 8.2.4 section 12.3.3
Figure 8.8 An API gateway that implements an endpoint using API composition can use the fallback pattern to return a useful response even when one or more of the services it calls are unavailable. For example, if the Delivery Service is unavailable, the GET /orders/{orderId} endpoint can return a response containing either empty or cached delivery information.
The diagram shows how an API gateway substitutes delivery information when a provider is unavailable. section 8.2.4
Fallback reduces effective runtime coupling, but it cannot eliminate it when a query needs fresh data from particular providers. Use it where replacement data remains meaningful; otherwise, a degraded response may not be a useful response. section 12.3.3
Listing 8.2 In a Spring Boot application, Resilience4j can be used by annotating client proxy methods. Method calls are intercepted by Spring AOP and wrapped with resiliency logic.
class OsoAuthorizer {
@CircuitBreaker(name = "osoAuthorizer")
@TimeLimiter(name = "osoAuthorizer")
@Retry(name = "osoAuthorizer", fallbackMethod = "isAuthorizedFallback")
public CompletableFuture<Boolean> isAuthorized(String user, String action, String securitySystem) {
...
}
private CompletableFuture<Boolean> isAuthorizedFallback(String user, String action, String securitySystem, Exception exception) {
return CompletableFuture.completedFuture(false);
}
This Spring Boot example attaches an authorization fallback returning false to a Resilience4j retry annotation. section 8.2.4























