KatInterview

Architecting a Payment Gateway with Real-Time Authorization and Batch Settlement

System DesignModel answer
MediumModel answerSystem Designsystem-designpayment-processingidempotency

Last updated

Design a robust payment architecture that handles real-time authorization holds, deferred batch captures, and safe retries without double-charging users.

Design a payment system that executes two main money movement stages: placing a real-time authorization hold on a payer's funds at order placement, and settling (capturing) held funds later in batch jobs.

Your architecture must address:

  1. Real-time Hold & Batch Capture: End-to-end lifecycle, API flow, data model, and batch generation.
  2. Idempotency & Safe Retries: Ensuring network retries, client double-clicks, and background job execution never duplicate authorizations or captures.
  3. Consistency & Failure Recovery: Handling edge cases like network timeouts mid-flight, processor outages, orphan holds, and asynchronous reconciliation.

Clarifications & Scope Assumptions

  • Scale: Assume 2,000 peak authorization requests/sec and daily/event-driven batch settlements processing 5M events per night.
  • Model: Assume integration with external acquirers/processors (e.g., Stripe, Adyen) via API, while maintaining an internal double-entry ledger.
  • Holds: Authorizations expire after 7 days unless captured or explicitly released. Partial captures are allowed.

Hints

Hint 1

Differentiate between authorization holds (reserving credit limit/funds) and capture/settlement (actual money movement).

Hint 2

Use database unique constraints on idempotency keys to handle concurrent duplicate API requests safely.

Hint 3

Implement a double-entry ledger pattern to make money state changes immutable and auditable.

Hint 4

Handle network timeouts with an asynchronous polling or reconciliation daemon rather than assuming failure.