Part 8 of 8 · 2 min read
Exercises
Easy
Easy 1: Rate (20 minutes)
5 million transactions a day. Give the average per second, and the peak if it is 10 times the average.
Done when: you write about 58 per second and about 579 at peak.
Hint
5,000,000 / 86,400.
Easy 2: Backoff (20 minutes)
Waits double from 1 second. List the waits for 6 retries and the total.
Done when: you write 1, 2, 4, 8, 16, 32 and a total of 63 seconds.
Hint
Each wait is double the one before.
Easy 3: Double entry (20 minutes)
A $50 sale has a $5 fee. Write the entries and show that they sum to zero.
Done when: you write debit buyer 50, credit seller 45, credit fee 5, and 50 − 45 − 5 = 0.
Hint
Debits equal credits.
Medium
Medium 1: Duplicate requests (30 minutes)
Three requests with key K-9 arrive. The first and second are 2 seconds apart, and the third arrives while the first is still running. What happens to each?
Done when: you write: the first runs, the second returns the saved result, and the third is refused as a concurrent duplicate, giving 1 charge.
Hint
Only one request may charge.
Medium 2: Find mismatches (30 minutes)
PSP file: P1 $10, P2 $20, P3 $15, P4 $30. Ledger: P1 $10, P2 $20, P4 $35. List the mismatches and the kind of fix.
Done when: you write P3 missing in the ledger, P4 amount wrong by $5, and a queue for each.
Hint
Compare each id and amount.
Medium 3: Crash recovery (30 minutes)
The service crashes after the PSP charged the card but before it saved SUCCESS. What does it do on restart?
Done when: you write: find orders in EXECUTING, ask the PSP using the token, and set the status from the answer, with no new charge.
Hint
The PSP knows the true state.
Hard
Hard 1: Draw the hosted page flow (60 minutes)
Draw the six steps of the hosted page with the client, payment service, PSP and database. Mark where the nonce and token are stored.
Done when: a diagram with numbered steps and a note on redirect versus webhook.
Hint
The token is saved before the hosted page is shown.
Hard 2: State machine (60 minutes)
Write the states of a payment order, the allowed moves, and which events cause them, including pending, retry and refund.
Done when: a table of states and moves, and no way to go from SUCCESS back to NOT_STARTED.
Hint
Money moves forward only, and corrections are new entries.
Hard 3: Mock interview (60 minutes)
Answer "design a payment system" aloud in 35 minutes and mark yourself on the four steps. List two missed topics.
Done when: a recording, a score on each step, and two named gaps.
Hint
Use the four-step framework as a checklist.