How would you design an in-memory order book for a high-frequency trading platform handling 50,000 orders/sec?
Write your answer first
Saved on this device only — nothing is uploaded.
Reveal model answer & level guide
For a high-frequency trading engine processing 50,000 orders/sec, latency must stay sub-millisecond. I maintain price levels in an indexed B-tree or red-black tree (sorted by price) combined with doubly-linked lists at each price tier for strict Price-Time priority (FIFO execution). Fast lookup for order cancellation or amendment uses an in-memory hash table mapping OrderID to node pointers in O(1). All allocations are pre-allocated in ring buffers to eliminate dynamic memory allocation in the critical execution path.
- Entry
- Describes basic bid/ask queues and sorting by price.
- Mid
- Combines tree maps for prices with linked lists for time priority and O(1) hash lookups.
- Senior
- Eliminates GC/allocation pauses with off-heap ring buffers, cache-line alignment, and lock-free concurrency.