Design Payment Processing System

Payment processing platform inspired by Stripe-style payment processors: payment intents with idempotency keys, a card vault that limits PCI scope, a double-entry ledger, signed webhooks, settlement reconciliation, chargebacks and processor failover. A teaching design.

Functional requirements

  • Authorize, capture, void, refund, and settle payments.
  • Idempotent APIs for all payment mutations with client-provided keys.
  • Multi-provider gateway with failover and per-provider routing.
  • Risk checks before authorization; velocity and device rules.
  • 3DS/SCA flows with challenge and fallback handling.
  • Provider webhooks ingestion with verification and retries.
  • Immutable double-entry ledger for balances and audit.
  • Reconciliation jobs against provider statements; chargeback handling.

Non-functional requirements

  • Availability: 99.95%+; no single-AZ failure should halt charges.
  • Performance: checkout auth p95 < 300 ms; capture enqueue < 50 ms; webhook ack < 200 ms.
  • Consistency: strong for ledger and idempotency; eventual for analytics.
  • Security: PCI isolation for payment service; tokens in KMS; HMAC-verified webhooks.
  • Durability: immutable audit logs and ledger with backups and point-in-time recovery.
  • Resilience: timeouts, circuit breakers, retries/backoff, DLQs; provider failover.
  • Observability: metrics/logs/traces for auth success, latency, retries, DLQ depth, and ledger drift.
  • Compliance: audit trails for every state transition with user/actor attribution.

How the design evolves

Stage 1: Charge While the Merchant Waits

See how timeouts and retries turn into double charges.

What was missing: Nothing yet.

Why that's risky: If the response times out, the merchant retries and the customer is charged twice; a crash between charging and recording loses track of money.

What gets added: One server that charges the card through the processor and then records the payment.

Trade-offs: Simple, but money movement has no safety net.

Stage 2: Payment Intents with Idempotency Keys

Make every retry safe and every payment's state explicit.

What was missing: Retries charged twice and payments had no explicit state.

Why that's risky: Raw card numbers pass through every API server, putting the whole system in PCI scope.

What gets added: A payments API built around payment intents that move through explicit states (created, authorized, captured, refunded), with an idempotency key stored in the same transaction as the intent so a retry returns the original result.

Trade-offs: Authorizing and capturing separately (capture later, on shipping) adds a step but lets merchants cancel without refunds.

Stage 3: Card Vault and Tokenization

Shrink PCI scope to one small service.

What was missing: Card numbers flowed through every API server.

Why that's risky: Money movement isn't recorded as a balanced ledger, so balances and fees can't be proven correct.

What gets added: A card vault that swaps card numbers for tokens and is the only component that decrypts them (with keys from a key management service) to send them to the processor.

Trade-offs: An extra hop to the vault per charge, in exchange for most of the system never touching card data.

Stage 4: Double-Entry Ledger

Record every movement of money so that it always balances.

What was missing: No ledger: balances were computed from payment rows.

Why that's risky: Merchants aren't told when payments succeed or get disputed, and nothing checks our records against the processor's.

What gets added: A double-entry ledger where every authorization, capture, refund and fee posts balanced debit and credit entries; merchant balances are sums of entries.

Trade-offs: Ledger entries are append-only; mistakes are fixed with reversing entries, never edits.

Stage 5: Webhooks, Settlement and Chargebacks

Tell merchants what happened, reconcile with the processor, and handle disputes.

What was missing: No webhooks, no reconciliation, no dispute handling.

Why that's risky: One processor outage stops all charging, and merchants' dashboards load the primary database.

What gets added: A payment event stream feeding a webhook sender (signed events, retried for days), a settlement and reconciliation worker that matches the processor's daily files to the ledger, and a chargeback handler that posts reversals and asks merchants for evidence.

Trade-offs: Webhooks are at-least-once, so merchants must deduplicate by event id.

Stage 6: Backup Processor, Read Replica, Limits and Monitoring

Keep accepting payments through a processor outage, and protect and watch the platform.

What was missing: A single processor, dashboards on the primary, no merchant limits, no monitoring.

Why that's risky: Remaining risk is regional: the payments DB and ledger need synchronous replication to a second zone.

What gets added: Routing to a backup processor when the primary fails or declines abnormally, a read replica for dashboards and reports, rate limits per merchant key, and monitoring of authorization rate, processor errors, webhook backlog and reconciliation mismatches.

Trade-offs: Retrying a decline on another processor is only safe for technical failures, never for real card declines.

Frequently asked questions

How do you guarantee idempotency for all mutations?

Require client-supplied idempotency keys and store them with final outcomes. For async steps, use outbox tables and idempotent workers keyed by (intent_id, step). Expire keys conservatively and reject conflicting replays.

How do you do multi-provider failover safely?

Route through a provider gateway with health-checked providers and circuit breakers. Persist provider-of-record with each charge, and reconcile later if a failover provider captured the payment to avoid duplicates.

Ledger correctness: why double-entry?

Double-entry ensures every debit has a credit, enabling invariant checks. Postings are immutable and append-only; balances derive from sums. Corrections are new reversing entries, never mutations.

