CSE Roadmap

Common tier · about 5 hours · 8 parts

Part 7 of 8 · 2 min read

Trade-offs

What to say out loud.

Trade-offs and what to say

Choice Gain Cost
Two-phase commit Database enforces atomicity Locks, slow, coordinator risk
TC/C Parallel, database independent Application must write cancel logic
Saga Fits microservices Ordered steps, compensations to write
Event sourcing Audit and replay Learning curve, more storage
Local files Very fast State on each node, needs replication
Raft group Safe log Limited by the leader, more nodes
Sharding Scale Cross-group transfers need a coordinator
Snapshots Fast rebuild Storage and a schedule

Interview angle

Answer in your head first, then open it.

Why not Redis alone?

A transfer needs two writes, and a crash between them loses money.

How do you make a cross-shard transfer atomic?

A saga or TC/C with compensations, and a phase status table for recovery.

Why event sourcing?

Reproducibility: any balance can be rebuilt and checked.

How do you keep the event log safe?

Replicate it with Raft over 3 or 5 nodes.

How do you reach 1 million a second?

Append-only local files, snapshots and many Raft groups.

One follow-up to try. "Add currency conversion." A good reply: a transfer may span two currencies, so an exchange step is added, with a quoted rate that is stored in the event so replays give the same result. Amounts are kept in the smallest unit of each currency, as integers. The audit trail records the rate source and time.

Check yourself: 1. Why store the exchange rate inside the event? 2. Which data is rebuilt, and which is protected? 3. What does the coordinator record while a saga runs?

Words you will meet

Word Meaning
2PC Two-phase commit: prepare, then commit or abort
TC/C Try, confirm or cancel, as application-level steps
Saga A chain of local transactions with compensations
Command A request that may be refused
Event A validated fact, never changed
State machine Code that validates commands and applies events
Snapshot A saved copy of the state at one moment
Raft A consensus algorithm that replicates a log