AppliedMultiple choice
Designing an order book · Part 2 of 3
You are writing a limit order book for one instrument. It must add orders, cancel them by order id, and publish the best bid and offer after every event. There are L occupied price levels and N resting orders, and each level keeps its orders in time priority.
A cancel message carries only the order id. Which structure makes the cancel ?
- AA hash map from order id to the order’s node in a doubly linked list at its level
- BScan the queue at each level until the id turns up
- CA vector per level, erasing the order at its stored index, which is cache-friendly and so the fastest choice
- DA second balanced tree keyed by order id
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
More systems and low latency questions
- An array-based book pre-allocates one slot per price tick.Foundation
- You join a price level behind 800 shares.Foundation
- You keep one million live orders in a hash map at 48 bytes an entry.Applied
- A buy order for 500 at a limit of $100.02 meets offers of 200 at $100.00, 100…Applied
- What data structure best supports a limit order book that must add, cancel and…Advanced
- A busy matching engine, part 1 of 3Foundation