How Zerodha optimizes its 20TB of data?

On peak traffic, despite having a heavy "hot" cache layer, the warehouse DB serves up to 40-50,000 queries per second. Instead of normalizing their data, they denormalized it because JOINs across tables holding billions of rows is difficult to scale.

ON THIS PAGE

The 100cr salary of @zerodhaonline founders is not eye-opening to me, but the tech and how they operate on such a large scale is to me. How do they optimize their database with close to 20TB of data? A 🧵

@zerodhaonline stores financial and transactional data on their PostgreSQL instances. With billions of rows that power their Console and its large-scale number crunching and reporting.

On peak traffic, despite having a heavy “hot” cache layer, the warehouse DB serves up to 40-50,000 queries per second. Instead of normalizing their data, they denormalized it because JOINs across tables holding billions of rows is difficult to scale.

After a lot of experimentation, they partitioned their data to group records by months based on their timestamps. They even experimented with per-day partitioning that significantly boosted their bulk inserts speed but slowed down query speed.

Per-month partitioning turned out to be a far better trade-off. They removed auto-increment IDs and tuned parameters of PostgreSQL that I won’t discuss in this post, but they turned the knobs to gain performance after experimenting.

Due to the nature of bulk inserts and updates of billion rows in batches that @zerodhaonline does aftermarket hours, they turned auto-vacuum off. If auto-vacuum kicks in the middle of the bulk operation, it will lock everything down.

Instead, they had a cron job that does “vacuum analyze” on partitions. Taking care of not over-indexing their DB, they also used materialized views to make the queries faster, and computation for the same queries doesn’t happen repeatedly.

If you found this thread insightful please RT and like the thread. It motivates me to bring high-quality stuff and not post random things. Consider following me for more insightful threads! Also, tag @Nithin0dha and @nikhilkamathcio

Make sense of what's next.

A clear-eyed digest of AI, products, and ideas worth understanding. Join the NextBigWhat newsletter.

Free. Unsubscribe anytime.

more AI news

Disney eyes acquisition of Character.ai amid bankruptcy filing

Disney is considering a potential acquisition of Character.ai, a tech startup that has recently filed for Chapter 11 bankruptcy. The move could allow Disney to integrate advanced AI chatbot technology into its offerings. This acquisition could reshape Disney’s approach to digital interactions and character engagement.

Only 5000 people have fully grasped AI’s potential: Andrej Karpathy

Andrej Karpathy emphasizes that only a small fraction of people, around 5,000, have fully grasped the potential of AI, indicating a growing gap in AI capabilities. Meanwhile, Box CEO Aaron Levie predicts the future of agent swarms in AI, though he notes that most enterprises are currently unprepared to implement such advanced technologies. This highlights the need for increased awareness and readiness among businesses to leverage AI effectively.

Meta AI launches Muse Wonder, advancing personal and professional agent capabilities

Meta AI Research has introduced Muse Wonder, a new frontier model designed for enhancing personal and professional agent functionalities. This innovative model features a Responsive Step and Repeat hero animation, showcasing its advanced capabilities. The development is set to influence how users interact with AI, potentially transforming productivity and user experience.

Google launches synth-id to identify AI-generated content

Google has introduced a standalone platform called SynthID Detector, designed to help users determine if online content was generated using Google AI or its partner tools. This initiative aims to enhance transparency and trust in digital content, amidst growing concerns about the authenticity of AI-generated materials. The tool reflects Google’s commitment to ethical AI usage and the accountability of content creators.

US halts green card access for major IT firms amid H-1B abuse claims

The US Department of Labor has suspended major tech companies, including Microsoft, Infosys, and Cognizant, from the green card program due to allegations of H-1B visa abuse. This decision impacts several prominent IT firms such as TCS, Wipro, and Capgemini, potentially affecting their ability to recruit foreign talent. The move underscores increasing scrutiny on visa practices within the tech industry.