Matching Engine Architecture for Stock Exchanges
Learn how a stock exchange matching engine handles orders, sets trade priority, cuts delay, and stays reliable during fast market activity.
Introduction to Matching Engine Architecture

A stock exchange matching engine connects buyers and sellers in real time. It receives orders, checks them, matches trades, and shares results.
Matching engine architecture covers more than the matching core. It includes order entry, risk checks, order books, data feeds, logs, and recovery tools.
The core must follow the same steps every time. A small delay can change which order trades first. Fairness depends on that sequence.
Most systems keep the core engine small and predictable. Other services handle storage, reports, access, and risk tasks around it.
A typical trading system architecture follows this path:
- A trader sends an order through a broker or exchange gateway.
- The gateway checks the message format and account rules.
- Risk checks approve or reject the order before book entry.
- The engine adds the order or matches it against the other side.
- The trade service records the result and sends market updates.
- Clearing and settlement systems receive the final trade record.
Key Components of a Matching Engine

The order book stores open buy and sell interest for one market. Buy orders sit on the bid side. Sell orders sit on the ask side.
Each price level can hold many orders. The book must preserve order, size, and status without losing updates.
The matching core checks each new order against the other side. It creates trades when price and order rules allow a match.
Order gateways manage incoming links and message checks. They may also limit message rates during sudden demand.
| Component | Main job |
|---|---|
| Order gateway | Receives and checks incoming messages |
| Order book | Stores open bids and offers by price |
| Matching core | Applies rules and creates trades |
| Market data service | Publishes quotes, trades, and book changes |
| Event log | Stores a replayable system record |
Risk controls can reject an order before it reaches the core book. Common checks include price bands, size limits, credit limits, and account status.
A market data feed shares book changes with brokers, vendors, and trading firms. Some exchanges publish separate feeds for quotes and completed trades.
Event logs capture each accepted order, change, cancel request, and trade. These logs support recovery, audits, and dispute reviews.
Order Types and Their Functions
Order types tell the engine how to handle a trading request. The main types are market orders and limit orders.
A limit order sets the worst price a trader accepts. A buy limit at $50 can trade at $50 or less.
A sell limit at $50 can trade at $50 or more. The order stays open until it fills, expires, or gets canceled.
A market order seeks the best available price at once. It may fill across several price levels. Large orders can move the market.
Other order types add timing or display rules. Their exact features vary by exchange and market.
- Stop order: Activates after the market reaches a set trigger price.
- Iceberg order: Shows only part of its full size to the market.
- Fill-or-kill order: Must fill in full or cancel at once.
- Immediate-or-cancel order: Fills what it can, then cancels the rest.
- Day order: Remains active until the trading session ends.
The engine must track hidden and shown size with care. An iceberg order should not gain unfair priority when it refreshes.
How Matching Algorithms Decide Trade Priority

Most exchanges use price-time priority. The best price comes first. Orders at the same price follow arrival time.
For example, two buy orders wait at $100. The order accepted first gets matched first.
A later order must wait, even when it has a larger size. This rule gives traders a clear and repeatable result.
Some markets use other matching algorithms. A pro rata model shares fills by size at one price.
An auction model collects orders before setting one clearing price. This model can help markets open in an orderly way.
A liquid stock market may favor price-time priority. A derivatives market may use pro rata rules for some contracts.
The engine must handle partial fills. A 1,000-share buy order may match 400 shares first.
The remaining 600 shares keep their place under market rules. Cancel and replace actions also need strict handling.
A price change often loses the order's old time priority. A size cut may keep it under exchange rules.
Performance and Latency Considerations
High-frequency trading demands very fast order handling. Some venues aim for microsecond response times.
Latency means the delay between order entry and the engine's reply. Low latency matters most when many orders compete for one price.
Engine teams often keep the hot path short. They avoid slow storage calls during matching.
Memory-based books can cut delay. A single process can also reduce message travel between services.
Fast systems still need safe controls. A speed gain has little value if it causes lost orders or wrong trades.
- Keep active books in fast memory.
- Use fixed message formats where possible.
- Measure each step from gateway to market feed.
- Separate matching work from slow reports.
- Test peak order rates before launch.
Scalability needs careful design. Separate markets can run on separate engine instances.
One market should not slow another market without a clear reason. Teams should test bursts, cancel storms, and feed delays.
Reliability and Fault Tolerance Measures
A stock exchange matching engine must keep a trusted record of every event. That record helps the team rebuild the book after a fault.
Event logging writes accepted orders, trades, cancels, and system actions in sequence. The engine can replay those events to restore its state.
Many venues use a hot standby system. It keeps a current copy of the active engine state.
If the main engine fails, the standby can take control. The switch must preserve order sequence and prevent duplicate trades.
Recovery plans need more than backup servers. They need clear tests, timed drills, and checks for damaged data.
| Control | Purpose |
|---|---|
| Hot standby | Continues service after a main engine fault |
| Event log | Rebuilds state from an ordered record |
| Health checks | Finds faults before they spread |
| Replay tests | Confirms that recovery gives the same result |
| Time sync | Keeps event order clear across systems |
Clock control also matters. The exchange must show when orders arrived and when trades occurred.
Teams should test network loss, power loss, bad messages, and full storage. A recovery plan is real only after a live drill.
Regulatory Compliance and Fair Execution
Exchanges must keep records that explain how each trade came about. Records should cover orders, changes, cancels, and final fills.
Fair access is another core duty. Members need clear rules for entry, market data, and system timing.
The exchange must apply the same matching rules to all eligible orders. Staff should not change priority by hand during normal trading.
Risk controls and circuit breakers help limit disorderly trading. A circuit breaker pauses or slows trading after a sharp move.
Audit tools should connect each order to its later actions. This trail helps find errors, abuse, and rule breaches.
A sound compliance plan should include:
- Full order and trade records.
- Clear access and timing rules.
- Tests for equal order treatment.
- Alerts for unusual trading patterns.
- Regular reviews of system changes.
Rules vary by market and country. The engine design must match the venue's rulebook and legal duties.
Technical design and fair dealing cannot be split apart. A fast engine still fails if its rules are unclear or hard to audit.
How to Assess a Matching Engine Design
Start with the market's needs. A small venue may value simple recovery and low cost.
A busy exchange may need several engine instances, feed paths, and standby sites. The right design depends on order volume, asset type, and trading hours.
Ask vendors to show real test results. Request figures for peak messages, cancel rates, reply delay, and recovery time.
Review the full path, not just the matching core. Gateways, risk checks, feeds, and logs can add most of the delay.
- Map every order path.
- Set clear speed and uptime goals.
- Define priority rules for each market.
- Test faults and replay results.
- Check records against legal duties.
- Run a controlled market trial.
The best order matching engine is not the fastest in a lab. It is the one that stays fast, correct, clear, and safe under real load.
Frequently asked questions
- What is a matching engine in a stock exchange?
- A matching engine pairs buy and sell orders. It applies market rules, creates trades, and sends updates.
- How does an exchange order book work?
- An order book stores open buy and sell orders in ranked lists. Price comes first, then accepted time.
- Why is latency important in high-frequency trading?
- Low latency helps an exchange process orders quickly. It also limits delays between the book, trades, and market feeds.
- How do matching engines scale?
- Venues can split books by instrument and add more gateway servers. Separate market feeds can serve more data users.
- What records must a matching engine keep?
- It should record order arrival, sequence, checks, changes, fills, rejects, and output events. These records support review and replay.