Part 8 of 8 · 2 min read
Exercises
Easy
Easy 1: Order rate (20 minutes)
600 million orders a day over 6.5 hours. Give the average per second and the peak at 5 times.
Done when: you write about 25,600 and about 128,000 per second.
Hint
600,000,000 / 23,400.
Easy 2: Downtime (20 minutes)
Give the seconds of downtime per day for 99.9, 99.99 and 99.999 per cent.
Done when: you write 86.4, 8.64 and 0.864 seconds.
Hint
0.1, 0.01 and 0.001 per cent of 86,400.
Easy 3: Spread (20 minutes)
Best bid 50.20 and best ask 50.24. Give the spread.
Done when: you write 0.04.
Hint
Ask minus bid.
Medium
Medium 1: Match an order (30 minutes)
Asks: 200 at 10.00 (two orders of 100), 300 at 10.01. A market buy for 350 arrives. Give the fills and the new best ask with its remaining quantity.
Done when: you write 200 at 10.00 and 150 at 10.01, then best ask 10.01 with 150 left.
Hint
The oldest orders at the lowest price fill first.
Medium 2: Latency budget (30 minutes)
Five network hops at 500 microseconds and a 4 ms disk write, versus five mmap hops at 1 microsecond and the disk write moved off the path. Give both totals.
Done when: you write 6.5 ms and 5 microseconds.
Hint
5 × 0.5 ms plus 4 ms.
Medium 3: Raft sizes (30 minutes)
A cluster has 7 servers. Give the majority needed and the number of failures tolerated.
Done when: you write 4 and 3.
Hint
More than half of 7.
Hard
Hard 1: Draw the single-server design (60 minutes)
Draw the one-server layout with the event store, sequencer, gateway, matching engine with order manager, market data publisher and reporter. Number the order flow.
Done when: a diagram with at least 7 parts and a numbered flow.
Hint
The sequencer is the only writer to the event store.
Hard 2: Order book code (60 minutes)
Write the class design of an order book with price levels, a doubly linked list and an order map. Show add, cancel and match with their costs.
Done when: class definitions and three operations with time costs of constant time.
Hint
The map finds an order, the previous pointer unlinks it.
Hard 3: Failover drill (60 minutes)
Write the timeline of a primary failure: detection, election, takeover, and checks. Give the total pause and the data lost.
Done when: a timeline with times in milliseconds, a total, and a statement of zero lost events.
Hint
Heartbeats missed times the interval.