Bird
0
0

Identify the bug in this retry with exponential backoff pseudocode:

medium📝 Analysis Q6 of 15
Microservices - Resilience Patterns
Identify the bug in this retry with exponential backoff pseudocode:
max_retries = 3
base_delay = 100
retry_count = 1
while retry_count <= max_retries:
  wait_time = base_delay * (2 ** retry_count)
  retry_count += 1
  print(wait_time)
ABase delay should be multiplied by retry_count, not exponent
BRetry count should increment after print statement
CRetry count should start at 0 to calculate correct delay
DMax retries should be less than retry count
Step-by-Step Solution
Solution:
  1. Step 1: Analyze retry count initialization

    Retry count starts at 1, so first delay is base_delay * 2^1 = 200 instead of 100.
  2. Step 2: Correct initialization for expected delay

    Starting retry_count at 0 ensures first delay is base_delay * 2^0 = base_delay (100).
  3. Final Answer:

    Retry count should start at 0 to calculate correct delay -> Option C
  4. Quick Check:

    Retry count start = 0 for correct delay [OK]
Quick Trick: Start retry count at zero for correct exponential delay [OK]
Common Mistakes:
MISTAKES
  • Starting retry count at 1
  • Multiplying delay incorrectly
  • Incrementing retry count too early

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes