Home / Order Matching Engine

Order Matching Engine

January 2026 Full Stack C++ · Next.js · TypeScript

Overview

A full-stack order matching engine that implements a price-time priority algorithm for matching buy and sell orders across multiple trading symbols. The backend is built in C++20 with a REST API served via cpp-httplib, while the frontend uses Next.js and TypeScript to provide a real-time trading dashboard.

The engine supports LIMIT and MARKET orders, partial fills, order cancellation, and a full trade history. The frontend auto-refreshes every two seconds to reflect live order book and trade data without requiring WebSockets.

Key Features

Tech Stack

C++20 cpp-httplib nlohmann/json Next.js TypeScript Tailwind CSS Make

Architecture

The C++ backend runs a multi-threaded HTTP server on port 8080. A Next.js proxy rewrites /api/* requests to the backend, avoiding CORS issues while keeping the frontend on port 3000. All prices are stored as 64-bit integer cents to eliminate floating-point precision problems.

Challenges & Learnings

The hardest part was designing a data structure that guarantees correct price-time priority: a std::map naturally sorts by price, but matching multiple deques within a price level required careful iterator management during partial fills. Bridging a compiled C++ server with a Node.js frontend also required setting up a transparent reverse-proxy in Next.js config to keep development seamless.