InterviewLegend

Design an Exchange Matching Engine

Frequently asked
Alex Chen30 min readGuide updated
In this lesson
  • Build a per-instrument order book and explain the matching loop while you code it
  • Make order ids, cancels and IOC orders behave correctly when a cancel races a fill
  • Scale it out to many instruments and high message rates, then rebuild every book after a crash

Understanding the problem

The prompt

Something like this. Build a small exchange where traders send buy and sell orders for a set of instruments, and it matches them and reports the trades. Talk through your design while you build it, then tell me how it holds up at higher scale.

This is the live, talk-it-through version of the problem Akuna is best known for. The order book take-home is a separate exercise graded by hidden tests, with its own lesson. Here a person sits across from you and wants your reasoning as much as your code. The newest live reports are from mid-2025. In June 2025 a software engineer in Singapore had a final whose second round was building an exchange engine, and a separate panel in the same loop was classic system design. A Singapore write-up from July 2025, possibly the same loop, describes an exchange-engine round the candidate explained while coding. A secondhand listing from September 2025 puts an in-memory, single-instrument limit order book in a technical screen. And a quant developer question list from late 2025 says an exchange matching engine was last asked about a year before that.

Older reports have the same shape. Sydney graduate finals in June 2023 asked candidates to "write an exchange that can handle trades." A Sydney intern final in May 2021 combined retrieving product data from a server with a low-latency "buy low, sell high" system. A Chicago C++ phone screen in November 2018 began small: a buy order class, with the orders sorted by price. Nobody has posted a full spec for the live round. So prepare the core every version shares, then the scale questions. The newest listing, from October 2026, is a 24-hour take-home version, and it names four follow-ups: immediate-or-cancel orders, many instruments, high message rates and rebuilding the book after a crash. The deep dives below take them in turn.

The Akuna Capital angle
Akuna trades derivatives with its own capital, on exchanges it doesn't run. Its engineers build the systems on the other side of those matching engines, so a cancel racing a fill is familiar ground for them. Expect them to check any rule you state casually.

Requirements

Functional requirements

Agree on the surface first, because the round runs on a clock and a feature you didn't need costs you the scale discussion. A trader submits a limit order: an instrument, a side, a price and a quantity. The engine trades it against the other side at the best prices first, and among orders at one price, the oldest goes first. Exchanges call this price-time priority. Whatever doesn't trade rests in the book. The trader can cancel a resting order by its id, and everyone gets told about trades.

In scope

  • Limit orders on many instruments, matched by price-time priority
  • Partial fills, with the remainder resting in the book
  • Cancel by order id, and a clear answer when the order already traded
  • Immediate-or-cancel orders that never rest
  • Trade reports to both sides and a public feed of book changes
  • Rebuilding every book after a crash, losing nothing that was acknowledged

Out of scope for now (say so, then move on)

  • Pre-trade risk checks and margin, beyond a size and price sanity check
  • Opening and closing auctions
  • Clearing and settlement after the trade
  • Login, entitlements and the network protocol details

Non-functional requirements

Correctness comes first, and in an exchange correctness has a strict meaning. Given the same orders in the same sequence, the engine must produce the same trades every time, on any machine. That property is called determinism, and the crash-recovery design leans on it completely. An order the engine has acknowledged must never be lost. Latency comes next, and it's the tail that matters. Traders care about the slow 1 percent of messages as much as the average, because a stall at the wrong moment means trading on stale prices. Inside the engine, aim for a few microseconds per message. A database round trip takes hundreds of microseconds at best, so the books live in memory. Throughput is where the "higher scale" push will come from. Ask for numbers. If none come, propose some and write them down.

  • Instruments: about 10,000. Every option strike and expiry is its own book, so the count climbs fast. Each book is small, and most are quiet most of the day.
  • Peak messages: 1 million a second. New orders, cancels and modifies together. In a market full of quoting firms, cancels and replacements far outnumber trades.
  • Budget on one core: about 1 microsecond. A million messages through a single thread leaves one microsecond each, so the engine gets split by instrument.
  • Journal growth: about 1.5 TB a day. At 64 bytes per message, 1 million a second is 64 MB a second. Over a 6.5-hour session that comes to roughly 1.5 TB.

