Built a crypto exchange simulator to learn system design.
Real-time order matching
Market & limit orders
Fund locking & balance validation
WebSocket-based updates
No real money involved.
Demo π
https://t.co/6g76ranvE5
Please review @kirat_tw
@saen_dev Trade-off: Sequential processing per pair does limit throughput to X orders/second per pair, but ensures correctness. For most trading scenarios outside HFT, this is acceptable.
Built a crypto exchange simulator to learn system design.
Real-time order matching
Market & limit orders
Fund locking & balance validation
WebSocket-based updates
No real money involved.
Demo π
https://t.co/6g76ranvE5
@saen_dev WebSocket Latency: The matching engine runs in a separate microservice and publishes results to Redis pub/sub. WebSocket servers are pure broadcast layers with no business logic, so they can scale horizontally. For HF scenarios, batching updates to reduce per-message overhead.
@saen_dev Race Conditions: The engine uses a singleton pattern per trading pair, processing orders sequentially through a message queue. While this sacrifices some parallelism, it eliminates race conditions entirely and ensures deterministic order matching.
@saen_dev Order Book Structure: I'm using a sorted map structure in Redis with price levels as keys. Each price level maintains a queue of orders (FIFO at same price), which handles the priority naturally - time priority within price priority.
@saen_dev I am managing it though redis and redis is just pushing things into websocket after all the matching and calculations it's like a pub/sub so there is no such load in ws layer and it's a microservices structure so it's more efficient as well balanced
Built a crypto exchange simulator to learn system design.
Real-time order matching
Market & limit orders
Fund locking & balance validation
WebSocket-based updates
No real money involved.
Demo π
https://t.co/6g76ranvE5
Please review @kirat_tw