Skip to the page

Trade-offs and mobile system design · senior

Mobile system design: a payments flow

A mobile payment flow is a state machine driven by your server: create an order with an idempotency key, hand off to the payment SDK or UPI app, then confirm the final status from your server (never trust the client callback), and resume any pending payment after an app kill.

The notes

What you must know

  • States: idle → creatingOrder → awaitingPsp (UPI app or PSP SDK) → verifying → success | failed | unknown. "Unknown" is a real state when the network times out.
  • Your server creates the order with an idempotency key; the client disables Pay while in flight; a double tap reuses the same order.
  • After the PSP returns, ask your server for the status (poll with backoff, or wait for a server push after the webhook). The PSP's client callback is only a hint.
  • App killed mid-payment: on the next start, read the pending order from storage and verify its status before allowing a new attempt.
  • UPI on Android: an intent to the UPI app and read the result; on iOS: app switching through URL schemes; both still need server verification.
  • Security: PIN entry only inside the PSP/NPCI SDK, FLAG_SECURE, Play Integrity / App Attest for high-value actions, no card data in JS state or logs, amounts as integer paise.
  • Observability: funnel events (Pay tapped → order created → PSP opened → verified) and alerts on success-rate drops by PSP and app version.

The red pen

Common traps: mistake → fix

  • Mistake: Marking success from the client callback.

  • Mistake: Retrying "create order" without an idempotency key

    Fix: double charge.

  • Mistake: Floating-point money.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design the client side of a UPI or checkout flow from "Pay" to the success screen, including failures.
  2. The user taps Pay twice. What happens?
  3. The app is killed after the UPI app returns success but before your server confirms. What then?
  4. Network timeout: did the payment go through?
  5. How do you protect the payment screen?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

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

Start your free interview