A high-performance backend system for executing Solana DEX Market Orders with intelligent routing, concurrent background workers, real-time WebSocket updates, and an extensible job-based architecture.
This project demonstrates concurrency, queues, workers,WebSockets, and Mock DEX price routing.
Market orders were implemented first because they:
-
Require instant execution
-
Stress-test latency, routing, and concurrency
-
Exercise the full pipeline:
API โ Queue โ Worker โ Router โ DB โ Pub/Sub โ WebSocket -
Showcase real-time updating via Fastify WebSocket + Redis Pub/Sub
This forms a strong foundation for future order types.
Built on BullMQ, enabling new order types without refactoring core logic.
A Price Watcher service can enqueue jobs once the target price is hit.
A Mempool Listener can enqueue jobs during liquidity spikes.
The core pipeline remains the same:
Routing โ Execution โ Database Updates โ WebSocket Events
graph LR
Client[Client] -- POST /execute --> API[Fastify API]
Client -- WebSocket --> WS[WS Gateway]
API -- Queue job --> Queue[BullMQ]
Queue -- Process --> Worker[Background Worker]
Worker -- Fetch Quotes --> Router[DEX Mock Router]
Worker -- Execute Swap --> SolanaMock[Solana Mock Execution]
Worker -- Update --> DB
Worker -- Publish --> RedisPub[Redis Pub/Sub]
RedisPub -- Push --> WS
WS -- Notify --> Client
drizzle/ # Database migrations
src/
โโโ db/ # Drizzle ORM schemas
โโโ services/ # Queue setup
โโโ test/ # Automated tests + load tests
โโโ utils/ # Redis setup
| โโโ redisConnection.ts
โโโ dex-mock-router.ts # Simulates Raydium/Meteora best routing
โโโ server.ts # Fastify HTTP + WebSocket server
โโโ types.ts # Interface, enums, validations
โโโ worker.ts # BullMQ order execution worker
โโโ .env # Environment variables
โโโ drizzle.config.ts
โโโ package.json
โโโ tsconfig.json
โโโ readme.md
| Component | Tech |
|---|---|
| Runtime | Node.js + TypeScript |
| API Framework | Fastify |
| Queue System | BullMQ |
| Messaging | Redis Pub/Sub |
| Database | PostgreSQL + Drizzle ORM |
Create a .env file:
PORT=3000
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/eterna_orders"
REDIS_HOST="localhost"
REDIS_PORT=6379
HOST="localhost"
ENDPOINT=/api/orders/executenpm run dev # Start API (watch mode)
npm run worker # Start BullMQ worker
npm run db:push # Apply Drizzle migrations
npm run build # Compile TS โ JS
npm start # Start prod servernpm installnpm run db:pushnpm run startSingle order:
npx ts-node src/test/client-test.tsConcurrent load test:
npx ts-node src/test/concurrent-load-test.tsSubmit a market order.
{
"inputToken": "SOL",
"outputToken": "USDC",
"amount": 10
}{
"orderId": "uuid",
"message": "Order placed successfully!"
}Connect to the same endpoint:
GET /api/orders/execute?orderId=<id>
{ "event": "pending" }
{ "status": "routing" }
{ "status": "building" }
{ "status": "confirmed" }
{ "status": "failed" }Worker runs with 10 concurrent jobs.
3 retries with exponential backoff.
Simulates:
- Raydium
- Meteora
- Best-price selection
- Real Solana DEX integration (Raydium/Meteora)
- Limit order engine
- Sniper orders via mempool monitoring