Ravindra BagaleCourses & study guides Track your progress

Guides

Zerodha Architecture Explained: How India's Largest Broker Self-Hosts Its Stack

Short answer: Zerodha self-hosts almost everything using free and open-source software. Its systems run in a hybrid setup: physical racks in two data centres where stock exchange leased lines end, plus AWS (2020). Services are written mainly in Go and Python. Data lives in self-managed PostgreSQL on bare EC2 instances (about 20 TB across four shards in 2021), logs in ClickHouse (2023), and metrics in Prometheus and VictoriaMetrics.

Suppose you buy shares on Zerodha Kite

It is 9:20 am. You buy 10 shares on Kite from Pune. In simple terms:

  1. Kite (built with Flutter on mobile) sends your order to Zerodha's in-house systems.
  2. Order systems run near the exchange leased lines in Zerodha's data centres, so orders reach NSE or BSE quickly.
  3. Services written in Go check rules and margins.
  4. After the market closes, end-of-day jobs load exchange files into large PostgreSQL databases for Console (P&L, ledger, reports).
  5. That night, a self-hosted pipeline on EC2 and S3 generates, digitally signs and emails 1.5+ million contract note PDFs in about 25 minutes (2024).
  6. All logs go to ClickHouse; metrics to VictoriaMetrics.

What architecture style does Zerodha use?

Zerodha is famous for a tiny tech team (about 30 people in 2020) and a "simple scales" philosophy.

  1. Self-host FOSS: Zerodha's stack page lists self-hosted tools: Go, Python, Java, Dart; PostgreSQL, ClickHouse, Redis, ScyllaDB, MySQL; Nginx, HAProxy, Kong; NATS, Kafka; Nomad, Salt, GitLab.
  2. Scale the application before the infrastructure (2020): keep networking and IO minimal, and prefer simple designs.
  3. Hybrid hosting: two data centres plus AWS, bare metal to Kubernetes clusters.
  4. Batch work on raw EC2: short-lived EC2 instances and S3 for big jobs like contract notes, instead of managed services.

Zerodha architecture diagram (public parts)

This diagram shows only what Zerodha or its partners have shared publicly. Press Play to follow a request step by step.

Watch the orange dot follow each numbered step.
Zerodha architecture from public information (simplified)Two data centres (exchange leased lines) + AWSBatch and storage on AWSSimplified; based on publicly shared information.TraderKite app (Flutter), webNginx / HAProxy / KongproxiesIn-house servicesGo, PythonPostgreSQLself-hosted on EC2, shardedRediscachingKafka + NATSstreams, queuesPrometheus + VictoriaMetricsGrafana, AlertmanagerEC2 + S3 jobs1.5M PDFs in 25 min
  1. You place a buy order on Kite.
  2. Self-hosted proxies route it.
  3. Go services check and send the order.
  4. Reports come from large PostgreSQL databases.
  5. Hot data is cached in Redis.
  6. Events move through Kafka and NATS.
  7. Prometheus and VictoriaMetrics watch everything.
  8. Contract notes are made on EC2 and stored in S3.
  9. Your order is filled.
Diagram 1: the public parts of Zerodha's architecture. Simplified; based only on publicly shared information. Open the diagram as an image (PNG) · WebP

What does Zerodha use? Main technologies

LayerWhat Zerodha uses (public)What it does in simple words
HostingTwo data centres + AWSHybrid setup
LanguagesGo, Python, Java, DartServices and apps
MobileFlutterKite app
DatabasePostgreSQL (self-hosted on EC2)Trades, P&L, ledger
LogsClickHouse + Vector (2023)Log storage and search
QueuesKafka, NATSMessaging
MonitoringPrometheus, VictoriaMetrics, GrafanaMetrics and alerts
OrchestrationNomad, Salt, KubernetesDeploy and manage

Which cloud provider does Zerodha use?

Zerodha uses a hybrid setup: physical racks in two data centres (where exchange leased lines end) and AWS. On AWS it mostly uses raw EC2 instances, EBS snapshots and S3, and runs its own software on them rather than using many managed services.

How does Zerodha send 1.5 million contract notes in 25 minutes?

Every trading day, SEBI rules require brokers to send each client a digitally signed contract note before the next trading day. Since 2024 Zerodha uses a self-hosted pipeline:

  1. Each note passes through four kinds of workers: process data, generate the PDF (from Typst markup), digitally sign it, and email it.
  2. Work is split into jobs that run on many short-lived EC2 instances, started only for the duration of the work.
  3. Workers read input files from S3, process them and write the output back to S3 for the next worker.
  4. Zerodha compared EBS, EFS and S3 for this shared storage and picked S3 for cost and simplicity; AWS also suggested FSx for Lustre.
  5. Its earlier self-hosted Postal mail server became a bottleneck as volume grew, which was one reason to redesign.

The result: more than 1.5 million PDFs generated, signed and emailed in about 25 minutes at negligible cost, and the same orchestration ideas now power other distributed jobs. It is a good example of Zerodha's rule: scale the application design before throwing infrastructure at a problem.

How it started: a 30-person team builds India's largest broker (2013 to 2020)

  1. Zerodha was founded in 2010; its tech team started around 2013.
  2. By 2020 a team of about 30 had built the trading platform, back office and reporting in-house; Zerodha handled about 15% of daily retail trading volume in India.
  3. In 2018 Zerodha bet on Flutter for its mobile apps while Flutter was still in alpha, after trying native and React Native.
  4. Logs ran on the ELK stack from 2018 until traffic grew sharply after 2020, which led to the ClickHouse move.