The object model, in words

Four objects do the work. An order is one instruction to buy or sell. It holds the trader's own id for it, the exchange's id, the instrument, the side, a limit price and the quantity still open, which shrinks as it fills. Prices are whole numbers of ticks, never floats. A tick is the smallest price step the instrument allows, and integer ticks mean two equal prices always compare equal. A price level is every resting order at one price on one side, kept in arrival order. The front of that queue trades first. The level also keeps a running total of its open quantity, so the public feed can publish depth without walking every order. A book belongs to one instrument. It has two sides, bids sorted from the highest price down and asks from the lowest price up, so the best price on each side is always at the front. A trade is one match between the incoming order and one resting order, at the resting order's price. One incoming order can create several trades as it works through the levels.

What the engine keeps in memory
StructureFields
Orderexchange_order_id · client_order_id · instrument · side · price_ticks · open_quantity · sequence_number
Price levelprice_ticks · queue of orders, oldest first · total_open_quantity
Book (one per instrument)bids, best first · asks, best first · map from exchange_order_id to the order
Tradetrade_id · instrument · buy order id · sell order id · price_ticks · quantity · sequence_number
Everything here is derived state. The durable truth is the journal of input commands, and any book can be rebuilt by replaying it.

Time priority needs a tie-breaker that a replay can reproduce. So the engine stamps each accepted order with a sequence_number that only ever goes up. Time priority comes from that number and never from a clock reading. Two orders stamped in the same microsecond still get an unambiguous order, and a replay after a crash gets the same one.

The API

Keep the interface small. Traders send three kinds of command and receive two streams back. A real venue speaks FIX, the standard text protocol for orders, or its own binary format. For the round, plain calls are fine.

The interface
RequestServer pushFire-and-forget
TraderOrder gatewayplace an order
submit(instrument, side, price, quantity, kind, client_order_id)
ack with exchange_order_id, or reject with a reason
kind is a resting limit order or immediate-or-cancel. A repeated client_order_id is rejected.
TraderOrder gatewaypull a resting order
cancel(exchange_order_id)
cancelled with the open quantity, or too late to cancel
TraderOrder gatewaychange price or size
modify(exchange_order_id, price, quantity)
ack, or too late to modify
Treated as cancel plus a new order, so it goes to the back of the queue.
Order gatewayTraderprivate execution reports
fills and cancels for this trader only
order id, fill price, fill quantity, open quantity
Market dataEveryonepublic book changes and trades
feed of level updates, each with a sequence number
instrument, side, price, total quantity at that price
A gap in sequence numbers tells a subscriber it missed a packet and must recover.

The architecture end to end

In the room, build this bottom up. Write the single-book engine first, get the matching loop right and say why each structure is there. Only then draw the boxes around it. The full picture below is where the "higher scale" questions take you. Blue is outside the exchange and violet is a process we run. Amber moves messages. Green is stored state.

Loading diagram...

1) Order entry. A trader's order reaches the Order gateway, which rejects anything malformed right there, a negative quantity or a price off the tick grid. The checked command goes to the Sequencer, which stamps it, appends it to the Input journal and copies it to a second machine. Once the copy lands, the order is committed. After that, a crash anywhere can't lose it, even though no book has seen it yet. The copy costs tens of microseconds on a local network, and it happens before matching, so the engine itself never waits on a disk or a network.

2) Matching. The sequencer forwards the command to whichever shard owns the instrument, say Matching shard A. That one thread finds the book and runs the matching loop. Each fill becomes a trade at the resting order's price, and any remainder either rests or, for an immediate-or-cancel order, gets cancelled. Every step is an in-memory pointer operation, so a command takes a few microseconds. How the book is laid out to make that true is the first deep dive. For now, one book behind one thread does all the matching.

3) Reporting. The shard sends the acknowledgement and any fills back to the Order gateway, which routes each one to the trader who owns the order. Book changes go to the Market data publisher, which numbers them and sends them over the Multicast feed. Fan-out to thousands of subscribers happens there, away from the matching thread. Meanwhile the Standby shards read the same journal and keep identical books, which is how the rebuild-after-a-crash follow-up gets answered in the last dive.

