liveBook · Manning

Fallback

As explained in The Art of Code

A fallback is an alternative behavior or result selected when the preferred operation is unavailable or unsuccessful.

A fallback preserves a useful outcome when a preferred operation cannot succeed. For technical failures, do not stop at logging: ask whether the application can continue with a degraded but acceptable result. A fallback is distinct from retrying. Retry addresses a possibly transient failure; fallback supplies an alternative after reasonable attempts fail or when the preferred dependency is unavailable. section 7.2.4

Use fallback deliberately at system boundaries, especially remote calls. A timeout may reflect a brief network or service outage, so retry first when that is reasonable. If the dependency remains unavailable, a circuit breaker can short-circuit later calls while it recovers; the caller can then use cached data or return a clear, actionable error. This contains repeated failure rather than letting every request wait on the same unhealthy dependency. section 7.2.4 section 9.2

Payment-service fallback

A payment-service call repeatedly times out. After a limited number of attempts, open a circuit breaker so new calls fail immediately instead of consuming more resources. During the open period, return a cached response where that remains acceptable, or explain clearly that the requested action cannot currently complete. The alternative must remain honest about what the system did not do. section 7.2.4 section 9.2

Fallback can also mean graceful degradation: preserve essential features while disabling or limiting noncritical ones under stress. Reduced image quality and temporary read-only mode are examples. This is a product and design decision, not a way to conceal errors; avoid a fallback that changes business rules, hides a failure, or crosses architectural boundaries without justification. section 9.2 section 7.2.4

Make the failure path readable. A method should communicate what success returns and what happens when it goes wrong, using meaningful exceptions, logs, or fallbacks as appropriate. Choose the response based on the failure category, the layer handling it, the recipient, and whether recovery is actually possible. section 2.5 section 7.2.4

How The Art of Code covers it

How deep it goes
Explains retry, circuit breakers, cached responses, and graceful degradation, while deferring implementation details to resilience libraries.
Examples
Uses remote timeouts, cached responses, actionable errors, reduced image quality, and temporary read-only mode.
What you can do after
Apply it via resilience policies by selecting an acceptable degraded result when a dependency remains unavailable.
How it connects
Connects fallback with retry, circuit breaker, cache, graceful degradation, logging, and error handling.

Also explained in

Compare how 15 books explain fallback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.