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
- Idempotency key propagation through retry chains
- Gateway health scoring: real-time rolling success rate
- Fallback routing: when primary gateway is degraded
- Saga pattern for atomic debit + routing + confirmation
- Audit log for every routing decision (regulatory requirement)
added …