Bird
Raised Fist0
Microservicessystem_design~20 mins

Fallback pattern in Microservices - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Fallback Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of fallback pattern

In a microservices architecture, what is the primary purpose of implementing a fallback pattern?

ATo log all service calls for auditing purposes
BTo provide an alternative response or behavior when a service call fails or is slow
CTo permanently disable a service when it fails once
DTo increase the number of service calls to improve throughput
Attempts:
2 left
💡 Hint

Think about how to keep the system responsive when a service is unavailable.

Architecture
intermediate
2:00remaining
Choosing the correct fallback implementation

You have a microservice that calls an external payment service. Sometimes the payment service is slow or unavailable. Which fallback approach is best to maintain user experience?

AQueue the payment request for later processing and inform the user of delay
BReturn a cached successful payment confirmation from a previous transaction
CRetry the payment call indefinitely until it succeeds
DReturn a default failure message immediately and log the error
Attempts:
2 left
💡 Hint

Consider user experience and system reliability when the external service is down.

scaling
advanced
2:00remaining
Scaling fallback mechanisms under high load

When a microservice experiences high load and many fallback executions, what is a key consideration to ensure the fallback system itself does not become a bottleneck?

AIncrease the number of fallback responses to match the load
BRemove all fallback logic to reduce complexity
CImplement rate limiting and circuit breakers to control fallback invocation
DDisable monitoring to reduce overhead
Attempts:
2 left
💡 Hint

Think about controlling traffic and preventing overload.

tradeoff
advanced
2:00remaining
Tradeoffs of aggressive fallback usage

What is a potential downside of aggressively using fallback responses in a microservices system?

AIt may mask real issues and delay fixing the root cause of failures
BIt always improves system performance without drawbacks
CIt reduces the need for monitoring and alerting
DIt guarantees 100% uptime for all services
Attempts:
2 left
💡 Hint

Consider what happens if fallback hides problems.

component
expert
3:00remaining
Designing a fallback component for a microservice

You are designing a fallback component for a microservice that calls multiple downstream services. Which design choice best supports scalability and maintainability?

AImplement a centralized fallback service that handles all fallback logic for downstream calls
BDisable fallback and rely solely on retries
CEmbed fallback logic directly inside each microservice's business logic without separation
DUse a shared library with configurable fallback strategies that each microservice imports
Attempts:
2 left
💡 Hint

Think about code reuse and flexibility across services.

Practice

(1/5)
1. What is the main purpose of the fallback pattern in microservices?
easy
A. To provide a backup response when a service call fails
B. To increase the number of service calls
C. To replace the main service permanently
D. To log all service requests for auditing

Solution

  1. Step 1: Understand the fallback pattern role

    The fallback pattern is designed to handle failures gracefully by providing an alternative response.
  2. 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.
  3. Final Answer:

    To provide a backup response when a service call fails -> Option A
  4. Quick Check:

    Fallback pattern = backup response [OK]
Hint: Fallback means backup response on failure [OK]
Common Mistakes:
  • Thinking fallback increases service calls
  • Confusing fallback with permanent service replacement
  • Assuming fallback is for logging only
2. Which of the following is a correct way to implement a fallback method in a microservice?
easy
A. Ignore the failure and return an error to the user
B. Call the main service repeatedly until it succeeds
C. Return cached data or a default message when the main service fails
D. Restart the entire microservice on failure

Solution

  1. Step 1: Review fallback implementation options

    Fallback should provide a quick alternative response like cached data or default messages.
  2. Step 2: Eliminate incorrect options

    Repeated calls can cause delays, ignoring failure hurts user experience, and restarting service is costly and slow.
  3. Final Answer:

    Return cached data or a default message when the main service fails -> Option C
  4. Quick Check:

    Fallback = cached or default response [OK]
Hint: Fallback returns cached or default data on failure [OK]
Common Mistakes:
  • Retrying endlessly instead of fallback
  • Returning errors instead of fallback data
  • Restarting services unnecessarily
3. Consider this pseudocode for a microservice call with fallback:
response = callMainService()
if response.failed:
    response = fallbackResponse()
print(response)
What will be printed if callMainService() fails?
medium
A. The fallback response
B. The original failed response
C. An error message and no response
D. Nothing, the program crashes

Solution

  1. Step 1: Analyze the failure condition

    If callMainService() fails, the code assigns fallbackResponse() to response.
  2. Step 2: Determine printed output

    The printed output will be the fallback response, not the failed original response or an error.
  3. Final Answer:

    The fallback response -> Option A
  4. Quick Check:

    Failed main call triggers fallback output [OK]
Hint: Failed call triggers fallback print [OK]
Common Mistakes:
  • Assuming failed response is printed
  • Expecting program crash on failure
  • Confusing fallback with error message
4. This code snippet tries to implement a fallback but has a bug:
def get_data():
    try:
        return call_service()
    except:
        call_fallback()
What is the bug here?
medium
A. The code does not catch exceptions
B. The try block does not call the service
C. The except block should raise an error
D. The fallback function is not returned

Solution

  1. Step 1: Check try-except behavior

    The try block returns the service call result, but except calls fallback without returning it.
  2. Step 2: Identify missing return

    Without returning fallback's result, the function returns None on failure instead of fallback data.
  3. Final Answer:

    The fallback function is not returned -> Option D
  4. Quick Check:

    Missing return in except causes None [OK]
Hint: Always return fallback result in except block [OK]
Common Mistakes:
  • Forgetting to return fallback data
  • Misunderstanding try-except flow
  • Assuming fallback raises error
5. You design a microservice that calls a payment gateway. To avoid delays, you want to use the fallback pattern. Which fallback strategy is best to keep the system responsive and safe?
hard
A. Return a generic error message without fallback
B. Return a cached success response immediately and update later asynchronously
C. Retry the payment gateway call 10 times before fallback
D. Restart the payment microservice on failure

Solution

  1. Step 1: Understand fallback goals for payment service

    Fallback should keep system responsive and avoid blocking user with delays.
  2. Step 2: Evaluate options for responsiveness and safety

    Returning cached success immediately and updating asynchronously balances responsiveness and eventual consistency.
  3. Step 3: Eliminate risky or slow options

    Retries cause delays, generic errors hurt UX, restarting service is costly and slow.
  4. Final Answer:

    Return a cached success response immediately and update later asynchronously -> Option B
  5. Quick Check:

    Cached immediate fallback with async update = best practice [OK]
Hint: Use cached immediate fallback plus async update [OK]
Common Mistakes:
  • Excessive retries causing delays
  • No fallback causing poor user experience
  • Restarting services on failure