Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to implement a fallback response in a microservice.
Microservices
response = call_service() or [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Raising an exception stops the flow instead of degrading gracefully.
✗ Incorrect
Using a default response ensures the system continues working even if the service call fails.
2fill in blank
mediumComplete the code to check service health before calling it.
Microservices
if [1](): response = call_service() else: response = "fallback"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a negative health check leads to wrong logic.
✗ Incorrect
Checking if the service is available helps decide whether to call it or use fallback.
3fill in blank
hardFix the error in the circuit breaker pattern code.
Microservices
if circuit_breaker.[1](): response = call_service() else: response = "fallback"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_open allows calls when it should block them.
✗ Incorrect
The circuit breaker must be closed to allow calls; if open, calls are blocked.
4fill in blank
hardFill both blanks to implement a timeout fallback in a microservice call.
Microservices
try: response = call_service(timeout=[1]) except [2]: response = "fallback"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception type causes fallback not to trigger.
✗ Incorrect
Setting a timeout of 5 seconds and catching TimeoutError allows graceful fallback on delays.
5fill in blank
hardFill all three blanks to create a fallback cache mechanism.
Microservices
cache = [1]() if not cache.has(key): data = call_service() cache.[2](key, data) else: data = cache.[3](key)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using delete instead of get loses cached data.
✗ Incorrect
CacheStore is the cache class; set stores data; get retrieves data for fallback.