Design A Limit Order Book With Price-Time Priority Matching

Last updated: November 29, 2026

Quick Overview

Implement a single-symbol limit order book supporting add(order_id, side, price, qty), which matches against resting orders at price-time priority and returns the fills, and cancel(order_id).

Point72
Coding & Algorithms
Software Engineer
Point72
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement a single-symbol limit order book supporting add(order_id, side, price, qty), which matches against resting orders at price-time priority and returns the fills, and cancel(order_id).

Matching logic is core knowledge for engineers building execution and simulation systems at Point72, and many backtesters embed a book like this. The onsite interviewer wants correct priority rules, efficient best-price access, O(1) cancels via lazy deletion, and careful partial-fill bookkeeping.

What the Interviewer Expects
  • Keep price levels per side with FIFO queues for time priority
  • Use heaps (or a sorted map) to reach the best bid and ask quickly
  • Match an incoming order while it crosses, filling at the resting order's price
  • Support partial fills and leave the remainder resting
  • Cancel in O(1) by marking and lazily skipping
  • Discuss complexity and what a production book would change
Key Topics to Cover
data structure design
heaps
FIFO queues
lazy deletion
matching engine
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add market orders and immediate-or-cancel orders?
  • How would you publish top-of-book and depth snapshots efficiently after each event?
  • Why do production engines often use arrays indexed by tick instead of heaps?
  • How would you make this deterministic for replaying a day of exchange messages?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Limit orders only, single symbol, integer prices in ticks. An incoming buy matches resting sells priced at or below its limit, best price first, and within a price, earliest first; sells mirror this. ...

High-Level Design

Per side, a dictionary from price to a FIFO deque of order ids gives time priority, and a heap of prices gives the best level (bids stored negated). An order table maps id to side, price and remaining...


Submit Your Answer
Markdown supported

Related Questions