All Questions
Api Design hard

Your payment API runs on 10 servers behind a load balancer. Two retries with the same Idempotency-Key hit different servers simultaneously. How do you prevent double-charging?

  1. A Utilize a centralized, distributed key-value store (like Redis or DynamoDB) using atomic, conditional writes (SETNX) to track and lock the Idempotency-Key across all regional server nodes.
  2. B Configure 'Session Affinity' at the load balancer level to ensure that retried requests originating from the same client IP are consistently routed to the identical application server instance.
  3. C Enforce a system-wide distributed lock manager by setting the primary database's isolation level to SERIALIZABLE, forcing every incoming request to be processed in a globally ordered sequence.
  4. D Rely on the client application to implement a locally-persisted request log and perform an internal deduplication check before attempting any secondary network retry for a failed transaction.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions