PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/Akuna Capital

Design an order-matching engine

Last updated: May 15, 2026

Quick Overview

This question evaluates a candidate's ability to design a high-throughput, low-latency in-memory limit order-matching engine, testing competencies in data structure selection, algorithmic complexity, deterministic concurrency, API design, and handling domain-specific constraints such as self-trade prevention.

  • hard
  • Akuna Capital
  • System Design
  • Software Engineer

Design an order-matching engine

Company: Akuna Capital

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

Design and implement an in-memory order-matching engine for a limit order book. Requirements: - Operations: - placeOrder(orderId, side, price, quantity, type) where side ∈ {BUY, SELL} and type ∈ {LIMIT, MARKET} - cancelOrder(orderId) - topOfBook(): return best bid and best ask (price, totalQuantity) - depth(k): return top k price levels on each side - Matching rules: price–time priority; match immediately on arrival; allow partial fills; leave remainders on the book; market orders sweep the book until filled or empty; prevent self-trade. - Performance targets: support up to 1e6 live orders and ~1e5 ops/sec; aim for O(log P) insert/cancel and O( 1) top-of-book; avoid linear scans over orders. - Concurrency: single-threaded matcher is acceptable; describe how you would extend to multi-threading without breaking determinism. Deliverables: specify data structures (e.g., price-indexed maps with FIFO queues), implement core APIs, analyze time/space complexity, and explain strategies to prevent timeouts on adversarial inputs.

Quick Answer: This question evaluates a candidate's ability to design a high-throughput, low-latency in-memory limit order-matching engine, testing competencies in data structure selection, algorithmic complexity, deterministic concurrency, API design, and handling domain-specific constraints such as self-trade prevention.

Related Interview Questions

  • Implement a two-user communications handler - Akuna Capital (medium)
  • Design communication handler and exceptions - Akuna Capital (medium)
  • Fix and harden an object pool - Akuna Capital (hard)
  • Design user communication functions - Akuna Capital (easy)
  • Design user communication manager APIs - Akuna Capital (medium)
Akuna Capital logo
Akuna Capital
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
System Design
27
0

In-Memory Limit Order-Matching Engine (Limit Order Book)

Context

You are asked to design and implement an in-memory, single-instrument limit order book that supports live order matching at scale. Orders match on arrival using price–time priority, with support for partial fills, market orders, and cancellations. The system should be efficient enough to handle up to 1e6 live resting orders and ~1e5 operations per second.

To support self-trade prevention deterministically, assume each order includes a traderId (accountId). If traderId is omitted in your chosen interface, briefly justify an alternative.

Requirements

  • Core APIs
    1. placeOrder(orderId, traderId, side, price, quantity, type)
      • side ∈ {BUY, SELL}
      • type ∈ {LIMIT, MARKET}
      • price is ignored for MARKET orders
    2. cancelOrder(orderId)
    3. topOfBook(): return best bid and best ask as (price, totalQuantity)
    4. depth(k): return top k price levels on each side as lists of (price, totalQuantity), best-first
  • Matching Rules
    • Price–time priority within each price level (FIFO by arrival).
    • Match aggressively upon arrival; allow partial fills.
    • Unfilled remainder of a LIMIT order rests on the book; MARKET orders never rest.
    • MARKET orders sweep price levels until filled or the book is empty.
    • Prevent self-trade: the incoming order must not trade against resting orders from the same traderId. Define a clear policy (e.g., cancel resting, cancel incoming, or decrement incoming).
  • Performance Targets
    • Up to 1e6 live resting orders, ~1e5 ops/sec.
    • Aim for O(log P) insert/cancel where P = number of price levels.
    • O(1) top-of-book read.
    • No linear scans over orders for cancel or best-price lookup.
  • Concurrency
    • Single-threaded matching engine is acceptable.
    • Describe how to extend to multi-threading while preserving determinism.
  • Deliverables
    • Specify data structures (e.g., price-indexed trees with FIFO queues per level).
    • Implement core APIs (clean, production-minded code is a plus).
    • Analyze time/space complexity.
    • Explain strategies to remain robust under adversarial input patterns.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Akuna Capital•More Software Engineer•Akuna Capital Software Engineer•Akuna Capital System Design•Software Engineer System Design
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.