Design: Retry with Exponential Backoff in Microservices
Design focuses on retry logic between microservices communication. Out of scope are client-side retries and database transaction retries.
Functional Requirements
Non-Functional Requirements
Jump into concepts and practice - no test required
Client --> Service A --> Retry Middleware --> Service B
| |
| v
| Circuit Breaker
| |
v v
Logging & Monitoring Message Queue (for async retries)retry with exponential backoff in microservices?nth retry?max_retries = 3
base_delay = 100
for attempt in range(max_retries):
success = call_service()
if success:
print('Success')
break
else:
wait_time = base_delay * 2 ** attempt
print(f'Retry after {wait_time} ms')max_retries = 3
base_delay = 100
for attempt in range(max_retries):
success = call_service()
if success:
print('Success')
break
else:
wait_time = base_delay * 2 ** (attempt + 1)
sleep(wait_time / 1000)