Problem
Design the core payment gateway that processes card and UPI transactions for Razorpay merchants.
Requirements
Functional:
- Merchant initiates payment → user pays → confirmation webhook sent to merchant
- Support retries without double-charging
- Support payment status polling
- Refund initiation
Non-functional:
- 100K transactions/minute at peak
- Exactly-once processing (idempotency)
- < 2s end-to-end p99
- 99.99% uptime
Critical discussion topics
- Idempotency key design and storage
- State machine for payment lifecycle (created → processing → success/failed/refunded)
- Outbox pattern for reliable webhook delivery
- Handling bank timeout vs bank failure (different retry strategies)
- PCI-DSS compliance implications on your architecture