Technology choices

  • The matching shards are custom C++, one thread pinned to one core, with no database anywhere on the path. The books are small enough for memory and touched on every message. C++ gives control over memory layout and has no garbage collector to pause the thread at a bad moment. The LMAX exchange published the same shape: a single-threaded core handling millions of orders a second.
  • The Input journal is an append-only log. Kafka is the familiar name for this, and it's fine when a few milliseconds per commit is acceptable. For microseconds, trading systems use something lighter such as Aeron, or a log of their own written to local NVMe and copied to a peer. Either way, the order is acknowledged only after the copy lands, so one dead machine loses nothing.
  • The Sequencer is a small service of our own. Its job is narrow: one total order and an append before forwarding. It is a single point of failure, so it runs as a primary with a hot backup that reads the same journal and takes over at the last sequence number written.
  • The Multicast feed uses UDP multicast, as most exchange feeds do, often with a binary format similar in spirit to Nasdaq's ITCH. One packet reaches every subscriber at once. Delivery isn't guaranteed, so every packet carries a sequence number and a recovery service fills gaps.
  • The Order gateway is stateless, so we run several. A gateway restart drops its sessions, and traders reconnect and ask about their open orders. No order lives only in a gateway.

If the interviewer works on a stack you haven't named, defend the category. You need a durable, totally ordered log in front of the engine and a single writer per book. The brand matters far less than those two properties.

Potential deep dives

How should one book store orders so matching and cancel stay fast?

This is where a live round usually starts, and it's the same question the 2018 phone screen asked in miniature with "a buy order class" sorted by price. The book has to answer three questions on almost every message. What's the best price on the other side? Which order at that price is oldest? Where is order 81,442 right now? Each structure below answers some of those well and some badly. A quoting firm cancels far more often than it trades, so the third question comes up constantly.

BadOne sorted list of every order

Approach

Keep each side as a single list sorted by price and then by arrival. The best order is at the front, which makes matching look easy.

Challenges

Every new order needs a sorted insert, which shifts up to the whole list. A book with 50,000 resting orders pays tens of thousands of moves per insert. Cancel has to search the list for the id first. Both costs grow with book depth, and depth is largest exactly when the market is busiest, so the engine slows down at the worst moment.

GoodA sorted map of price levels plus an id map

Approach

Map each price to its level, with the map sorted so the best price comes first. Each level is a queue in arrival order. Add one hash map from order id straight to the order's position in its queue. In C++ that's a std::map per side and a std::list per level, holding on to the list iterator for each order. Finding the best price is a look at the map's first entry. Matching pops from the front of that level. Cancel jumps through the id map and unlinks the order in constant time.

Challenges

A new price level costs a tree insert, logarithmic in the number of levels. Tree nodes and list nodes are scattered across memory, so walking them misses the CPU cache. And every insert allocates memory, which can stall for microseconds in the tail. For a take-home or a whiteboard this is the right answer. A 2023 order-book candidate summed it up as "just use the normal standard library."

cpp
std::map<int64_t, Level, std::greater<>> bids; // highest price first
std::map<int64_t, Level> asks; // lowest price first
std::unordered_map<uint64_t, Order*> orders_by_id; // for cancel in O(1)

The Good tier is usually where the round should land first. The push past it comes from the scale numbers. At a million messages a second, an allocation or a cache miss on every message eats most of a microsecond budget. Say that reason out loud before you start optimizing.

GreatAn array of levels indexed by tick, with pooled orders

Approach

Most activity happens within a few hundred ticks of the current price. So keep an array of levels indexed by price in ticks, covering a window around that price, with a pointer to the best level on each side. Finding a level is an array index. Each order carries its own previous and next pointers, an intrusive list, so unlinking needs no separate node. Orders come from a pool sized at startup, and nothing allocates during trading.

Challenges

When the best level empties, the engine has to find the next non-empty one, and a bitmap of occupied levels makes that search fast. Prices outside the window need an overflow map and a rule for re-centering. The pool needs a size limit and a clean reject when it runs out. It's more code to get right, so build it only after the simple version passes.

