This document provides a comprehensive, step-by-step summary of the lecture detailing the system design, financial mechanics, and software architecture behind building a trading exchange like Zerodha.

Part 1: High-Level Functional Requirements

Before building the architecture, it is essential to understand the functional flow of an exchange from the perspective of a user.

  1. User Onboarding and KYC: Users must sign up and complete Know Your Customer (KYC) verification (e.g., providing government IDs) to connect a valid Demat account.
  2. Account Balances: Upon successful registration, the user has a zero balance in both fiat currency (e.g., INR, USD) and assets (e.g., stocks).
  3. Funding the Account: The user deposits fiat currency from their bank account into the exchange wallet.
  4. Trading Assets: * Buying: A user can buy a specific quantity of an asset at a given price. The fiat balance is debited, and the asset balance is credited.
  1. Withdrawal: The user can withdraw their new fiat balance back to their bank account.

Part 2: Core Financial Mechanics and Jargon

To build a trading system, specific financial concepts dictate the logic of the code.

1. Price Determination (Supply and Demand)

The price of any asset on an exchange is strictly determined by supply and demand, not by the company itself.

2. The Order Book

The Order Book is a public ledger maintained by the exchange that shows all current, unmatched orders.