Logo

Coding preview

Thread-Safe Order Book Snapshot

What this preview is

About this preview

Thread-Safe Order Book Snapshot is a medium quant coding problem on concurrency in Python, asked at Quant.

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.

Building a thread-safe order book snapshot

This medium-difficulty concurrency problem tests whether you can design a data structure that allows high-frequency mutations (adding and canceling orders) while guaranteeing consistent snapshots. It's representative of the kind of lock-and-state-management challenges that arise in real trading systems.

The core tension: mutating threads need to run concurrently for throughput, but a snapshot reader must see an atomic view with no torn reads or partial updates. The solution hinges on choosing the right synchronization primitive and understanding when to hold versus release locks. You'll need to manage order storage efficiently, track unique IDs, and maintain sorted output on read without blocking writers unnecessarily.

  • Reader-writer lock patterns and their trade-offs
  • Atomic counter generation for order IDs
  • Data structure choice for fast insertion, deletion, and sorted retrieval
  • Lock scoping and avoiding deadlock