How order matching engines work
A matching engine pairs buy and sell orders into trades. Here is how order matching engines work, and why price-time priority decides who is filled first.

Mechanics, not signals. This explains how a market feature works. It is not a trading strategy, entry, target, or recommendation to buy or sell anything.
Quick answer
A matching engine is the exchange software that pairs incoming orders with resting orders to create trades. It follows a fixed rule, usually price-time priority, matching better prices first and, at the same price, the earliest order first, then rests any unfilled quantity in the order book.
Key points
- The engine matches orders and rests the remainder
- Price-time priority: best price first, then earliest
- Large orders fill across multiple price levels
- Matching is deterministic and fully auditable
- Clearing and settlement happen after the match
A matching engine is the software at the heart of an exchange that pairs buy orders with sell orders and turns them into trades. Every order you send arrives here, is placed into the order book, and is either matched against a waiting order or left to rest. It is a strict, rule-following referee — and understanding its rules explains why fills happen the way they do.
What the engine actually does
At its core, the matching engine performs one loop, continuously and very fast. For each incoming order it asks: does this order cross with anything resting on the opposite side of the book? If yes, it executes a trade for as much as it can. If not, or if any quantity is left over, it records the remainder in the book as a resting order. That is the whole job — but it is done with total consistency, for enormous volumes of orders, in a precisely defined sequence.
Consistency is the point. Because a market must treat every participant by the same rules, the engine cannot make judgement calls. It applies a fixed priority system to decide which resting order gets matched first, so that any two orders in the same situation are always handled the same way.
Price-time priority, step by step
The most common rule set is price-time priority, sometimes called FIFO (first in, first out). It has two tiers:
- Price first: better-priced orders are matched before worse-priced ones. A buyer offering more, or a seller asking less, moves ahead in the queue.
- Time second: among orders at the same price, the one that arrived earliest is matched first. Being early in the queue at a given price is a real, mechanical advantage.
Consider an illustrative sell side with two offers at the same price: 5 units at 100.5 posted at 9:00:00, and 3 units at 100.5 posted at 9:00:01. A market buy for 4 units takes all it can from the earliest order first: 4 of the 5 units posted at 9:00:00. The later order is untouched until the earlier one is exhausted. That is time priority in action.
Priority also determines what happens when an incoming order is larger than the size at the best opposing price, the engine fills across multiple levels. A market buy for 10 units against 4 at 100.5 and 9 at 100.7 fills 4 at 100.5, then 6 at 100.7, and stops. The buyer receives a blended average price, and the book is left with the 100.5 level gone and 3 units at 100.7. This walking behaviour is exactly the mechanism behind slippage, and how far an order walks depends on market depth.
Other priority models
Price-time is the most widespread model, but not the only one. Some derivatives venues use pro-rata matching, where an incoming order is split among all resting orders at the best price in proportion to their size, rather than strictly by who arrived first. Others use hybrids that reward the first order to establish a new best price and then share the rest pro-rata. These are design choices a venue makes and publishes in its rules; the important idea is that the matching logic is always explicit and deterministic, not discretionary.
Speed, throughput, and fairness
Modern engines process very large numbers of orders per second with extremely low latency. Speed matters because time priority means the order that arrives first wins the queue, so the sequence in which orders are received has real consequences. To keep this fair and orderly, exchanges take several mechanical measures:
- Deterministic sequencing: orders are timestamped and processed in a defined order, so the outcome does not depend on chance.
- Matching separate from the gateway: the core matching logic is often isolated from the systems that receive and validate orders, so it can run as fast and predictably as possible.
- Circuit breakers and price limits: many venues pause trading or reject orders outside set bounds to prevent errant orders from causing disorderly moves.
Regulators and exchanges pay close attention to this machinery because high-speed electronic matching shapes how fair and stable a market is, a topic examined in central-bank and markets-committee studies of electronic trading.
Underpinning that fairness is a defining property of a good matching engine: it is deterministic. Given the same sequence of orders, it always produces the same trades in the same order. This is not a nicety — it is what makes a market auditable. Every order is stamped with a unique identifier and a precise time of arrival, and the engine records the exact sequence in which events were processed. Because the outcome depends only on that recorded sequence and the published rules, a venue (or a regulator examining it) can replay the log and confirm that every match followed price-time priority correctly. Determinism is also why the order of arrival carries such weight: since the engine never improvises, being first in the queue at a given price is a concrete, logged advantage rather than a matter of luck.
The life of an order inside the engine
From the engine’s point of view, every order moves through a small set of well-defined states. It is received and validated at the gateway (checking the account, balance, and that the order is well-formed), then accepted into the matching process. From there it is either matched — fully or partially — or rested in the book as an open order. A rested order stays open until it is filled, cancelled by its owner, or expires under its time-in-force rule. Each of these transitions generates a message back to the participant: accepted, partially filled, filled, cancelled, or rejected. Understanding this lifecycle demystifies the status updates a trading interface shows; they are simply the engine reporting which state your order is now in.
Continuous matching, the mode described so far, is the usual one but not the only one. Many venues open or close a session with an auction: for a short window, orders are collected without matching, and then a single clearing price is calculated that maximises the quantity that can trade. Everyone who trades in that auction does so at the one price, which is a fairer way to handle the burst of activity at the start and end of a session. Engines also commonly include self-trade prevention, a rule that stops a single participant’s buy and sell orders from matching each other, which could otherwise create misleading volume. These are additional mechanical safeguards layered on top of the core matching loop.
What happens after a match
Matching is only the first step. Once the engine records a trade, the details flow onward to clearing and settlement, where the actual transfer of the asset and the payment are arranged and finalised. On a crypto exchange this often happens on the venue’s internal ledger for trades between its users, with on-chain movement only when funds enter or leave. The matching engine decides that a trade happened and at what price; separate systems make sure the two sides actually exchange what they owe.
What this means
A matching engine is a deterministic rule-follower, not a decision-maker. It takes each order, checks whether it crosses the book, executes what it can by a fixed priority — almost always best price first, then earliest arrival — and rests the rest. Once you internalise price-time priority, a lot of market behaviour stops being mysterious: why better prices fill first, why being early in the queue matters, and why large orders fill at several prices. The engine is simply applying the same rules to everyone, every time. This article explains mechanics only and is not trading advice.
Sources
Frequently asked questions
What is price-time priority?
It is the rule most matching engines use to order the queue: better-priced orders are matched first, and among orders at the same price, the one that arrived earliest is matched first.
Does the matching engine also settle the trade?
No. The engine decides that a trade happened and at what price, then separate clearing and settlement systems handle the actual transfer of the asset and the payment between the two sides.
Is price-time priority the only matching rule?
No. Some venues use pro-rata matching, which splits an incoming order among resting orders at the best price by size, or hybrids of the two; every venue publishes the rule it uses.
Related
What is circulating supply?
Circulating supply is the number of crypto tokens freely available to trade today. Learn how it differs from total and…
Impermanent loss, explained arithmetically
Impermanent loss is the shortfall a liquidity provider takes versus holding when pool prices diverge. See the exact constant-product math…
What is a flash loan?
A flash loan is an uncollateralised loan borrowed and repaid in one transaction. Learn how atomicity makes it possible and…
