Design Juspay's Payment Orchestration Layer Across Multiple Gateways

Problem

Design Juspay's payment orchestration layer — the routing and retry engine that sends payment requests to the optimal gateway and handles failures.

Requirements

Functional:

  • Route payment to best gateway based on: success rate, latency, merchant preference, instrument type
  • Retry on failure: different retry strategies per failure type (timeout vs decline)
  • Support A/B testing of gateway routing rules
  • Provide unified status to merchant regardless of which gateway processed

Non-functional:

  • 500K TPS at peak
  • End-to-end latency < 1.5s (NPCI mandate)
  • Zero fund loss: idempotent retries, no double charge
  • 99.99% availability

Critical discussion points

  1. Idempotency key propagation through retry chains
  2. Gateway health scoring: real-time rolling success rate
  3. Fallback routing: when primary gateway is degraded
  4. Saga pattern for atomic debit + routing + confirmation
  5. Audit log for every routing decision (regulatory requirement)
added …
LeaderboardSalaryAccount