0
0
Microservicessystem_design~10 mins

Lessons from microservices failures - Interactive Code Practice

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

Complete the code to identify the common cause of microservices failure related to network issues.

Microservices
if service_response.status_code == [1]:
    retry_request()
Drag options to blanks, or click blank then click option'
A503
B500
C404
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 500 which is a server error but not specifically service unavailable.
2fill in blank
medium

Complete the code to implement a retry mechanism with exponential backoff in microservices communication.

Microservices
for attempt in range(max_retries):
    try:
        call_service()
        break
    except NetworkError:
        sleep([1] ** attempt)
Drag options to blanks, or click blank then click option'
A2
B3
Cattempt
Dmax_retries
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'attempt' as base causes linear backoff, not exponential.
3fill in blank
hard

Fix the error in the circuit breaker pattern implementation to prevent cascading failures.

Microservices
if failure_count > [1]:
    open_circuit()
else:
    call_service()
Drag options to blanks, or click blank then click option'
A-1
B5
C100
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or negative values disables circuit breaker logic.
4fill in blank
hard

Fill both blanks to correctly implement a health check for a microservice.

Microservices
def health_check():
    response = requests.get('[1]')
    return response.status_code == [2]
Drag options to blanks, or click blank then click option'
Ahttp://localhost:8080/health
Bhttp://localhost:8080/status
C200
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/status' or expecting 404 as healthy response.
5fill in blank
hard

Fill all three blanks to implement a timeout and fallback in a microservice call.

Microservices
try:
    response = call_service(timeout=[1])
except TimeoutError:
    response = [2]()

if response.status_code == [3]:
    process_response(response)
Drag options to blanks, or click blank then click option'
A5
Bfallback_service
C200
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using too high timeout or wrong status code.