KatInterview

Secure Embedded Bank-Transfer Checkout Component Design

System DesignModel answer
MediumModel answerSystem Designsystem-designpaymentsiframe-security

Last updated

Design a merchant-embeddable bank-payment checkout component: isolated iframe, safe parent-frame messaging, token exchange, asynchronous settlement, and webhook reliability at high scale.

Problem

Your company runs a payments platform and wants to offer a drop-in bank-transfer checkout component. A merchant adds a small JavaScript SDK to its checkout page. When a shopper picks "pay from my bank", the SDK opens a modal containing an iframe served from your own domain. Inside it, the shopper finds their bank, signs in, and approves a transfer over a rail such as ACH, RTP, or FedNow. The merchant must never see the shopper's bank credentials or account details.

Functional requirements

  • Session creation: the merchant's server creates a single-use, short-lived session token tied to the amount, currency, and merchant identity.
  • Widget lifecycle: the SDK creates an iframe pointing at your hosted domain, sets up a trusted two-way channel with it, and surfaces callbacks such as onSuccess, onExit, and onError.
  • Consent and token exchange: the widget records the shopper's consent, finishes the bank's OAuth (or equivalent) handoff, and yields a short-lived code that the merchant's server exchanges for a payment token (single-use or reusable).
  • Asynchronous settlement: final settlement can take seconds to minutes (RTP, FedNow) or several business days (ACH). Merchants learn about progress via webhooks.

Non-functional and security requirements

  • Bank credentials, account numbers, and internal auth tokens must never reach the merchant's DOM or network logs.
  • Defend against clickjacking, XSS, and origin spoofing in parent-to-iframe messaging.
  • Be safe under retries: dropped connections, interrupted OAuth redirects, double clicks.
  • 99.99% availability; iframe cold load under 500 ms.

Scale

  • Peak 10,000 widget loads per second and 500 completed authorizations per second.
  • More than 5,000 merchants and 100 million linked bank accounts.

What your answer should cover

  1. The end-to-end flow and APIs across merchant server, merchant page, iframe, your backend, and bank APIs.
  2. Browser security: the postMessage handshake, origin checks, CSP, iframe sandboxing, and OAuth redirect strategy.
  3. The data model and state machines for sessions and payments, including failures, returns, and disputes.
  4. Reliability and observability: funnel tracking, PII-free telemetry, and webhook delivery guarantees.

Hints

Hint 1

Size the system first. Widget loads are static and belong on a CDN; the origin mostly sees session lookups. Authorizations (500/s) are modest for the database, and each payment produces several webhook events.

Hint 2

Ask which party you trust at each hop. The merchant page is untrusted, so the amount and payee must be fixed server-side at session creation, and the client-side success event should mean only 'the user consented', not 'money moved'.

Hint 3

Banks often forbid framing and third-party cookies break in-frame sessions, so run bank sign-in in a popup or top-level redirect rather than inside the iframe. Use PKCE and a signed state value, and let the server finish the code exchange.

Hint 4

Model sessions and payments as separate state machines. Payments need states for returns and disputes, and every transition should be an append-only event that also feeds the webhook outbox.