A high-performance, real-time cryptocurrency exchange platform built with a microservices architecture. Features include order matching, real-time market data, WebSocket connections, and a modern trading interface.
- Node.js
- Docker and Docker Compose
- Redis
- PostgreSQL with TimescaleDB extension
Order matching needs to be fast β microseconds, not milliseconds. Storing orders directly in a database would add network + disk I/O on every match, making it impossible to handle high throughput. The engine keeps the full order book in memory and only persists completed trades asynchronously via a Redis queue to the DB processor service. This decoupling is what allows the engine to handle 10,000+ orders/sec without being bottlenecked by the database.
Candlestick (kline) data is pure time-series β every query is "give me all prices between time A and time B." TimescaleDB's hypertables partition this data automatically by time, cutting kline query times dramatically compared to a regular Postgres table with billions of rows. The 1m/1h/1w materialized views are pre-aggregated, so the frontend gets instant responses without re-scanning raw trade data on every request.
Market data needs to be broadcast to potentially thousands of connected clients simultaneously. If the WebSocket logic lived inside the API server, a spike in connected users would compete with order processing for the same resources. Separating it means the trading engine is completely isolated from broadcast load β the WS server just subscribes to Redis pub/sub and forwards updates.
Each service (API, engine, DB processor, WS server) needs to communicate without being directly coupled. Redis pub/sub gives a lightweight, fast message bus that keeps services independent. The API publishes an order β engine picks it up β publishes the result β DB processor and WS server both consume it. Adding or restarting any single service doesn't affect the others.
git clone https://github.com/akash-wt/exchange
cd exchangecd Backend/docker
docker-compose up -dThis starts:
- TimescaleDB on port 5432
- Redis on port 6379
cd Backend/db
npm install
npm run seed:dbAPI Server:
cd Backend/api
npm install
npm run devTrading Engine:
cd Backend/engine
npm install
npm run devDatabase Processor:
cd Backend/db
npm install
npm run devWebSocket Server:
cd Backend/ws
npm install
npm run devMarket Maker (Optional):
cd Backend/mm
npm install
npm run devcd frontend
npm install
npm run devβββ Backend/
β βββ api/ # REST API server
β βββ engine/ # Trading engine
β βββ db/ # Database service
β βββ ws/ # WebSocket server
β βββ mm/ # Market maker
β βββ docker/ # Infrastructure setup
βββ frontend/ # React frontend
βββ README.md
Each service uses environment variables for configuration. Key variables include:
- Database connection settings
- Redis connection details
- API endpoints
- WebSocket URLs
The platform uses TimescaleDB for efficient time-series data storage:
- tata_prices: Price and volume data
- klines_1m/1h/1w: Materialized views for different timeframes
POST /api/v1/order- Place new orderDELETE /api/v1/order- Cancel orderGET /api/v1/order/open- Get open orders
GET /api/v1/depth- Order book depthGET /api/v1/trades- Recent tradesGET /api/v1/tickers- Market tickersGET /api/v1/klines- Historical price data
Subscribe to real-time data streams:
// Depth updates
{"method": "SUBSCRIBE", "params": ["depth@TATA_INR"]}
// Trade updates
{"method": "SUBSCRIBE", "params": ["trade@TATA_INR"]}
// Ticker updates
{"method": "SUBSCRIBE", "params": ["ticker@TATA_INR"]}Run the test suite:
cd Backend/engine
npm testTests cover:
- Order matching logic
- Market depth calculations
- Trade execution scenarios
- Database: Use managed PostgreSQL with TimescaleDB
- Redis: Use Redis Cluster for high availability
- Load Balancing: Deploy multiple API instances behind a load balancer
- Monitoring: Implement comprehensive logging and monitoring
- Security: Add authentication, rate limiting, and input validation
Build and deploy using Docker:
# Build services
docker build -t exchange-api ./Backend/api
docker build -t exchange-engine ./Backend/engine
docker build -t exchange-ws ./Backend/ws
# Deploy with docker-compose
docker-compose up -dNote: This is a development/educational project. For production use, additional security measures, testing, and compliance considerations are required.

