Designing a Scalable Stock Broker Platform: A System Design Deep Dive

Table of contents

Introduction

In today’s fast-paced financial markets, stock broker platforms like Zerodha, Groww, and INDmoney serve millions of users who demand real-time data, instant order execution, and high reliability. Building such a system requires a deep understanding of distributed systems, real-time communication, data consistency, and scalability.

In this article, we’ll dissect a real-world system design interview where the candidate is tasked with designing a stock broker platform from scratch. We’ll walk through the key decisions, trade-offs, and architectural patterns used to build a robust, scalable, and low-latency system that can handle billions of requests per day while ensuring data integrity and user experience.

Whether you’re preparing for a system design interview or building a fintech product, this breakdown will give you actionable insights into how to design for performance, consistency, and resilience.

Functional and Non-Functional Requirements

The primary goal is to design a stock broker platform — not the stock exchange itself. The exchange (e.g., NSE, BSE) is assumed to exist and handle order matching, clearing, and settlement. Our system acts as the intermediary between users and the exchange.

Functional Requirements:

Non-Functional Requirements:

Traffic assumptions:

This makes the system read-heavy, especially on price data.

High-Level Architecture Overview

The system is composed of several microservices and external integrations:

Order Processing Flow

Real-Time Price Flow

SSE from Exchange

e.g., NSE/BSE

Forward Orders

Webhook: Order Status Update

External Systems

User Clients

API Gateway

Price Service

Order Management Service OMS

SSE to Clients

Real-Time Price Updates

Exchange Gateway Processor

Time-Series DB

e.g., TimescaleDB

Order DB

PostgreSQL / RDS

Kafka

Order Queue

Stock Exchange

Key components:

Real-Time Stock Price Distribution with SSE and Time-Series DB

Why Not WebSockets?

Clients need real-time price updates, but not two-way communication. WebSockets would be overkill and resource-intensive, especially if a user monitors multiple stocks (each requiring a separate connection). Instead, Server-Sent Events (SSE) are used:

Architecture Flow:

  1. The Exchange Gateway Processor subscribes to real-time price feeds from NSE/BSE via SSE.
  2. Incoming price ticks are:
    • Stored in a Time-Series Database (e.g., TimescaleDB) for historical queries.
    • Pushed to the Price Service via a pub/sub mechanism (e.g., Redis Pub/Sub for low-latency push).
  3. The Price Service broadcasts updates to subscribed clients via SSE.

Handling New Users (Catch-Up Logic):

Data Model (Time-Series DB):

Table: stock_price_history
- symbol: VARCHAR (e.g., INFY)
- timestamp: TIMESTAMPTZ
- price: DECIMAL
- volume: INTEGER

Index: (symbol, timestamp)
Partitioning: By time (daily or hourly chunks)
Sharding: By symbol (high-volume stocks on dedicated nodes)

Order Management System and Asynchronous Processing

Why Not Direct API Calls?

Directly forwarding orders to the exchange under high load risks:

Solution: Asynchronous Processing with Kafka

  1. User submits order → OMS receives it via POST /api/v1/order.
  2. OMS validates and persists the order in Order DB with status PENDING.
  3. Order is published to Kafka for async processing.
  4. Exchange Gateway Processor consumes from Kafka and forwards orders to the exchange.
  5. Exchange returns an exchange_order_id → OMS updates the record.
  6. Exchange sends webhook on status change (filled, rejected, canceled).

Data Model (Order DB):

Table: orders
- order_id: UUID (Primary Key)
- user_id: UUID
- symbol: VARCHAR
- order_type: ENUM('BUY', 'SELL')
- price_type: ENUM('MARKET', 'LIMIT')
- limit_price: DECIMAL (nullable)
- quantity: INTEGER
- status: ENUM('PENDING', 'PLACED', 'FILLED', 'CANCELLED')
- exchange_order_id: VARCHAR (nullable)
- created_at: TIMESTAMPTZ
- updated_at: TIMESTAMPTZ

Handling Failures:

Scalability, Consistency, and Latency Optimizations

1. Hybrid Scaling Strategy

2. Co-Location with Exchange

3. Smart Load Balancing

4. Database Optimizations

5. Push-Based Internal Communication

Handling Surge Traffic and Rate Limiting

During market open/close, traffic spikes dramatically. To manage this:

1. Backpressure via Kafka

2. Rate Limiting at Gateway

3. Tiered Data Freshness

4. Pre-Scaling for Known Peaks

Conclusion

Designing a stock broker platform is a complex but rewarding challenge that sits at the intersection of real-time systems, financial integrity, and massive scale. The key takeaways from this design are:

This system not only handles the scale but also ensures that users can trade with confidence — knowing their orders won’t get lost and their data is accurate.

See you on the next post.

Sincerely,

Eng. Adrian Beria.