A high-performance backend-focused trading simulation platform that replicates core functionality of a financial exchange, including a custom order matching engine, real-time market updates, and portfolio tracking.
This project is designed to demonstrate backend engineering, system design, concurrency handling, and fintech domain understanding.
This system simulates a simplified stock exchange where users can:
- Place buy/sell orders
- Trade virtual assets in real time
- View live order book updates
- Track portfolio performance
At its core is a price-time priority matching engine, similar to real-world trading systems.
- Limit and market orders
- Price-time priority order matching
- Partial order fills
- Order cancellation support
- Multi-symbol trading (e.g., AAPL, TSLA)
- WebSocket-based live updates
- Live order book changes
- Trade execution broadcasts
- Real-time price updates
- User registration and authentication
- Cash balance management
- Portfolio tracking (holdings per asset)
- PostgreSQL for persistent storage
- Orders, trades, and user data tracking
- Event logging for trade history
graph TD
A[Client - React / Postman] --> B[API Layer - FastAPI / Spring Boot]
B --> C[Auth Service]
B --> D[Order Management Service]
B --> E[Matching Engine]
D --> E
E --> F[In-Memory Order Book]
E --> G[Trade Execution Engine]
G --> H[PostgreSQL Database]
E --> I[Event Dispatcher]
I --> J[WebSocket Gateway]
J --> A
H --> D
H --> C
sequenceDiagram
participant U as User
participant API as API Server
participant ME as Matching Engine
participant OB as Order Book
participant DB as PostgreSQL
participant WS as WebSocket Server
U->>API: Place Order (BUY/SELL)
API->>ME: Forward Order
ME->>OB: Add to Order Book
OB->>ME: Check for Match
alt Match Found
ME->>ME: Execute Trade
ME->>DB: Persist Trade + Order Update
ME->>WS: Broadcast Trade Event
WS->>U: Live Trade Update
else No Match
ME->>DB: Store Open Order
end
Client (React / Web UI)
↓
REST API (FastAPI / Spring Boot)
↓
Matching Engine (In-Memory, High Speed)
↓
Database (PostgreSQL)
↓
WebSocket Gateway (Real-Time Updates)
- In-memory order book for low-latency execution
- Event-driven trade processing
- Separation of API layer and matching engine
- Concurrent-safe order processing
The system uses a price-time priority algorithm:
-
Buy orders sorted by:
- Highest price first
- Earliest timestamp second
-
Sell orders sorted by:
- Lowest price first
- Earliest timestamp second
A trade executes when:
buy_price >= sell_price
Partial fills are supported until orders are fully matched.
- Python (FastAPI) / Java (Spring Boot)
- WebSockets (real-time communication)
- Async processing (optional)
- PostgreSQL
- Redis (pub/sub, caching)
- Docker (containerization)
- Kafka (event streaming for advanced version)
- React
- Trading dashboard UI
- Live order book visualization
- id
- username
- password_hash
- cash_balance
- id
- user_id
- symbol
- side (BUY / SELL)
- price
- quantity
- status (OPEN / PARTIAL / FILLED / CANCELLED)
- timestamp
- id
- buy_order_id
- sell_order_id
- symbol
- price
- quantity
- timestamp
- User places BUY order for AAPL at $150
- Another user places SELL order at $149
- Matching engine detects overlap
- Trade executes instantly at matched price
- Portfolio and order book update
- WebSocket broadcasts update to clients
Clients receive live updates via WebSockets:
- Order book changes
- Trade executions
- Price updates
- Portfolio changes
- Risk management system (margin limits, exposure caps)
- Latency benchmarking for matching engine
- Order replay system (reconstruct market state)
- Distributed matching engine (sharding by symbol)
- Kafka-based event streaming pipeline
# Backend
pip install -r requirements.txt
uvicorn app.main:app --reload
# Database
docker-compose up -d postgresThis project demonstrates:
- Backend system design
- High-performance in-memory processing
- Real-world fintech architecture concepts
- Concurrency-safe engineering
- API + real-time system integration
It is directly relevant to roles in:
- Fintech engineering
- Backend software engineering
- Trading infrastructure teams
- Add React trading dashboard
- Add candlestick chart visualization
- Introduce simulated market volatility engine
- Add authentication with OAuth2 / JWT refresh tokens
- Deploy to cloud (AWS / GCP)
Built as a capstone project to demonstrate production-level backend engineering and fintech system design skills.