| Users / Traffic | System Behavior | Fallback Usage | Impact on User Experience |
|---|---|---|---|
| 100 users | Low traffic, services mostly responsive | Fallback rarely triggered | Users get fresh data, fallback not noticeable |
| 10,000 users | Moderate load, occasional service delays | Fallback triggers occasionally during service slowdowns | Users see cached or default data sometimes, minimal disruption |
| 1,000,000 users | High load, frequent service timeouts or failures | Fallback triggers often to maintain availability | Users see degraded but available data, system remains responsive |
| 100,000,000 users | Very high load, multiple cascading failures possible | Fallback triggers extensively; fallback services may also degrade | Users experience limited functionality, possible stale data, but system avoids total failure |
Fallback pattern in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
The first bottleneck is the dependent microservice or external API that the main service calls. As traffic grows, these dependencies can become slow or unavailable due to overload or network issues. Without fallback, the entire request fails. The fallback pattern helps by providing an alternative response or cached data to maintain system responsiveness.
- Implement Circuit Breakers: Detect failing dependencies and trigger fallback quickly to avoid waiting on slow responses.
- Use Caching: Cache previous successful responses to serve during fallback, reducing load on dependencies.
- Horizontal Scaling: Add more instances of fallback services or caches to handle increased fallback requests.
- Graceful Degradation: Design fallback responses to provide minimal but useful data instead of full failure.
- Timeouts and Retries: Set appropriate timeouts and retry policies to avoid cascading delays.
- At 1M users with 10 requests per user per minute, system handles ~166,000 requests/sec.
- If 5% of requests trigger fallback, fallback services handle ~8,300 requests/sec.
- Cache storage depends on response size; for 1KB responses cached for 1 hour, storage ~30GB.
- Network bandwidth for fallback responses at 8,300 req/sec * 1KB = ~8.3 MB/s (~66 Mbps).
- Scaling fallback services horizontally to handle peak fallback load is cost-effective compared to full service scaling.
When discussing fallback pattern scalability, start by explaining the dependency failure risk. Then describe how fallback maintains availability under load. Discuss bottlenecks in dependencies and fallback services. Finally, explain scaling strategies like caching, circuit breakers, and horizontal scaling to handle increased fallback traffic.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Implement fallback mechanisms to serve cached or default data when the database is overloaded, preventing total failure. Also, add read replicas or caching layers to reduce direct database load.
Practice
fallback pattern in microservices?Solution
Step 1: Understand the fallback pattern role
The fallback pattern is designed to handle failures gracefully by providing an alternative response.Step 2: Identify the main goal
Its main goal is to keep the system responsive and avoid cascading failures by returning backup data or default messages.Final Answer:
To provide a backup response when a service call fails -> Option AQuick Check:
Fallback pattern = backup response [OK]
- Thinking fallback increases service calls
- Confusing fallback with permanent service replacement
- Assuming fallback is for logging only
Solution
Step 1: Review fallback implementation options
Fallback should provide a quick alternative response like cached data or default messages.Step 2: Eliminate incorrect options
Repeated calls can cause delays, ignoring failure hurts user experience, and restarting service is costly and slow.Final Answer:
Return cached data or a default message when the main service fails -> Option CQuick Check:
Fallback = cached or default response [OK]
- Retrying endlessly instead of fallback
- Returning errors instead of fallback data
- Restarting services unnecessarily
response = callMainService()
if response.failed:
response = fallbackResponse()
print(response)
What will be printed if callMainService() fails?Solution
Step 1: Analyze the failure condition
IfcallMainService()fails, the code assignsfallbackResponse()toresponse.Step 2: Determine printed output
The printed output will be the fallback response, not the failed original response or an error.Final Answer:
The fallback response -> Option AQuick Check:
Failed main call triggers fallback output [OK]
- Assuming failed response is printed
- Expecting program crash on failure
- Confusing fallback with error message
def get_data():
try:
return call_service()
except:
call_fallback()
What is the bug here?Solution
Step 1: Check try-except behavior
The try block returns the service call result, but except calls fallback without returning it.Step 2: Identify missing return
Without returning fallback's result, the function returns None on failure instead of fallback data.Final Answer:
The fallback function is not returned -> Option DQuick Check:
Missing return in except causes None [OK]
- Forgetting to return fallback data
- Misunderstanding try-except flow
- Assuming fallback raises error
Solution
Step 1: Understand fallback goals for payment service
Fallback should keep system responsive and avoid blocking user with delays.Step 2: Evaluate options for responsiveness and safety
Returning cached success immediately and updating asynchronously balances responsiveness and eventual consistency.Step 3: Eliminate risky or slow options
Retries cause delays, generic errors hurt UX, restarting service is costly and slow.Final Answer:
Return a cached success response immediately and update later asynchronously -> Option BQuick Check:
Cached immediate fallback with async update = best practice [OK]
- Excessive retries causing delays
- No fallback causing poor user experience
- Restarting services on failure
