A simple and scalable in-memory opinions trading platform ( like https://probo.in/ ) built with microservices architecture, enabling users to trade on predictions and opinions. The platform consists of three main services: Gateway, Engine, and WebSocket, all connected via Redis for high-performance and low-latency communication.
probo/
├── gateway/ # API Gateway Service
├── engine/ # Core Business Logic Service
├── websocket/ # Real-time WebSocket Service
├── docker-compose.yml
└── README.md
The platform uses a microservices architecture with the following components:
- Gateway Service : API gateway that handles all incoming HTTP requests and forwards them to the engine via Redis queues
- Engine Service : Core business logic service that processes all trading operations, user management, and order matching
- WebSocket Service : Real-time communication service for live orderbook updates and market data streaming
- Redis: Message broker for inter-service communication using pub/sub pattern and request queues
- User Management: Create users and manage their accounts
- Symbol Management: Create and manage trading symbols/stocks
- Balance Management: Handle INR and stock balance operations
- Order Management: Buy, sell, and cancel orders with real-time matching
- Real-time Updates: WebSocket connection for live orderbook updates
- Scalable Architecture: Microservices (gateway api and websocket) with Redis-based communication for easy scaling
-
For containerized setup
- Docker and Docker compose
-
For normal setup
- Node.js (v14 or higher)
- Redis server
- Clone the repository:
git clone "https://github.com/abhayxcode/opinion-trading.git"
cd probo- Start all services using Docker Compose:
docker-compose up --buildThis will start:
- Redis on port 6379
- Gateway service on port 3000
- Engine service on port 8000
- WebSocket service on port 8080
# Install Redis (macOS)
brew install redis
redis-server
# Or install Redis (Ubuntu)
sudo apt-get install redis-server
sudo systemctl start redis-serverCopy .env.example and create .env files in each service directory:
Terminal 1 - Gateway Service:
cd gateway
npm install
npm run devTerminal 2 - Engine Service:
cd engine
npm install
npm run devTerminal 3 - WebSocket Service:
cd websocket
npm install
npm run devFor production deployment:
# Build all services
cd gateway && npm run build
cd ../engine && npm run build
cd ../websocket && npm run build
# Start production servers
cd gateway && npm start
cd ../engine && npm start
cd ../websocket && npm start- Gateway Service:
http://localhost:3000
POST /user/create/:userId- Create a new user
POST /symbol/create/:stockSymbol- Create a new trading symbol
GET /balances/inr- Get all INR balancesGET /balances/inr/:userId- Get INR balance for specific userGET /balances/stock- Get all stock balancesGET /balances/stock/:userId- Get stock balance for specific userPOST /onramp/inr- Add INR to user's account
POST /order/buy- Place a buy orderPOST /order/sell- Place a sell orderPOST /order/cancel- Cancel an existing order
GET /orderbook- Get all orderbooksGET /orderbook/:stockSymbol- Get orderbook for specific symbol
POST /reset- Reset the entire in-memory database
Connect to WebSocket server at: ws://localhost:8080
{
"type": "SUBSCRIBE",
"orderbookId": "STOCK_SYMBOL"
}{
"type": "UNSUBSCRIBE",
"orderbookId": "STOCK_SYMBOL"
}- Backend: Node.js, TypeScript, Express.js
- WebSocket: ws library
- Queue and Pub/Sub: Redis
- Containerization: Docker, Docker Compose
- Development: nodemon, ts-node
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