The Akuna Capital angle
A May 2026 Shanghai loop's C++ rounds leaned heavily on the STL and lower-level optimization. In this round that means knowing what a std::map node costs in allocations and cache misses, and when an array beats it. Explain that trade-off in words before you write any of the faster version.

What exactly does the matching loop do, including IOC orders?

The loop is short, and that's the trap. Candidates who stumble here usually get the structure right and a rule wrong, and interviewers listen for the rules. Say the loop in words while you write it.

while order has quantity left and the best opposite price crosses its limit:
resting = oldest order at that best price
traded = min(order quantity left, resting quantity left)
report a trade at the RESTING price for traded
shrink both; remove resting if empty, remove its level if empty
rest the remainder (resting limit order) or cancel it (immediate-or-cancel)
1

Trade at the resting price

A buy at 105 that meets a sell resting at 101 trades at 101. The order that was waiting set the price, and the aggressor gets the improvement. Filling at the incoming limit is the most common bug in this problem.

2

Crossing means the prices overlap

A buy crosses when the best ask is at or below its limit, and a sell crosses when the best bid is at or above its limit. Stop the moment it doesn't, even if quantity is left.

3

Immediate-or-cancel never rests

An IOC order runs the same loop and then cancels whatever is left, reporting the cancelled quantity. The 2023 take-home called it FillAndKill. It's one branch at the end of the loop, so the book code stays shared.

4

A modify is a cancel plus a new order

Changing the price or raising the size sends the order to the back of the queue. Many real venues let a size decrease keep its place. Akuna's own specs have been stricter: a 2023 HackerRank version said even a modify that changes nothing loses priority, and the October 2026 listing also has every modify lose it. Ask which rule they want.

5

Market orders need a guard

A market order is a buy or sell at any price. On a thin book it can sweep far from the last trade. Real venues cap how far it may go, so mention a price limit even if you don't build one.

The September 2025 listing also named self-trade prevention: stopping a firm's buy from matching its own resting sell. The usual fix is a check inside the loop. When the resting order belongs to the same account, cancel the resting order or the incoming one, by a rule the account picked in advance. It's one comparison per fill, and naming it unprompted shows you've thought about who's on each side of a trade.

How do order ids and cancels work when a cancel races a fill?

There are two ids per order, and mixing them up causes real bugs. The trader picks a client order id so it can track the order before the exchange has replied. The engine assigns an exchange order id when it accepts the order, from a counter that only goes up. Cancels and modifies point at the exchange id. The gateway rejects a client id the session has already used, which turns a trader's accidental resend into a harmless reject.

Now the race. A trader sends a cancel for order 512. At the same moment, an incoming sell fills order 512 completely. The sequencer puts one of them first. If the cancel is first, the order is pulled and the sell finds nothing there. If the fill is first, the cancel arrives for an order that no longer exists, and the engine answers "too late to cancel." It must never answer with an error that suggests the order is still live. A partial fill is the in-between case: the cancel succeeds and reports only the quantity that was still open. The trader sees a fill report and a too-late reply for the same order, and that's correct. Say this sequence out loud in the round. Someone who builds trading systems for a living will be listening for it.

BadScan the book for the id

Approach

On cancel, walk the levels on both sides until the order turns up, then remove it.

Challenges

Cancel becomes linear in book depth. In a quoting market cancels outnumber trades, so the engine spends most of its time searching. It also can't tell "already filled" from "never existed" without more bookkeeping, so the too-late reply comes out wrong.

GreatAn id map that owns the order lifecycle

Approach

Keep a hash map from exchange order id to the live order, with a pointer to its place in the level. Insert when the order rests, erase in the same step that fills or cancels it. Cancel is one lookup and one unlink. A missing id is a clean "too late or unknown" reply, and the ids come from the sequence, so they're unique across every instrument.

Challenges

The map has to be erased at exactly the moment the order leaves the book, or a cancel finds a dangling pointer. A shard that sizes its pool and map up front can still run out, and needs a clean reject when it does. With exchange-wide ids, the gateway also needs to know which shard owns an id, so encode the shard in the id or keep a small routing map.

How do we handle many instruments?

