Stock Broker System (HLD)

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-02-07

Problem Statement

Design a scalable, fault-tolerant, and low-latency stock broker system that enables users to:


1.<span></span>Place, modify, and cancel stock orders (market, limit, stop-loss, etc.).
2.<span></span>Execute trades by integrating with external stock exchanges.
3.<span></span>Provide real-time portfolio updates (holdings, margins, P&L).
4.<span></span>Stream market data (live price feeds, order book updates, charts).
5.<span></span>Ensure regulatory compliance and risk management (audit logs, exposure checks, KYC).


The system must handle millions of orders per day and thousands of concurrent users while maintaining high availability and security.


Requirements


Functional


1.<span></span>Account & Wallet Management – onboarding, funds, deposits/withdrawals. Order Lifecycle – create, validate, modify, cancel orders.
2.<span></span>Trade Execution – connect to exchanges, ensure low-latency execution, handle partial fills.
3.<span></span>Portfolio Service – track holdings, margins, exposure, P&L in real-time.
4.<span></span>Market Data Service – provide live tick data, historical price charts, order books.
5.<span></span>Risk & Compliance – margin checks, regulatory logging, fraud detection.


Non-Functional


1.<span></span>Low Latency – order execution within milliseconds.
2.<span></span>Scalability – millions of trades & concurrent users.
3.<span></span>Reliability – no order loss, recoverable failures.
4.<span></span>Security – secure authentication, encryption, fraud detection.
5.<span></span>High Availability – 24x7 uptime with redundancy & failover.


Components to Consider (HLD Scope)


1.<span></span>API Gateway – REST/WebSocket APIs for users.
2.<span></span>Order Management System (OMS) – validates, queues, and routes orders.
3.<span></span>Exchange Connector – communicates with stock exchanges.
4.<span></span>Portfolio & Risk Engine – updates holdings, performs compliance & exposure checks.
5.<span></span>Market Data Service – ingests live feeds, pushes updates to clients.
6.<span></span>Persistence Layer – relational DB (orders, users, trades), time-series DB (market data), message queues for event-driven updates.


Key Design Challenges


1.<span></span>Designing for high-throughput, low-latency trade execution.
2.<span></span>Ensuring atomic order validation and placement under concurrent load.
3.<span></span>Managing real-time data streaming at scale.
4.<span></span>Trade-off between consistency (ACID) vs availability/performance.


Solution

Comments