Selected work / Systems / Exchange architecture

Matchx

An exchange architecture study, from order arrival to trade persistence.

An order arrives.A system responds.

An order endpoint is only the beginning. The interesting work is how an order reaches the book, becomes a trade, and reaches the rest of the system.

Follow the story
The thinking behind the build
  • Spring Boot
  • PostgreSQL
  • Kafka
  • WebSocket
Explore the repository
Built for
Exploring a real engineering problem
Format
Repository-based architecture study
Evidence
Source reviewed / demo not published here

01 / The problem

A trade is more than an API response.

Concurrent orders, partial fills, downstream storage, and live views create different demands. Matchx explores those responsibilities in separate services without presenting the result as a production exchange.

From the friction → to the system

02 / Architecture

Give each responsibility a boundary.

Follow one journey through the system.

System / Matchx01 — 04
  1. 01
    Order APIPrice + quantity + side
  2. 02
    Matching enginePer-symbol order book
  3. 03
    Kafkatrade-events
  4. 04
    PersistenceTrade PostgreSQL database
Architecture illustration / source reviewed
Not a product screenshot
01 / 04

Order API

A priced buy or sell order enters through the API. Price, quantity, and side define the request.

02 / 04

Matching engine

The per-symbol order book handles matching and remaining quantities. Correct price selection still needs explicit verification.

03 / 04

Kafka

Matched trades are published asynchronously to trade-events, keyed by symbol. Send failures are a separate concern to test.

04 / 04

Persistence

A separate consumer stores trades. Order-book snapshots take another branch to the Angular client over WebSocket.

Outside the main path

A separate branch sends order-book snapshots over STOMP/WebSocket to the Angular client. WebSocket updates are not shown as depending on the persistence consumer. Compose defines separate main and trade PostgreSQL databases.

Inside the implementation

The details
make the difference.

A closer look at the decisions, boundaries, and work still ahead.

Engineering notes / 01

Where matching happens

The matching-engine-service owns MatchingEngine and OrderBook. The source represents price-based buy and sell orders, price levels with queues, remaining quantities, and partial fills. No separate market-order type was established in this review.

This is not labeled a verified price-time-priority engine: the sell-side lookup uses lastKey() on a reverse-ordered bid map. That selection needs a correctness test before making a best-price guarantee.

Engineering notes / 02

Trade flow and failure boundaries

TradePublisherService asynchronously publishes trades to trade-events, keyed by symbol. A separate Spring Kafka consumer handles trade persistence. The engine also provides order-book snapshots to the WebSocket publisher.

The publisher logs send failures. That alone does not establish crash recovery or durable replay of every matched trade. A recovery test and a durable publication strategy are follow-up work before claiming lossless execution.

Engineering notes / 03

What the simulator demonstrates

The market simulator generates priced orders around a changing mid-price, crossing orders, and volatility spikes. It is a way to exercise the flow; it is not a measured throughput or latency benchmark.

Useful next evidence would include an order-book capture, matching-correctness tests, a consumer restart test, and a reproducible load report.

Scope & evidence

What this page establishes.

Source-level architecture review. No throughput, latency, fairness, crash-safety, or production-readiness result is claimed.