Skip to the page

India-scale design · Design

Design a UPI payments app backend with idempotency

The interviewer asks

Design the backend of a UPI payments app like PhonePe or Google Pay. A user scans a shop's QR code, enters an amount and their PIN, and pays. Money must never move twice.

Then

Follow-ups the interviewer asks next

  1. Who are the parties in one UPI payment, and which part do we own?
  2. Walk me through the happy path and the states a payment moves through.
  3. What's the API, and how does the idempotency key work?
  4. The bank's answer doesn't come back in time, and the user taps Pay again. What happens?
  5. Our server crashed after sending the request to the bank and before saving the answer. How do we find out what happened?
  6. UPI handles about 2,500 crore transactions a month. If we handle a third of them and the peak is 3x the average, how many per second, and where's the bottleneck?
  7. How do you record money movements so they always add up?
  8. NPCI limits how often you can call check-status. How does that change your retry design?
  9. Where must this data be stored, and why?

The answer

What a strong answer covers

  • Parties: the payer's app and its PSP bank, NPCI's UPI switch, and the payee's bank. The app never holds the money. We own the app backend, the PSP integration, our own records and notifications.
  • States: created, pending (sent to the bank), then success, failed or unknown, and later reversed or refunded. States only move forward, stored with a version number.
  • Idempotency: the app creates a key per payment attempt; the server stores (key, request hash, result) under a unique constraint, so a retry gets the stored result and the same key with a different body is rejected. The transaction id sent to the bank is created once and reused on every retry.
  • Unknown outcome: never send a new debit. Mark it pending, call check-status with backoff within the allowed count, reconcile with the bank and NPCI settlement files, and tell the user "payment pending, don't pay again".
  • Ledger: double-entry, append-only journal rows (debits and credits that sum to zero), balances derived from them, and daily reconciliation with bank reports.
  • Numbers: 2,500 crore a month over about 26 lakh seconds is about 9,600 a second for all of UPI; a third is about 3,200, and 3x at peak is about 10,000 a second. The bottleneck is the banks' latency and limits, so the design is async, with timeouts and a circuit breaker per bank.
  • Current rules (as reported): from 16 June 2025 NPCI cut the pay-request response time to 15 seconds and check-status to 10 seconds (from 30); from 1 August 2025 system-initiated calls are limited (for example 50 balance checks a day per app) and status checks are allowed only a few times per transaction.
  • Data: RBI's 2018 rule says payment system data must be stored only in India, so the main and DR regions are both in India (for example Mumbai and Hyderabad).
  • Security: device binding; the PIN is entered only in NPCI's common library and never reaches our servers.

The red pen

Common traps

Avoid:"a distributed transaction across the banks"; retrying a debit with a new transaction id after a timeout; a mutable balance column with no journal; treating a timeout as a failure and asking the user to pay again.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview