CSE Roadmap

Core tier · about 5 hours · 8 parts

Part 7 of 8 · 2 min read

Trade-offs

What to say.

Trade-offs and what to say

Other topics from the book. Consistency between services: use idempotency and the retry design, with a single database transaction where the data is in one place. A distributed transaction (a saga or two-phase commit, Level 5) can span services, but costs complexity. Security: use HTTPS everywhere, encrypt data, rate-limit and monitor for fraud, and keep card data in the PSP's care.

Choice Gain Cost
Use a PSP No card data, less regulation Fees, a dependency
Hosted payment page Card data never touches you Less control of the look
Relational database ACID, mature tools Harder to scale
Idempotency key Safe retries A key store
Async queues Isolation, scale More states to track
Reconciliation Catches drift Delay, human work
Double entry Provable books More rows

Interview angle

Answer in your head first, then open it.

What is hard here?

Correctness under failure, not volume.

How do you avoid double charging?

An idempotency key, enforced by a unique key, plus a PSP token.

How do you retry?

Exponential backoff with limits, then a dead letter queue.

How do you know the books are right?

A double-entry ledger and nightly reconciliation.

How do you avoid handling card numbers?

A PSP hosted page and tokens.

One follow-up to try. "A buyer says they were charged but the order shows unpaid." A good reply: the status may be pending, or the webhook may have been missed. Look up the payment order by id, ask the PSP for its status using the token, and update the order. If the PSP says paid and the order says unpaid, record a corrected ledger entry and fix the order. Reconciliation would find the same gap the next night, so also check why the webhook failed.

Check yourself: 1. Why is a PSP a trade-off? 2. What is the first thing to check for a "charged but unpaid" report? 3. How do you correct a wrong ledger row?

Words you will meet

Word Meaning
PSP A company that moves money for you
Pay-in and pay-out Money coming in, and money going out to sellers
Ledger A permanent record of money entries
Double entry Each transaction as equal debit and credit
Idempotency key A unique value that marks repeats of one request
Webhook A call from a provider to your system with an update
Reconciliation Comparing records from different systems
Dead letter queue A place for messages that keep failing