A matching engine is the software at the centre of a stock exchange that matches each order to buy with an order to sell. It is used for shares, futures and options. It keeps an order book: a list of every buy order and every sell order that is waiting, sorted by price.
The engine follows a strict rule called price-time priority. The best price is matched first. For a buyer, the best price is the lowest selling price on offer. If two orders have the same price, the one that arrived first is matched first.
Imagine the order book for one share. Three sell orders are waiting. The first is 200 shares at ₹500.10, entered at 10:01 a.m. The second is 300 shares at ₹500.10, entered at 10:03 a.m. The third is 500 shares at ₹500.20. Now a buy order arrives for 400 shares, at any price up to ₹500.15. The engine fills 200 shares from the first seller and 200 shares from the second seller, all at ₹500.10. The third order is too expensive for this buyer, so it is not touched. The remaining 100 shares of the second seller stay in the book. All of this takes a few microseconds.
Orders reach the engine from brokers' order management systems, from funds' execution algorithms and from high-frequency trading firms. These firms place their servers inside the exchange's own data centre, to save microseconds. This is called co-location.
The engine must be fast, but it must also be fair and exact. Every order passes through the same queue. The same orders in the same sequence must always produce exactly the same trades. A backup copy of the engine runs in parallel, so that it can take over immediately if the main one fails.
After each match, the engine does two more things. It sends the trade to clearing and settlement, where the trade is guaranteed and settled. It also publishes the new price to the market data feed. Within moments, that price appears on every financial data terminal. India's exchanges now handle more options contracts than any other market in the world, so their matching engines are among the busiest anywhere.