0
0
HLDsystem_design~12 mins

Idempotency for safe retries in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Idempotency for safe retries

This system ensures that repeated requests with the same intent do not cause duplicate effects. It supports safe retries by making operations idempotent, so clients can resend requests without risk of unintended side effects.

Key requirements include tracking request uniqueness, preventing duplicate processing, and providing consistent responses for repeated requests.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
Idempotency Service
  |           |
  v           v
Cache       Backend Service
  |           |
  v           v
Database    Database
Components
User
client
Sends requests to the system, may retry on failure
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Receives requests, performs authentication, routing, and forwards to Idempotency Service
Idempotency Service
service
Checks if request with same idempotency key was processed; returns cached response or forwards request
Cache
cache
Stores recent request results keyed by idempotency key for fast lookup
Backend Service
service
Processes the actual business logic for the request
Database
database
Stores persistent data and idempotency records for durability
Request Flow - 13 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayIdempotency Service
Idempotency ServiceCache
CacheIdempotency Service
Idempotency ServiceBackend Service
Backend ServiceDatabase
DatabaseBackend Service
Backend ServiceIdempotency Service
Idempotency ServiceCache
Idempotency ServiceAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Cache
Impact:Idempotency Service cannot quickly find cached responses, causing repeated requests to hit Backend Service and Database, increasing load and latency.
Mitigation:System falls back to checking idempotency records in Database to avoid duplicate processing, though with higher latency.
Architecture Quiz - 3 Questions
Test your understanding
Which component ensures that repeated requests with the same idempotency key do not cause duplicate processing?
ABackend Service
BLoad Balancer
CIdempotency Service
DAPI Gateway
Design Principle
This architecture demonstrates the principle of idempotency by using a dedicated service and cache to detect and handle repeated requests safely. It prevents duplicate side effects by storing request results keyed by unique idempotency keys, enabling safe retries and improving user experience.