At work, we run a multi-primary MySQL system with roughly 20 billion rows across six tables and 14.8 TiB of stored data. The system spans three regions, each with one primary and two local replicas, with replication pipelines connecting the system.
The tables aren't partitioned, and the system isn't sharded. Yet, our queries are still surprisingly fast. The reason is that the data we repeatedly access is much smaller than the data we keep, and nearly all of the active data fits in memory.
One primary per region
Each instance has 32 cores and about 238 GiB of RAM. InnoDB's buffer pool is a RAM cache for data and index pages. Ours is 100 GiB: less than 1% of the stored dataset. The disk is about 75% full, with roughly 6.1 TiB free.
The hardware each MySQL instance runs on
The active data fits in memory
Most rows stop changing after about two weeks. Of the rows changed in the last week, 99.96% were created in the last 12 days. Older rows remain available, but this workload rarely reads or updates them.
Two weeks of recent rows, together with the upper levels of every index, are estimated to occupy about 33–56 GiB. These are the routing pages that point lookups repeatedly visit, plus the recent row and index pages those lookups reach. This dataset fits comfortably in memory without pushing the limits of the 100GiB buffer pool. The remaining 14+ TiB of data sits dormant on disk.
The active data fits in memory
Our primary-key IDs increase over time, so recent rows tend to occupy nearby pages in InnoDB's clustered index, which stores rows in primary-key order. Repeated reads keep the useful pages hot while most older history stays on disk.
Reads favor recent rows
The observed buffer-pool hit rate is 98.7%. In other words, a cache smaller than 1% of the stored data serves 98.7% of page reads from memory.
Most reads stay in memory
Across the three primaries combined, we see about 10,000 SELECTs per second, with roughly one write per 100 reads. Most requests are point lookups or lookups on indexed columns, returning only a small number of rows.
Read traffic over 24 hours
InnoDB uses B+ trees, whose internal pages route a lookup toward one leaf page. Even a table containing 20 billion rows can have an index only about four levels deep. For example, with 100 rows per leaf page and 1,000 child pointers per internal page, a root, two intermediate levels, and a leaf level can address 100 billion rows.
Four levels to a row
Level 1: the cached root chooses a branch.
The upper levels are small enough to stay cached. A primary-key lookup can then follow those routing pages in memory and fetch only the leaf containing the row. A secondary-index lookup may also traverse the clustered index to retrieve the full row, unless the secondary index covers the query.
A query that needs a disk page can take roughly 10× as long as one served entirely from memory. Keeping almost all page reads in memory makes the slower path uncommon. This is essential to understanding why our system remains fast despite being large.
Why we haven't needed sharding or partitioning
A large row count alone doesn't make these indexed lookups expensive. Partitioning would help if our queries could prune away partitions, or if we needed to manage retention by dropping whole partitions. Here, indexes already narrow requests to a few pages, and the active pages fit in memory. Partitioning isn't necessary to achieve that access pattern. Sharding would spread storage and work across machines, but it would also introduce routing and cross-shard coordination that this workload hasn't needed.
We are planning a migration to TiDB in the future, but the rationale won't be because our current system can't scale. Instead, it can improve system resilience by avoiding a single-point-of-failure:
What would break this
This depends on how the data is used. It would weaken if:
- Reads spread across old history, or large scans displace frequently used pages from the buffer pool.
- Rows stay active for longer, or wider rows and more indexes push the working set beyond the pool.
- Queries lose useful indexes or start returning many rows, increasing the pages touched per request.
- Writes rise enough to make locking, page flushing, or replication the bottleneck.
A restart or failover can also expose a cold cache while useful pages warm up again. But again, this is unlikely due to the active set being recent.
Conclusion
The database keeps 14.8 TiB of history, but ordinary requests repeatedly use a much smaller set of pages. About 33–56 GiB of recent data and index routing pages fits in a 100 GiB cache. Combined with small indexed lookups, that explains how billions of rows coexist with a high cache hit rate and fast queries.