Skip to content

Repository files navigation

Order Execution Engine

A high-performance backend system designed to execute Market Orders with smart DEX routing, real-time WebSocket updates, and concurrent processing. Built with Node.js, TypeScript, and Redis queues.

Live Demo: https://order-execution-engine-three.vercel.app

🚀 Features

  • Smart DEX Routing: Simulates price comparison between Raydium and Meteora to find the best execution path.
  • [cite_start]Concurrent Processing: Uses BullMQ and Redis to handle up to 10 concurrent orders safely[cite: 57].
  • [cite_start]Real-time Updates: Full WebSocket support streams order status (pending → routing → confirmed) to the client[cite: 10, 15].
  • [cite_start]Reliable Storage: Persists order history in PostgreSQL (Neon) and active queues in Redis (Upstash)[cite: 66].
  • [cite_start]Scalable Architecture: Built with Fastify for low-overhead, high-performance API handling[cite: 64].

🛠 Tech Stack

  • Runtime: Node.js & TypeScript
  • Framework: Fastify
  • Database: PostgreSQL (Neon)
  • Queue/Cache: Redis (Upstash) & BullMQ
  • Deployment: Vercel

🧠 Design Decisions

Why Market Orders?

I chose to implement Market Orders as the primary order type because they prioritize speed of execution over price precision. In a high-frequency environment like Solana, ensuring a transaction lands on-chain immediately is critical.

  • Extensibility: To support Limit Orders, the engine would simply need a "price watcher" service that triggers the existing execution flow only when the market price matches the target. [cite_start]Sniper Orders would similarly add a "block watcher" to trigger execution upon a liquidity pool creation event[cite: 11].

Architecture Choice

I separated the API (Fastify) from the Worker (BullMQ). This ensures that heavy processing (routing calculations and database writes) never blocks the main thread, allowing the API to remain responsive even under high load.

⚙️ Setup Instructions

Prerequisites

  • Node.js (v18+)
  • Redis (Local or Upstash)
  • PostgreSQL (Local or Neon)

Installation

  1. Clone the repository: git clone https://github.com/archithaj06/order-execution-engine.git cd order-execution-engine 2.Install dependencies: npm install 3.Configure Environment: Create a .env file in the root directory: DATABASE_URL="postgresql://user:pass@host/db?sslmode=require" REDIS_URL="rediss://default:pass@host:6379" PORT=3000 4.Run Locally: npm run dev

🧪 Testing Running Tests The project includes unit and integration tests for the router and queue system. npm test

###API Endpoints (Postman)

Method Endpoint Description
POST /api/orders/execute Submit a new order.
GET /health Check system status.
WS /api/orders/ws/:orderId Connect via WebSocket for updates.

📹 Video Demo [Link to YouTube Video Demo]

git clone [https://github.com/archithaj06/order-execution-engine.git](https://github.com/archithaj06/order-execution-engine.git)
cd order-execution-engine

Releases

Packages

Contributors

Languages