0
0
Microservicessystem_design~10 mins

Retry with exponential backoff 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 the initial retry delay.

Microservices
retryDelay = [1]
Drag options to blanks, or click blank then click option'
A1000 # milliseconds
B5 # attempts
Ctrue # enable retry
D0 # no delay
Attempts:
3 left
💡 Hint
Common Mistakes
Using retry count instead of delay
Setting delay to zero disables backoff
2fill in blank
medium

Complete the code to calculate the next retry delay using exponential backoff.

Microservices
nextDelay = retryDelay * (2 [1] attempt)
Drag options to blanks, or click blank then click option'
A**
B-
C+
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of power
Using integer division instead of power
3fill in blank
hard

Fix the error in the retry condition to stop after max attempts.

Microservices
if attempt [1] maxAttempts:
    stopRetrying()
Drag options to blanks, or click blank then click option'
A<=
B==
C>=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' which allows too many retries
Using '==' which may miss some cases
4fill in blank
hard

Fill both blanks to implement jitter in the retry delay calculation.

Microservices
import random
jitter = random.[1](0, retryDelay)
nextDelay = retryDelay [2] jitter
Drag options to blanks, or click blank then click option'
Arandint
B+
C-
Drandom
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'random' instead of 'randint'
Subtracting jitter instead of adding
5fill in blank
hard

Fill all three blanks to implement a capped exponential backoff with jitter.

Microservices
maxDelay = 30000
baseDelay = 1000
attempt = 3
rawDelay = baseDelay * (2 [1] attempt)
cappedDelay = min(rawDelay, [2])
jitter = random.[3](0, cappedDelay)
finalDelay = cappedDelay + jitter
Drag options to blanks, or click blank then click option'
A**
BmaxDelay
Crandint
DbaseDelay
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '**' for exponent
Using baseDelay instead of maxDelay for cap
Using random instead of randint for jitter