Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 28/ 31
Reliability, Security & Case Studies

Security, Auth & Payment Systems

Design stateless/revokable auth, protect sensitive data, and guarantee exact double-entry financial ledgers.

AdvancedOAuth/JWT · Ledger · Idempotency3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
OAuth 2.0, JWTs & Revocable Sessions

Handle authentication, token expiry, refresh rotation, and instant logout safely.

Intermediate
Idempotent Payments & Double-Entry Ledgers

Prevent double charges, race conditions, and silent drift in financial systems.

Advanced

In plain words

Authentication checks who you are, authorization checks what you’re allowed to do, and payment systems must never charge you twice or lose money.

Think of it like…

JWTs are stamped event wristbands (fast check at the door without calling HQ); a double-entry ledger is a bound ink accounting book where you never erase an error - you write an offsetting adjustment entry.

Where you’ve seen it

"Log in with Google" uses OAuth. When you pay, an idempotency key makes sure a double-click doesn’t charge your card twice.

Words you’ll hear

Authentication
Proving identity (password, OTP, passkey).
Authorization
Deciding what an authenticated user may access.
JWT
A signed token carrying user info that servers can verify.
Idempotency key
A unique ID per payment attempt so retries don’t double-charge.

Visual diagram

Loading interactive diagram
Loading interactive exercise

Theory & deep dive

Double-Entry Bookkeeping: Never just `UPDATE balance = balance - 50`

If you only store a single balance integer and overwrite it, you have zero audit trail when a bug or dispute happens. Banks and fintechs use an append-only double-entry ledger: every movement creates two balanced rows (Buyer -$50 and Merchant +$50) so the sum of every transaction is always 0.

Key takeaway: Never overwrite money rows; append immutable double-entry ledger records and reconcile with your payment gateway.

How it works, step by step

Step 1 of 4
Auth Layer

1. Authenticate cleanly (JWT + Refresh Tokens)

Issue short-lived signed JWT access tokens (5–15 min) verified statelessly at the gateway, paired with revokable opaque refresh tokens stored in DB/Redis.

Short access TTL + revokable refresh token solves JWT logout
Key numbers at this step
Access JWT TTL
5–15 min
Signing
RS256 / EdDSA

When to use it & trade-offs

What it is

Security & Payment architecture covers authentication/authorization (OAuth 2.0, JWT, RBAC), encryption & secrets hygiene, and immutable double-entry ledgers with idempotent payment state machines.

Why it matters: A bug in caching or feeds is annoying; a bug in auth leaks private data, and a floating-point or non-idempotent payment bug literally loses money.

When to reach for it

  • Short-lived JWT access tokens + rotating refresh tokens (or Redis session IDs for high-security banking)
  • Append-only double-entry ledger in ACID PostgreSQL for any wallet, checkout, or payout system
  • KMS/Secrets Manager + TLS 1.3 everywhere + zero secrets in logs or URLs

When to avoid or be careful

  • Using IEEE-754 float/double for currency amounts (0.1 + 0.2 !== 0.3)
  • Granting 30-day JWTs with no revocation mechanism

Auth & Financial Design Choices

Opaque Session ID (Redis) vs. JWT
Best for: Instant server-side revocation (Session) vs. stateless microservice auth (JWT)

Strengths: Sessions revoke in 1 delete; JWTs validate signature with zero DB lookup.

Watch out: Long-lived JWTs cannot be revoked instantly without a Redis denylist.

Double-Entry Ledger vs. Single Balance Column
Best for: Wallets, marketplaces, Stripe-like processors, escrow

Strengths: Every dollar has a traceable source and destination; prevents negative drift.

Watch out: Requires periodic balance snapshots / materialized totals for fast reads.

RBAC vs. ReBAC (Zanzibar)
Best for: Admin roles (RBAC) vs. Google Drive / Docs per-folder sharing (ReBAC)

Strengths: RBAC is simple; ReBAC scales to billions of fine-grained resource ACLs.

Watch out: ReBAC requires graph indexing and careful permission caching.

Interview signals & numbers to know

When this topic comes up

  • payment processor
  • wallet / ledger
  • OAuth / RBAC
  • double spend
  • PCI compliance

Benchmarks & rules of thumb

Access JWT TTL -
5–15 minutes
Currency unit -
Integer cents / minor units
Password hash -
Argon2id / bcrypt
Reconciliation cadence -
Hourly / Daily vs PSP

Common mistakes & follow-ups

Common interview mistakes

  • Doing SELECT balance then UPDATE balance = balance - 10 without row locking (FOR UPDATE) or atomic conditional update (allows race-condition overdraft!)
  • Using FLOAT or DOUBLE for money instead of integer minor units (BIGINT)
  • Trusting incoming webhook JSON without verifying the provider’s cryptographic HMAC signature

Likely interviewer follow-ups

  • How do you prevent a user with $10 from spending $20 by sending two concurrent withdrawal requests?
  • If JWTs are stateless, how do you force-log-out a compromised user immediately?
  • Why is a reconciliation pipeline still required even if your ledger uses ACID transactions?
Interview tip: For any fintech/marketplace prompt, hit four keywords: Integer cents, Double-entry ledger, Idempotency keys, and PSP reconciliation.

Knowledge check

Loading quiz

Put it into practice

Design full architectures with AI feedback

Apply Security, Auth & Payment Systems inside real High-Level Design prompts or review Q&A flashcards.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Observability, Logging & Tracing
Next topic
Geo-Spatial & Location Systems