Building an order book processor with out-of-order event handling
This easy Python coding problem tests your ability to design a system that processes market data streams in the correct sequence, even when messages arrive out of order. It's representative of work quant trading firms do to maintain accurate, real-time order books from exchange feeds.
The core challenge is managing state across four event types (ADD, CHANGE, DELETE, DISCONNECT) while respecting sequence numbers rather than arrival order. You'll need to buffer out-of-order events, handle connection resets that require snapshot reconstruction, and apply subsequent updates correctly. The problem rewards clean separation of concerns: buffering logic, event application logic, and book state management.
- Out-of-order message queuing and sequencing
- Mutable data structures (bid/ask dictionaries) and their efficient update
- State machine transitions (connected vs. disconnected)
- Handling snapshot recovery and event replay after disconnect