Design an Order Matching Engine
Command PatternStrategy PatternObserver PatternPriority QueueConcurrency
Design an order matching engine for a stock exchange that processes buy and sell orders, maintains an order book, and executes trades based on price-time priority matching. The system should handle order submission, matching algorithms, trade execution, and notify interested parties about trades and order book updates. The design should be thread-safe, performant, and support concurrent order processing.
What You'll Build
- The system should accept and store buy and sell orders with details such as order ID, timestamp, stock symbol, price, quantity, and order type (limit/market).
- Orders should be organized in an order book, with separate books for buy orders and sell orders, sorted by price-time priority.
- The system should match orders based on price-time priority: higher-priced buy orders and lower-priced sell orders are prioritized, and within the same price, earlier orders are matched first.
- When a buy order's price is greater than or equal to a sell order's price, a trade should be executed at the sell order's price (price-time priority).
- The system should handle partial fills when order quantities don't match exactly, keeping the remaining quantity in the order book.
- ...and more
🎯
Step-by-Step Guidance
Follow our systematic 8-step approach to design the system from scratch. Learn how to identify actors, assign responsibilities, and create class diagrams.
📊
Interactive UML Builder
Build class diagrams visually with our drag-and-drop UML editor. Connect classes, define relationships, and see your design come to life.
💻
Multi-Language Support
Practice in Python, Java, C++, TypeScript, JavaScript, or C#. Get complete solutions and explanations in all supported languages.
🤖
AI-Powered Review
Get instant feedback on your design and code. Our AI reviews your implementation and suggests improvements based on best practices.
📚
Design Patterns
Learn how to apply design patterns like Command Pattern, Strategy Pattern and more. Understand when and why to use each pattern.
✅
Complete Solutions
Access detailed solutions with explanations, UML diagrams, and code implementations. Learn from industry best practices.
🐍 Python ☕ Java 📘 TypeScript 🟨 JavaScript ⚡ C++ 🟣 C#
Ready to Master This Problem?
Join thousands of developers practicing Low Level Design. Build your design step-by-step, get AI feedback, and learn from complete solutions.
🚀 Start Practicing Now