Start with the numbers. Ten thousand books with about 1,000 resting orders each is 10 million orders. At 64 bytes an order that's 640 MB, which fits in memory on one machine with room to spare. Memory isn't the problem. Time is. A million messages a second through one thread leaves one microsecond each, with nothing in reserve for a burst.

BadA thread pool with a lock per book

Approach

Put every book in one process, let a pool of threads take messages from a shared queue, and lock the book a message touches.

Challenges

Two messages for the same instrument can now land on different threads, and whichever grabs the lock first goes first. That breaks time priority and determinism, because the replay won't take the locks in the same order. Lock handoffs also cost far more than a microsecond under contention, and contention peaks on the busiest instruments.

GreatPartition instruments across single-threaded shards

Approach

Assign each instrument to exactly one shard, and give each shard one thread that owns its books outright. The sequencer forwards each command to the owning shard. Inside a shard nothing is shared, so nothing is locked. If a core does about 2 microseconds of work per message, it tops out near 500,000 a second. Eight shards give each about 125,000 a second at peak, with headroom for a hot instrument.

Challenges

Load isn't even. A few instruments carry most of the traffic, so balance shards on yesterday's message counts rather than how many instruments each one holds. Give the busiest ones a shard of their own. Moving an instrument between shards happens before the session opens. Anything that needs two instruments at once, like a spread order, needs a separate design, so flag it and park it.

The Akuna Capital angle
Akuna opened in Chicago in 2011, in what it calls the options capital of the world, and an options firm lives with "many instruments." Each strike and expiry trades as its own book, so one underlying can mean hundreds of books, mostly quiet, with a few very hot ones. Sharding by message rate fits that shape.

How do we keep up with very high message rates?

Sharding fixes the average. The tail needs more work. At a few microseconds per message, one page fault, one lock or one memory allocation can cost more than the matching itself. Messages also arrive in bursts. When a price moves, every quoting firm cancels and replaces at once, and the shard sees thousands of messages in a few hundred microseconds. So the design question becomes what's still on the hot path, and how to take it off.

One writer, fed by a ring buffer

Hand commands to each shard through a fixed-size ring buffer, a circular array with one producer and one consumer that need no lock. The LMAX Disruptor made this pattern well known. A burst fills the buffer instead of blocking the sequencer, and its fill level tells you when a shard is falling behind.

Nothing allocates while trading

Every order object comes from a pool sized at startup, and a filled order goes back to the pool. With no allocation on the hot path, there are no allocator stalls. Pre-touch the memory at startup so the first busy minute doesn't take page faults either.

Batch the slow work, never the matching

Journal writes and the copy to the peer machine get grouped, a few hundred commands per write, so disk and network costs are shared. Each order still matches the moment it arrives. Only the durability step is batched, so the batch window has to stay short.

Push back at the gateway

When one trader floods cancels, throttle that session at the gateway with a per-session message limit. A runaway client can't then fill a shard's ring buffer and slow everyone else's orders.

Then the machine itself. Pin each shard's thread to a core the operating system leaves alone, so it never gets scheduled out mid-burst. Busy-poll the ring buffer instead of sleeping on it, because waking a sleeping thread costs microseconds. Keep each order small, 64 bytes is one cache line, so touching an order means one memory fetch. Measure the slow end, the 99th and 99.9th percentile per message, because the average hides every stall that matters. Kernel-bypass networking at the gateway is worth naming for wire-to-wire latency, but it's a gateway concern and not the engine's.

A 2019 Sydney onsite had a round that took the code you'd written in an earlier round and "forces you to think about higher scale, as well as a high-level design question." That's an old report, and the code was a game strategy. The move carries over: expect to defend your own data structures at ten or a hundred times the load. Have the per-message budget ready as a number.

How do we rebuild every book after a crash?

A shard's books live only in memory, so a crash wipes them. Recovery has to put back every resting order, at the same price and in the same queue position, and lose nothing that was acknowledged. It also has to be quick, because every instrument on that shard is frozen until it's done.

BadWrite the book to a database on every change

Approach

Store each order row in a database and update it on every fill and cancel. After a crash, load the rows back.

Challenges

