I spent the first few minutes just listing APIs without really justifying them, which I think annoyed the interviewer a bit.
Start by clarifying requirements (e.g., asset class, order types, performance needs) and then propose a clean, minimal API that separates concerns between order management and market data queries. Justify each method by its role in the system, and implement using efficient data structures like heaps or balanced trees for price levels, ensuring thread safety and low latency.
Pro tip: Emphasize the importance of defining clear semantics for order cancellation and modification, and discuss how you would handle concurrency and consistency in a high-frequency trading environment.
Ask about expected order types (limit, market), asset class, throughput, latency requirements, and whether the orderbook is for a single symbol or multiple. This ensures the design meets the actual needs.
Propose methods such as placeOrder, cancelOrder, getBestBid, getBestAsk, getDepth, and possibly modifyOrder. Explain the parameters, return types, and error handling for each.
Explain why each method is necessary, how they support typical trading operations, and why certain methods (e.g., order matching) are excluded. Discuss trade-offs between simplicity and functionality.
Describe how to store orders and price levels efficiently, e.g., using a hash map for order lookup and a priority queue or balanced BST for bids/asks. Mention time complexity for key operations.
Write clean, modular code for the core methods, and discuss thread safety (e.g., locks, lock-free structures) and potential optimizations for low-latency scenarios.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.