Degradation Strategies: Fallbacks and Defaults
Static Fallback Values
The simplest degradation returns hardcoded defaults. Recommendation service down? Return top 10 popular products, a static list updated daily. Price unavailable? Show "Price unavailable, check in store." Static fallbacks require no external calls, guaranteed to work. Store fallback data in local memory or config files.
Cached Fallback Data
More sophisticated fallbacks use cached recent data. If catalog service fails, serve from local cache, potentially 1 hour stale but better than nothing. Set TTLs (Time To Live) to survive typical outages: 15-60 minutes for frequently changing data, 24 hours for stable data.
Feature Flags for Manual Degradation
Feature flags (configuration toggles) allow instant manual degradation. RECOMMENDATIONS_ENABLED=false removes recommendation calls across the system. During major events, preemptively disable non-essential features. Store in distributed config (Consul, etcd) for instant cluster-wide propagation.
Fallback Chains
Complex degradation uses chains: try primary, timeout after 100ms, try replica, check distributed cache, try local cache, return static default. Pattern: primary.call().orElse(replica).orElse(cache).orElse(default). Track which level served each request.
Async Fallbacks
Some operations degrade to async completion. Inventory check fails? Accept order optimistically, verify asynchronously. Payment timeout? Queue for retry, show "processing" status. Suitable when eventual consistency is acceptable and compensating actions (refunds) are possible.