A backend system that simulates market order execution on Solana DEXs with smart routing, asynchronous execution, real-time updates, and persistent order history.
- Market order execution simulation
- Smart DEX routing (Raydium vs Meteora)
- Asynchronous execution using BullMQ and Redis
- Concurrency control and retry with exponential backoff
- Real-time lifecycle updates via WebSockets
- Persistent order history stored in PostgreSQL
- Simple frontend for live order tracking
- Clean, production-style architecture
Client (Postman / Frontend) ↓ Express API ↓ BullMQ Queue (Redis) ↓ Worker (Concurrency + Retry) ↓ DEX Router (Raydium vs Meteora) ↓ Execution Simulation ↓ PostgreSQL (Order History) ↓ WebSocket (Live Status Updates)
| Component | Technology |
|---|---|
| Backend Framework | Node.js + Express |
| Queue & Retry | BullMQ |
| In-memory Store | Redis |
| Database | PostgreSQL |
| Real-time Updates | Socket.IO |
| Frontend | HTML + JavaScript |
| Environment Config | dotenv |
Redis is used to manage active and in-flight orders. BullMQ provides job queuing, concurrency limits, retries, and backoff strategies to ensure non-blocking and resilient execution.
PostgreSQL stores finalized order history. This ensures persistence, auditability, and enables historical queries while keeping Redis focused on transient state.
WebSockets are used to stream real-time lifecycle events to clients, eliminating the need for polling and improving responsiveness.
Each order follows the lifecycle below:
pending routing building submitted confirmed failed
Lifecycle events are streamed via WebSocket, and the final state is persisted in PostgreSQL.
POST /api/orders/execute
json { "tokenIn": "SOL", "tokenOut": "USDC", "amount": 1 }
Response { "orderId": "uuid", "status": "accepted" }
GET /api/orders/history
Returns all past orders stored in PostgreSQL.
Subscribe to Order Updates socket.emit("subscribeOrder", orderId);
socket.on("status", (data) => { console.log(data); });
CREATE TABLE orders ( id UUID PRIMARY KEY, token_in TEXT NOT NULL, token_out TEXT NOT NULL, amount NUMERIC NOT NULL, dex TEXT, price NUMERIC, status TEXT NOT NULL, error TEXT, created_at TIMESTAMP DEFAULT NOW(), completed_at TIMESTAMP );
Create a .env file in the backend root:
PORT=3000
PG_HOST=localhost PG_PORT=5433 PG_USER=postgres PG_PASSWORD=postgres PG_DATABASE=order_engine
REDIS_HOST=127.0.0.1 REDIS_PORT=6379
Start Redis redis-server
Start PostgreSQL
Ensure the PostgreSQL service is running and the database exists.
Install Dependencies npm install
npm run dev
Open the file below in a browser:
frontend/index.html
Submit orders via Postman
Observe lifecycle logs in the terminal
Verify retries and concurrency handling
Check stored orders in PostgreSQL:
SELECT * FROM orders;
Real Solana SDK integration
Limit and sniper order types
On-chain transaction execution
Authentication and user accounts
Metrics and monitoring
Distributed workers
Bull Board monitoring UI
This project is currently demonstrated using local Redis and PostgreSQL instances.
In a production deployment, the backend can be deployed to a cloud platform (Render, Railway, Fly.io) by connecting it to managed Redis and PostgreSQL services.
The application architecture is designed to be cloud-ready, with all infrastructure dependencies externalized via environment variables.
Rajeev Sutrakar, Software Developer