0
0
Microservicessystem_design~10 mins

Fallback pattern in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a fallback method for a microservice call.

Microservices
def get_user_data(user_id):
    try:
        return call_remote_service(user_id)
    except Exception:
        return [1]()
Drag options to blanks, or click blank then click option'
Alog_error
Bcall_remote_service
Cfallback_response
Draise_error
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original service call inside the except block
Raising an error instead of returning fallback
2fill in blank
medium

Complete the code to implement a fallback pattern using a circuit breaker.

Microservices
if circuit_breaker.is_open():
    response = [1]()
else:
    response = call_remote_service()
Drag options to blanks, or click blank then click option'
Afallback_response
Bcall_remote_service
Craise_exception
Dretry_call
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the remote service even when circuit is open
Raising exceptions instead of fallback
3fill in blank
hard

Fix the error in the fallback implementation to handle service failure gracefully.

Microservices
def fetch_data():
    try:
        data = call_service()
    except Exception:
        data = [1]
    return data
Drag options to blanks, or click blank then click option'
Alog_error()
Bcall_service()
Craise Exception
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the service again causing infinite loop
Raising exceptions instead of fallback
4fill in blank
hard

Fill both blanks to implement a fallback with a timeout and default response.

Microservices
try:
    response = call_service(timeout=[1])
except TimeoutError:
    response = [2]()
Drag options to blanks, or click blank then click option'
A5
B10
Cfallback_response
Dretry_call
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large timeout
Retrying instead of fallback on timeout
5fill in blank
hard

Fill all three blanks to create a fallback pattern with logging and default data.

Microservices
def get_data():
    try:
        return call_service()
    except Exception as e:
        [1](f"Service failed: {e}")
        return [2]()

fallback_response = lambda: [3]
Drag options to blanks, or click blank then click option'
Alog_error
Bfallback_response
C{"data": "default"}
Draise_exception
Attempts:
3 left
💡 Hint
Common Mistakes
Not logging errors
Raising exceptions instead of fallback
Fallback not returning default data