Skip to content

A distributed trading backend inspired by Exness, designed with modular microservices for performance and scalability.

Notifications You must be signed in to change notification settings

akash-R-A-J/exness

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exness Trading Platform

A microservices-based trading platform built with Node.js, featuring real-time trade execution through Kafka message streaming and dual-layer state management. 1

Architecture

The platform uses a microservices architecture with three core components:

  • Backend Service (Express.js on port 5000): HTTP API gateway handling authentication, request orchestration, and database operations
  • Engine Service (Node.js): Isolated trade processing with in-memory state for low-latency execution
  • Message Broker (Apache Kafka): Asynchronous inter-service communication with correlation IDs for request-response patterns 2

Tech Stack

  • Runtime: Node.js with TypeScript
  • Backend Framework: Express.js
  • Message Queue: Apache Kafka
  • Database: TimescaleDB (PostgreSQL)
  • Cache: Redis (for sessions and magic links)
  • Authentication: JWT with magic link signup 3

Key Features

Trade Operations

  • Open/close trades with leverage support
  • Real-time price updates from external poller
  • Automatic liquidation price calculation
  • In-memory order book for fast execution 4

Authentication

  • Passwordless magic link authentication
  • JWT-based session management
  • Protected trade and balance endpoints 5

Data Management

  • In-Memory State (Engine): latestPrice, openOrders, userBalance for sub-millisecond access
  • Persistent Storage (TimescaleDB): User accounts, asset definitions, trade history 6

API Endpoints

Endpoint Method Auth Description
/api/v1/signup POST None Generate magic link
/api/v1/signin/post GET None Validate magic link
/api/v1/trade/create POST JWT Open new trade
/api/v1/trade/close POST JWT Close existing trade
/api/v1/balance/usd GET JWT Query USD balance
/api/v1/balance/ GET JWT Query total balance

Request Response Pattern

image

Message Flow

The system implements a synchronous request-response pattern over Kafka using correlation IDs:

  1. Backend generates unique ID and publishes command to trade-price topic
  2. Engine consumes message, executes business logic, publishes result to acknowledge topic with same ID
  3. Backend consumer matches ID and resolves the waiting promise (5-second timeout) 7

Engine Task Routing

The engine routes messages based on data.task field:

  • createUser: Initialize user with 5000 USD balance
  • create: Open trade (validate balance, calculate liquidation)
  • close: Close trade (calculate PnL, update balance)
  • balance/usdBalance: Return current balance

Price updates from external poller (identified by from: "poller") update the latestPrice object without acknowledgment. 8

Getting Started

Prerequisites

  • Node.js
  • Kafka broker
  • TimescaleDB instance
  • Redis server

Environment Variables

KAFKA_BROKER=<kafka-broker-url>
TIMESCALE_CONNECTION_STRING=<postgres-connection-string>

Running Services

Backend:

cd backend
npm install
npm start

Engine:

cd engine
npm install
npm start

Supported Assets

The platform currently supports three trading pairs (hardcoded on initialization):

  • SOL_USDC (Solana)
  • ETH_USDC (Ethereum)
  • BTC_USDC (Bitcoin) 9

🤝 Open Source & Contributions

This project is open source and welcomes contributions from developers, students, and enthusiasts interested in trading infrastructure, distributed systems, and Kafka-based architectures.

🧭 How to Contribute


  1. Fork the repository
  2. Create a new branch for your feature or fix
git checkout -b feature/your-feature-name
  1. Commit your changes
git commit -m "Add: your feature description"
  1. Push to your fork
git push origin feature/your-feature-name
  1. Submit a Pull Request (PR) with a clear explanation of your change 10

🧾 Contribution Guidelines


  1. Follow consistent code formatting (Prettier / ESLint recommended)
  2. Add comments where logic is complex or business-critical
  3. Use TypeScript types and interfaces wherever possible
  4. Write descriptive commit messages
  5. Test your changes before creating a PR

Your name will be added to the Contributors section once your PR is merged 🎉 11


👨‍💻 Author

Akash Raj MERN Stack & Backend Developer

🪪 License

This project is licensed under the MIT License — free to use, modify, and distribute with attribution. 12

About

A distributed trading backend inspired by Exness, designed with modular microservices for performance and scalability.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published