Explore the technical architecture and implementation details of a high-performance trading engine.

The system follows a microservices architecture with three core components communicating through Redis streams. Real-time price data flows from external exchanges through WebSocket connections, gets processed by the trading engine, and triggers automatic liquidations based on leverage and risk parameters.
The trading engine processes orders through Redis streams with real-time price validation:
Automatic liquidation system runs on every price update:
Connects to Backpack Exchange for real-time BTC_USDC price feeds:
Streams bid/ask prices directly to the trading engine via Redis.
Every price update triggers immediate liquidation checks:
JWT-based authentication with middleware protection:
Complete order management with async communication:
The system implements an asynchronous request-response pattern using Redis streams as a message bus and an in-memory callback registry. This enables non-blocking communication between the API service and the trading engine while maintaining request-response semantics.
The sendRequestAndWait function orchestrates two parallel operations:
Each message contains:
The callback is stored in an in-memory map keyed by the correlation ID, with automatic cleanup on timeout.
The engine service runs a continuous loop that consumes from the engine-stream:
A separate subscriber loop continuously listens for callbacks:
When a callback arrives, the subscriber immediately resolves the corresponding Promise, unblocking the original API request and allowing it to return the response to the client.
createOrder, generates unique ID, builds payloadsendRequestAndWait(id, payload) which executes both operations in paralleladdToStream publishes message to engine-stream via XADDwaitForMessage creates Promise, registers callback in memory map with 5s timeoutrunLoop receives callback, extracts ID, finds matching callback in mapthis.callbacks[callbackId]() to resolve Promise, deletes callback from mapSet up your development environment and start building with 100xness. Join the world of limitless trading opportunities.