Each change now waits on a database write of hundreds of microseconds or more, which blows the latency budget a hundred times over. Queue position also needs its own column, kept exact through every partial fill. And if the process dies between a fill and the database write, memory and the database disagree, with no clean way to tell which is right.

GoodJournal the inputs, replay from the start of the day

Approach

Every command is already in the journal, in sequence order, before the engine sees it. Matching is deterministic. So recovery means starting with empty books and feeding the journal back through the same matching code. The books come back exactly as they were, with the same exchange ids, queue order and fills. The engine's outputs can be regenerated the same way and compared against what was sent.

Challenges

Replay time grows all day. At the peak rate, a shard's share of a 6.5-hour session is about 2.9 billion messages. Replaying 2 million a second, that's about 24 minutes of frozen trading for a crash near the close. Determinism also has to be real. One clock read or a loop over a hash map in output order makes the replay drift from the live run.

Determinism is a list of habits more than a feature. Timestamps come from the sequencer and arrive inside the command. Prices are integer ticks, so no rounding can differ between machines. Nothing iterates a hash map to decide what to emit, and nothing reads a random number. Given those habits, replay is the same code path as live trading.

books = load newest snapshot # tagged with last sequence number n
for command in journal after n:
apply(command) # the same code that runs live
GreatHot standbys that replay the journal, plus snapshots

Approach

Run a standby for each shard on another machine, reading the same journal and applying every command, so its books always match the primary's. When the primary dies, the standby confirms it has applied the last journaled command and takes over in well under a second. The standby also writes a snapshot every five minutes, tagged with its sequence number, so the primary never pauses. A cold restart then loads a snapshot and replays at most 37.5 million messages, about 19 seconds at 2 million a second.

Challenges

Two machines must never both believe they're the primary, so the takeover goes through one authority, usually the sequencer, which stops routing to the old primary first. Fills the old primary emitted but never sent get regenerated by the standby and deduplicated by sequence number downstream. A snapshot taken mid-command is useless, so snapshots only happen between commands.

The standby tier earns its cost by turning recovery from minutes into a fraction of a second. Snapshots remain a backstop for losing both copies. The general pattern is in the replication and partitioning lesson. For the log itself, the Kafka toolbox page covers offsets and replay, the same ideas this journal uses with far tighter latency.

The Akuna Capital angle
A 2019 take-home brief ranked passing every test first, then clean, readable design. Live rounds grade the same instinct. And a deterministic engine has a quiet bonus here: the journal doubles as a test suite. Replay a recorded day and compare the fills, and crash recovery turns into your testing story.

Practice the core in code

The take-home lesson already drills one book with cancel, modify and IOC. This problem adds the parts the scale questions are about. It keeps a book per instrument and issues exchange-wide ids from one counter. It rejects bad commands before they reach the journal, and it rebuilds every book from that journal after a simulated crash.

1

Multi-Instrument Exchange With Journal Replay

Hard
Problem
Build an Exchange that keeps one limit order book per instrument and can rebuild all of them after a crash.

submit(symbol, side, price, quantity, kind) takes a side of "BUY" or "SELL", an integer price and quantity, and a kind of "GTC" (rests in the book) or "IOC" (never rests). If the side or kind is anything else, or the price or quantity is below 1, return ["REJECT"].

Otherwise the order gets the next exchange-wide id, starting at 1. Return "ACK ", then one "TRADE " per fill. An IOC remainder adds "CANCEL ".

Matching uses price-time priority within the order's own symbol and fills at the resting order's price. A GTC remainder rests quietly.

cancel(order_id) removes a resting order and returns ["CANCEL "], or ["REJECT"] if it isn't resting. top(symbol) returns [best bid, best ask], with 0 for an empty side or an unknown symbol.

restart() simulates a crash. It loses all in-memory state except a journal of every accepted submit and successful cancel. Rebuild everything by replaying it and return the number of commands replayed. Rejected commands are never journaled.
  1. Exchange()
  2. submit("ABC", "SELL", 101, 5, "GTC")→ ["ACK 1"]
  3. submit("ABC", "SELL", 101, 3, "GTC")→ ["ACK 2"]
  4. submit("ABC", "BUY", 101, 6, "GTC")→ ["ACK 3","TRADE ABC 3 1 101 5","TRADE ABC 3 2 101 1"]
  5. top("ABC")→ [0,101]