How does Zerodha store data?

  1. PostgreSQL: hundreds of billions of rows, about 20 TB across four shards (2021); a separate Postgres instance acts as a hot cache; up to 40,000 to 50,000 queries per second at peak.
  2. AWS disk snapshots for backups; failover replicas for availability.
  3. ClickHouse for logs, some kept long-term for regulators.
  4. S3 for temporary files in batch jobs.

How does Zerodha monitor its systems?

  1. Prometheus with Grafana, and VictoriaMetrics for long-term storage, across both data centres and AWS (2020).
  2. Monitors system, application and business metrics.
  3. ClickHouse + Vector for logs; Alertmanager and Sentry are on the stack page.

If we built an app like Zerodha on AWS (illustrative)

Please read this first

This section is a learning design by Ravindra Bagale. It is not Zerodha's real setup. Zerodha uses AWS together with its own data centre racks. We use AWS here because it is what you learn in the AWS course.

Suppose you want to build "NiveshKaro", a simple investing app for mutual funds. Here is a simple AWS layout. A real broker must also connect to exchanges and follow SEBI rules.

1. Network: VPC, subnets, route tables, gateways

  1. Create one VPC with CIDR 10.0.0.0/16 in the Mumbai region (ap-south-1).
  2. Use two Availability Zones (A and B), so one AZ failing does not stop the app.
  3. In each AZ make three subnets: public (load balancer, NAT gateway), private app (your code) and private data (databases, cache).
  4. Attach one internet gateway (IGW) to the VPC. Public route table: 0.0.0.0/0 → IGW. This route is what makes a subnet public.
  5. Private app route table: 0.0.0.0/0 → NAT gateway, so servers can download updates but nobody can connect in from the internet.
  6. Private data route table: only the local VPC route. Use VPC endpoints to reach S3, DynamoDB and SQS without going over the internet.

2. Compute: where the code runs

  1. ALB in public subnets.
  2. Go services on EKS.
  3. Night batch jobs read SQS on Spot instances.

3. Storage and databases

  1. Aurora PostgreSQL for the ledger.
  2. DynamoDB for order history.
  3. ElastiCache for quotes; S3 for contract notes.

4. Monitoring

  1. Amazon Managed Prometheus + Grafana.
  2. CloudWatch Logs or self-hosted ClickHouse.

Request flow diagram

Press Play. The numbered list below the diagram lights up with each step.

Watch the orange dot follow each numbered step.
If we built a Zerodha-like app on AWS (illustrative)AWS Region (for example ap-south-1, Mumbai)VPC 10.0.0.0/16Availability Zone AAvailability Zone BPublic subnet 10.0.1.0/24RT: 0.0.0.0/0 → IGWPublic subnet 10.0.2.0/24RT: 0.0.0.0/0 → IGWApp subnet 10.0.11.0/24RT: 0.0.0.0/0 → NATApp subnet 10.0.12.0/24RT: 0.0.0.0/0 → NATData subnet 10.0.21.0/24RT: local onlyData subnet 10.0.22.0/24RT: local onlyvia VPC endpointsIllustrative learning design only. This is NOT the company's real setup.Userphone appRoute 53DNS lookupCloudFrontCDN edge cacheAmazon S3contract notesIGWApplication Load Balancerspans both AZsNAT gatewayNAT gatewayTrading APIEKS pods (auto scaling)Trading APIEKS pods (auto scaling)ElastiCachequotes, sessionsAuroraaccounts, ledgerElastiCachequotes, sessionsAuroraread replicaSQSEOD and PDF jobsDynamoDBorder historyCloudWatch + X-Raymetrics, logs, traces
  1. You open NiveshKaro. Route 53 answers.
  2. Static files via CloudFront.
  3. From S3.
  4. API calls through the internet gateway.
  5. The ALB forwards to a pod.
  6. The trading API checks your order.
  7. Quotes from ElastiCache.
  8. Ledger in Aurora; history in DynamoDB.
  9. Contract note job goes to SQS.
  10. CloudWatch watches.
  11. Order placed.
Diagram 2: an illustrative AWS design for learning. Zerodha does not necessarily run like this; see the sections above for what is publicly known. Open the diagram as an image (PNG) · WebP

Zerodha versus our AWS design

PartZerodha (public info)Our AWS design
HostingTwo DCs + AWSAWS only
PhilosophySelf-host FOSS on raw EC2Managed services
DatabaseSelf-hosted PostgreSQLAurora PostgreSQL
LogsClickHouseCloudWatch Logs
MonitoringPrometheus, VictoriaMetricsManaged Prometheus

Quick quiz: check what you learned

  1. What does Zerodha prefer for its software?

    1. Self-hosted open-source tools
    2. Only paid SaaS tools
    3. Mainframes
    4. No databases
    Show answer

    A. Zerodha self-hosts FOSS tools.

  2. Where are Zerodha's physical racks placed?

    1. In the office
    2. In data centres where exchange leased lines end
    3. On ships
    4. In phones
    Show answer

    B. Two data centres where leased lines terminate.

  3. What did Zerodha move its logs to in 2023?

    1. Excel
    2. Oracle
    3. ClickHouse
    4. Floppy disks
    Show answer

    C. Zerodha moved from ELK to ClickHouse and Vector.

  4. How fast does Zerodha make 1.5+ million contract notes?

    1. 10 hours
    2. 3 days
    3. 1 week
    4. About 25 minutes
    Show answer

    D. About 25 minutes (2024).