0
0
Microservicessystem_design~10 mins

Circuit breaker 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 the state when the circuit breaker stops calls temporarily.

Microservices
circuit_breaker_state = "[1]"
Drag options to blanks, or click blank then click option'
Aopen
Bclosed
Chalf-open
Ddisabled
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'closed' which means calls are allowed.
Choosing 'half-open' which is a testing state.
2fill in blank
medium

Complete the code to check if the circuit breaker allows calls in the {{BLANK_1}} state.

Microservices
if circuit_breaker_state == "[1]":
    allow_calls = True
else:
    allow_calls = False
Drag options to blanks, or click blank then click option'
Afailed
Bopen
Cclosed
Ddisabled
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'open' which blocks calls.
Choosing 'disabled' which is not a standard state.
3fill in blank
hard

Fix the error in the code to transition from open to half-open state after timeout.

Microservices
if time_since_open > timeout:
    circuit_breaker_state = "[1]"
Drag options to blanks, or click blank then click option'
Aclosed
Bopen
Cdisabled
Dhalf-open
Attempts:
3 left
💡 Hint
Common Mistakes
Setting state back to 'open' which keeps blocking calls.
Setting state to 'closed' without testing.
4fill in blank
hard

Fill both blanks to complete the logic for recording failures and opening the circuit breaker.

Microservices
failure_count += 1
if failure_count [1] failure_threshold:
    circuit_breaker_state = "[2]"
Drag options to blanks, or click blank then click option'
A>=
B<
Copen
Dclosed
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which never triggers opening.
Setting state to 'closed' which allows calls.
5fill in blank
hard

Fill all three blanks to complete the dictionary comprehension that tracks service status with circuit breaker states.

Microservices
service_status = {service: [1] for service, state in services.items() if state [2] "[3]"}
Drag options to blanks, or click blank then click option'
Astate.upper()
B==
Copen
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which selects wrong services.
Not converting state to uppercase.