Order 3 fills against order 1 first because it arrived first at 101. Order 2 keeps 2 open, so the best ask is still 101 and no bid rests.

How this uses the pattern

Keep one book per symbol (price levels in arrival order plus a heap of prices per side) and one id map across all symbols. Journal a command only after it passes validation, and route both live calls and replay through the same internal functions.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Multi-Instrument Exchange With Journal Replay

Loading...
Click "Run" to execute your code
The Akuna Capital angle
This is the deterministic-replay idea from the recovery deep dive, small enough to run. Two details catch people. The id counter isn't stored anywhere special, because replaying the accepted submits rebuilds it. And a rejected command must leave no trace, or the replayed ids drift from the live ones. Say both rules before you code.
Take it further
Add snapshots. Let snapshot() record the books, the id map, the next id and the journal length. Then restart() loads the latest snapshot and replays only the journal entries after it. Next, add a modify that journals as a cancel plus a new order, and check that replay keeps the lost queue position.

Follow-ups to be ready for

A subscriber missed packets. Every feed packet carries a sequence number, so a gap is visible right away. The subscriber stops applying updates for that instrument, asks a recovery service for the missing range or a full book image, and replays from there. Never let it guess at what it missed.

Retrieving product data. The 2021 Sydney final paired the trading system with fetching product data from a server. On an exchange, that's the instrument list: tick size, lot size and trading hours for each symbol. It changes rarely, so load it before the session opens and treat it as read-only during trading. A new listing takes effect at the next session.

Opening the market. Orders that arrive before the open can't be matched one at a time, or the first order to arrive gets an unfair price. Exchanges run an auction instead. They collect orders and pick the single price that trades the most quantity. Then continuous matching starts. Mention it, then park it unless asked.

Pre-trade risk. A real venue rejects an order that's far from the current price or far larger than normal before it reaches the book. Those checks belong at the gateway, where they cost the matching thread nothing, with one exception. A price band around the last trade depends on book state, so it runs inside the shard.

What is expected at each level

Intern and new grad

Most named design prompts at Akuna come from intern, graduate and junior loops, so this is the common case. Spend about 80 percent on getting one book right and 20 percent on scale. You should pick the price-level map and the id map without being led there. Run the matching loop on a small example out loud and get the rules exact. Fills happen at the resting price, IOC orders never rest, and a cancel after a full fill is too late. If time is left, sketch sharding by instrument and replay from a journal in a sentence each. The bar: a correct, readable single-book engine you can explain line by line.

Software engineer

Here the split moves to about 60/40. Get the single-book core out in the first third of the round, then drive into the follow-ups yourself. Raise the per-message budget as a number and use it to justify single-threaded shards. Explain why a lock per book breaks determinism. Lay out journal, replay, snapshots and standbys with the replay-time arithmetic. On the C++ track, expect to talk about allocation and cache behavior in the book structures. The bar: you find the scale problems before the interviewer names them, and each fix comes with a number.

Senior

No senior report names a live design prompt at Akuna. Senior candidates mostly describe the multi-day take-home, and one senior offer in 2023 said no architecture questions came up at all. If you do get this round, expect about 40/60 breadth to depth. You'd be leading on failover without two primaries, hot-instrument rebalancing, feed recovery and tail latency at the 99.9th percentile. The interviewer should mostly be steering you. Needing to be rescued reads as below the level. The bar: a design you could defend to the people who'd run it on a volatile morning.

Key Takeaways

  • ✓Build one book first: sorted price levels with an arrival-order queue at each, plus an id map for constant-time cancel.
  • ✓Fill at the resting price, cancel IOC remainders, and answer "too late to cancel" when a fill wins the race.
  • ✓Scale by giving each instrument to exactly one single-threaded shard, with no locks and no allocation while trading.
  • ✓Journal inputs before matching, keep the engine deterministic, then recover with hot standbys plus snapshots.
Akuna Capital interview guide

Know what Akuna Capital asks before you walk in.

30 coding · 5 system design · 16 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

Akuna Capital System Design Interview QuestionsHad your Akuna Capital interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.