What goes into observability for payments?

Track auth/capture/refund success rates, tail latencies, queue depths, retry counts, provider error taxonomy, and ledger drift. Create SLOs with burn-rate alerts on user-facing metrics.

How do you structure refunds and chargebacks?

Model refunds as new negative postings tied to the original charge. Chargebacks create dispute holds and postings; evidence workflows run via background workers with strict idempotency and audit logs.

PRISM
System Design Interview
Round 1 of 4 · Architecture Design · 60:00 remaining
PRISM logo PRISM logo
Problems
AI Interview
Interview Challenges
Build & Stress Test NEW
System Architectures
Design & Fix NEW
Interactive Roadmap
System Design Guides Interview Prep Guide
Problems
Today's mission
Notifications
    Theme
    Pricing Community NEW Send feedback Report a problem NEW
    Sign in
    Theme
    Community NEW Send feedback Report a problem NEW
    All problems
    Phase
    Build & Stress Test
    Phase 01: Thinking in Systems
    Upcoming

    Components

    User
    CDN
    Load Balancer
    Server
    Cache
    Database
    Blob Storage
    Search Index
    Queue
    Worker
    Rate Limiter
    Service
    API Gateway
    Reverse Proxy
    WebSocket Server
    Third-party API

    Inspector

    Notes
    Use clear names so your design intent is easy to understand.
    Good
    Name by business meaning
    "Order API", "Restaurant Service"
    Avoid
    Generic names = zero signal
    "Server 1", "API", "Queue"
    A short description for each component makes feedback much better.
    100%
    Start by identifying:
    • Users & entry points
    • APIs & services
    • Databases & storage
    • Traffic flow & scale

    Round 1 of 4 Architecture Design

    Run a simulation to see results.

    Time Remaining
    60:00
    System Design Interview

    What are the core functional requirements?
    What are the key non-functional constraints?

    Questions

    Start Evaluation to unlock questions.

    EVALUATE MODE

    Test yourself like it's the real thing.

    A structured 4-module evaluation that mirrors how top companies assess system design candidates.

    Architecture Design
    Draw your system on the canvas. Define components, connections, and data flow.
    FR & NFR Requirements
    Answer functional and non-functional requirement questions about your design.
    MCQ Round
    Multiple choice questions testing your depth on the chosen system.
    Tradeoff Analysis
    Justify your design decisions and defend your architectural tradeoffs.
    AI Report Generated
    Choose a Problem
    No problem selected
    • 30 min
    • 45 min
    • 60 min
    Round 2 of 4
    MCQ Round
    Answer multiple-choice questions based on your design.

    Exit Interview?

    You're in the middle of an interview session. Leaving now will end your current attempt.

    Your progress will be saved.

    Open a saved design

    Select a design to load into the canvas.

    My Evaluations

    Your past evaluation sessions

    Here’s a simple request flow that follows the expected layer order.

    External User
    →
    Edge CDN → API Gateway → Load Balancer
    →
    Compute App Servers / Services
    →
    DataAccess Cache
    →
    Storage Database / Search Index
    →
    Async Queue → Worker

    Tip: keep arrows moving forward through layers (Edge → Compute → Storage). Avoid sending storage back to compute.

    Evaluation Instructions

    Read the rules carefully before starting. The test auto-submits on refresh.

    Before you start

    • Build your architecture on the canvas. The timer starts when you click Start Evaluation.
    • Don't forget to answer Functional Requirement and Non Functional Requirements.
    • When satisfied with your design, click Next to lock it and view the questions.
    • Please answer final step questions to complete the evaluation.

    Dos

    • Do read each question carefully before answering.
    • Do include required components to maximize component coverage.
    • Do save a copy of your design if you want to keep it before submission.

    Don'ts

    • Don't refresh or close the tab during an active evaluation — this will auto-submit your answers.
    • Don't switch app modes or open another tab while the evaluation is running.
    • Don't attempt to edit the design after clicking Next; the workspace will be locked.

    All the best!!

    Confirm

    Input

    Notice

    Evaluation Report
    Report a problem

    Evaluation Complete

    Generating Your Report

    Hang tight — our AI is evaluating your design…

    Did you know?

    Loading…

    Share feedback

    Tell us what worked well and what we can improve.

    Let's personalize this

    Answer a couple of quick questions so we can tailor your journey and missions.

    Your welcome gift: of Full PRISM Access

    Your Pro access starts as soon as you press Start my journey.

    SYSTEM BRIEF

    System Constraints

    What the system must do — every item is a user-facing behaviour your architecture must support.

      ↑ Engineering Constraints

      These are the failure modes you must design against — latency SLAs, durability targets, traffic ceilings.

        ⇆ Architecture Constraints

        Core Concepts to Master

        Your Journey
        PHASE – –
        0 / 0 0%
        0
        Mock Interview Checklist

        Pick a topic to start

        Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.

        Phase Mastered

        You've conquered this phase. These are the skills you now own:

          +500 XP

          Company Interview Paths

          Progress Summary