0
0
Microservicessystem_design~10 mins

Timeout 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 set a timeout for a microservice call.

Microservices
response = service.call(request, timeout=[1])
Drag options to blanks, or click blank then click option'
A5s
B5
C5000ms
Dtimeout
Attempts:
3 left
💡 Hint
Common Mistakes
Using just '5' without units may cause errors.
Using variable names instead of actual timeout values.
2fill in blank
medium

Complete the code to handle a timeout exception in a microservice call.

Microservices
try:
    response = service.call(request, timeout=3000)
except [1]:
    handle_timeout()
Drag options to blanks, or click blank then click option'
AServiceUnavailable
BConnectionError
CTimeoutError
DValueError
Attempts:
3 left
💡 Hint
Common Mistakes
Catching unrelated exceptions like ValueError.
Not catching any exception leading to crashes.
3fill in blank
hard

Fix the error in the timeout retry logic code.

Microservices
for attempt in range(3):
    try:
        response = service.call(request, timeout=2000)
        break
    except [1]:
        if attempt == 2:
            raise
        wait_before_retry()
Drag options to blanks, or click blank then click option'
ATimeoutException
BTimeoutExpired
CTimeout
DTimeoutError
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent exception names.
Not breaking the loop on success.
4fill in blank
hard

Fill both blanks to implement a timeout pattern with fallback and logging.

Microservices
try:
    response = service.call(request, timeout=[1])
except [2]:
    log_timeout()
    response = fallback_service.call(request)
Drag options to blanks, or click blank then click option'
A3000
BTimeoutError
C5000
DConnectionError
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception types.
Setting timeout as a string instead of number.
5fill in blank
hard

Fill all three blanks to create a timeout pattern with retry, timeout value, and exception handling.

Microservices
for i in range([1]):
    try:
        response = service.call(request, timeout=[2])
        break
    except [3]:
        if i == [1] - 1:
            raise
        wait_before_retry()
Drag options to blanks, or click blank then click option'
A3
B2000
CTimeoutError
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception names.
Incorrect retry count or timeout values.