Real-Time BNPL Approval Service: Latency, Concurrency, and PII Vault
System DesignModel answerLast updated
Design a buy-now-pay-later checkout backend that decides approval in real time, protects a shared credit line under concurrency, and isolates sensitive shopper data.
Build the backend of a buy-now-pay-later (BNPL) platform. A shopper who already has an approved revolving credit limit selects installments at a partner merchant's checkout. Your system must immediately approve or decline the purchase, and once approved, create an installment schedule whose future charges are collected from the shopper's saved payment instrument.
The interviewer wants a first-pass architecture and data model, then depth on three areas: the latency budget for the approval decision, correct handling of two concurrent purchases competing for the same remaining credit, and storage of sensitive personal and financial data.
Before designing, clarify:
- Which capabilities are in scope beyond the approval decision: installment scheduling, late fees, merchant settlement, disputes, refunds?
- Expected daily purchase volume and peak-event characteristics (for example, a holiday sale where traffic multiplies several times)?
- Which sensitive fields must be persisted: government ID numbers, income, bank account or card numbers, address, contact details?
- Which regions and lending regulations apply, and do they constrain where data may be stored or processed?
Part 1 — Architecture and data model: name the main components, design the core entities, and trace the flow from the shopper clicking "Pay in 4" through creation of the first future installment charge. State precisely what changes on the account at approval time versus what changes only when money is later collected.
Part 2 — Decision latency: merchants generally need a decision in well under a second. Determine what must run synchronously, what can be deferred to background processing, and how you would defend a concrete budget such as p99 under 400 ms.
Part 3 — Concurrent purchases: one shopper completes two purchases in separate tabs within the same second, and the two amounts together exceed the remaining credit. Explain exactly what prevents both from being approved.
Part 4 — Sensitive data storage: design storage so that compromising any single service does not yield usable personal or financial data, while underwriting, billing, and support workflows that legitimately need those values still function without unacceptable latency.
Your answer should call out trade-offs, capacity assumptions, failure behavior, and common implementation mistakes.
Hints
Hint 1
Separate the credit-commitment event at approval from the cash-collection event at each installment due date; only the first one changes available credit.
Hint 2
Reserve credit with a single atomic conditional update (or compare-and-swap) in the system of record instead of a read-then-write check.
Hint 3
Keep raw PII behind a dedicated vault with envelope encryption and opaque tokens elsewhere; the checkout hot path should never need raw sensitive values.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Part 1 — Architecture, data model, and end-to-end flow
Assume roughly 1–5 million purchase attempts per day with a peak-to-average ratio of 5–10x during promotions, a checkout-decision target of p99 under 400 ms, and a hard SLA of about 1–2 seconds for the merchant-facing response.
Core components:
- Merchant-facing API / checkout service — authenticates the merchant, validates the request, and calls the decision service.
- Decision service — evaluates eligibility and fraud rules, then reserves credit.
- Credit service — the system of record for limits and available balances; owns the atomic reservation operation.
- Plan service — creates the installment schedule for approved purchases.
- Billing / collections service — a scheduler that charges installments on due dates, retries failures, and runs dunning.
- Vault service — stores encrypted sensitive values and issues scoped, short-lived access.
- Event bus + outbox — carries purchase, plan, charge, and settlement events to notifications, analytics, reconciliation, and merchant webhooks.
- Merchant settlement service — reconciles funded installments with partner merchants, out of scope for detail but modeled as an async consumer.
Key entities:
shopper(id, kyc_status, risk_ref)
credit_line(shopper_id, limit, available, version)
purchase(id, shopper_id, merchant_id, amount, status, created_at)
installment_plan(id, purchase_id, count, amount_per_installment)
installment(id, plan_id, due_date, amount, status, charged_at)
payment_instrument_ref(shopper_id, vault_token)
vault_record(token, encrypted_payload, key_id)
Trace of the flow:
- The shopper's browser calls the merchant, which sends an authorization request containing the shopper token, order amount, merchant ID, and a payment-instrument token.
- The checkout service verifies the request and asks the decision service for a decision.
- The decision service reads the credit line, checks standing (account not delinquent, KYC valid), applies cached fraud/risk rules, and attempts to reserve credit atomically.
- On success it returns "approved" with the plan shape, writes the
purchaserow asapproved, and creates the plan and installment rows — ideally via a transactional outbox so downstream consumers learn about the approval reliably. - Confirmation emails, analytics enrichment, merchant webhooks, and full risk-model rescoring are queued asynchronously.
- On each due date, the billing scheduler charges the payment instrument referenced by the plan. Success marks the installment
collectedand publishes an event; failure triggers retry with backoff, then dunning, late fees, and potentially a credit-review flag.
The single most important distinction: approval immediately reduces available by the full purchase amount and creates a hard obligation. Collection later moves money but does not release or further change available credit, because the credit was already committed at approval. Failure to collect one installment affects future approvals (for example, the line may be suspended) but does not reduce the already-reserved amount again. A refund or cancellation is the explicit exception: it returns credit via a compensating transaction, recorded as its own auditable event.
Part 2 — Latency budget
The synchronous path should be minimal. Proposed budget for p99 under 400 ms:
| Stage | p99 budget |
|---|---|
| Network + merchant gateway TLS termination | 40 ms |
| Request validation, token check, idempotency lookup | 20 ms |
| Credit-line read (local read replica or in-process cache) | 15 ms |
| Cached fraud/risk feature fetch | 30 ms |
| Rule evaluation (in-process, deterministic) | 10 ms |
| Atomic credit reservation commit + purchase write | 60 ms |
| Response serialization and margin | 40 ms |
| Total (target) | ~215 ms |
| Contingency for GC, retries, tail latency | 185 ms |
What must be synchronous: verifying the request is well-formed and idempotent, confirming the account is in good standing, checking available credit, evaluating fraud rules, and durably committing the reservation. If the reservation cannot be committed, there is no approval — anything less than a durable commit is unacceptable because it would allow double-spend.
What moves off the hot path: confirmation SMS/email, enriching analytics, refreshing a heavyweight risk model (train or score in batch, then push updated features into a fast store), merchant webhooks, receipt generation, and settlement reconciliation.
Design choices that matter: co-locate the decision service with the credit store's region; keep the credit line and risk features in a low-latency cache or read replica, but never trust a cached balance for the reservation — perform the authoritative conditional update on the primary; set tight per-dependency timeouts (for example, 60–80 ms for the feature store) with a conservative default-decline rather than an unbounded wait; use a circuit breaker on degraded dependencies; and make the whole decision path idempotent using a merchant-scoped idempotency key so a timeout-and-retry cannot create two purchases.
Capacity math: at 20,000 peak decision requests per second with 250 ms average service time, roughly 5,000 concurrent in-flight requests, so the decision tier needs on the order of 5,000–8,000 vCPU-equivalents plus headroom, and the credit store must sustain ~20,000 write transactions per second — a write-heavy workload that typically demands partitioning by shopper_id (or by hash of it) so a single shopper's transactions serialize on one shard while the fleet scales horizontally. Load-test the actual promotion curve; a p50 under 100 ms is easy and says nothing about p99 under 400 ms.
Part 3 — Two purchases, one credit line
The reservation is a single atomic conditional statement, executed on the system of record:
UPDATE credit_line
SET available = available - :amount,
version = version + 1
WHERE shopper_id = :id
AND available >= :amount;
Exactly one row must be affected; zero rows means the shopper lacks sufficient remaining credit or the line is not in a reservable state.
If the shopper has 100 available and both purchases are 70: both requests may read available = 100 concurrently, but the database serializes the updates on the row. The first commits and leaves 30. The second's predicate available >= 70 is now false, it affects zero rows, and the service declines it for insufficient credit. The read-then-write alternative — read 100, then write 30 — is the classic bug: both writers compute 30 and the line is overcommitted by 40. The equivalent optimistic scheme is a compare-and-swap on version with the caller retrying from a fresh read.
Partitioning by shopper ID makes this especially clean: because both requests hash to the same partition, they are naturally ordered. No distributed lock service is required; the transaction manager already provides the necessary mutual exclusion. Add a small retry for benign serialization conflicts (for example, 2–3 retries with jitter), but never retry a zero-row result — that is a genuine decline.
Part 4 — Sensitive shopper data
Use a dedicated vault service as the only place raw PII exists. It stores values encrypted with envelope encryption: a fresh per-record data-encryption key encrypts the payload, and that data key is itself wrapped by a KMS-managed master key. The vault records key_id alongside ciphertext so keys can be rotated without rewriting the corpus. Database-level encryption and a separate VPC/account boundary are additional layers, not substitutes.
Every other service stores only an opaque vault_token — a random, non-guessable identifier with no embedded meaning. Underwriting calls the vault's API for a specific field when it truly needs it; billing requests the payment credential only at charge time; support tooling accesses PII through a privileged, audited, just-in-time workflow rather than reading a shared database. Each access is logged with the requesting service identity, purpose, and field, and rate-limited per service.
The property this buys: compromising the checkout service, the analytics warehouse, or the support console yields only tokens, which are useless without the vault's access path. The blast radius of one compromised service is limited to whatever that service was authorized to fetch recently, rather than the entire customer database. Deny-by-default service-to-service authorization, mTLS, short-lived workload identities, and a separate break-glass path for incident response complete the picture.
The cost is an extra network hop and vault QPS, so keep it out of the checkout hot path entirely: the decision path needs the credit line, standing flags, and cached risk features — never raw ID numbers or bank details. Size the vault for bursty read patterns with a warm cache of decrypted-to-service-memory values only where policy allows, and never cache raw PANs beyond the scope of a charge. For PCI-scoped data, add tokenization so the vault holds a payment token rather than a raw card number whenever the processor supports it.
Common mistakes to avoid: encrypting in the application but shipping the key to every service; storing raw PII in a shared analytics store; logging full payloads; giving support staff standing read access; using a sequential or guessable token; and treating "encrypted at rest" as sufficient isolation if every service can decrypt.