跪拜 Guibai
← All articles
Backend

How YouTube Stores Its Massive Video Archive: Sharding, Vitess, and Spinning Disks

By 皮皮林551 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Any platform with heavy storage demands can reuse YouTube's pattern of serving hot content from CDN while archiving to cheap spinning disks, and using Vitess to keep MySQL sharding manageable without burning RAM on connection overhead.

Summary

YouTube's backend runs on a sharded MySQL cluster managed by Vitess, a database clustering system the company created to handle horizontal scaling without forcing shard logic into application code. Vitess handles sharding, failover, backup, and connection pooling; each MySQL connection normally costs 2MB of RAM, but Go-based pooling in Vitess cuts that overhead. The system runs on Kubernetes in a containerized environment, with Zookeeper coordinating nodes.

For the video files themselves, YouTube stores them on spinning hard drives in commodity servers, which are replaced rather than repaired when they fail. The platform adds more than a petabyte of new storage capacity every day because users upload over 500 hours of video per minute. Metadata, user preferences, account settings, and the indexes needed to fetch video all live in MySQL. The hot videos are served from CDN edge points; the long tail of less popular content is pulled from the database.

The architecture deliberately trades consistency for speed: read replicas can return slightly stale view counts, but videos render without waiting for the primary to sync. SSDs are rejected for archival storage because they are expensive and degrade over time, so rotating disks carry the bulk of the data.

Takeaways
— YouTube receives over 500 hours of video uploads per minute and serves more than a billion hours of video daily.
— Vitess is a database clustering system for MySQL that handles sharding, failover, backup, and connection pooling; it runs on Kubernetes and uses Zookeeper.
— Each MySQL connection at YouTube has a 2MB overhead, which Vitess reduces via Go-based connection pooling.
— Sharding spreads data across machines to increase write throughput; replicas handle read traffic and can serve stale data, which YouTube accepts for view counts.
— YouTube stores video on commodity servers with spinning hard drives, replacing failed units instead of repairing them; it adds over a petabyte of new storage per day.
— SSDs are avoided for archival storage because they are expensive and degrade over time.
— Frequently watched videos are served from CDN edges; less popular ones are fetched from the database.
Conclusions

YouTube's tolerance for stale read replicas shows a deliberate consistency trade-off: view counts are eventually consistent, but video playback must be immediate, so the system prioritizes rendering speed over perfect accuracy.

Vitess exists because hand-coded sharding is painful; moving shard logic into the framework lets developers write normal SQL while the system routes queries, a pattern that generalizes to any relational database struggling with scale.

The storage strategy separates hot and cold data: CDN handles popular videos, spinning disks handle archival, keeping performance high without forcing SSDs on the entire archive, a cost optimization that scales with content growth.

Concepts & terms
Vitess
A database clustering system for MySQL that provides horizontal sharding, connection pooling, failover, and backup, letting applications scale MySQL without embedding shard logic.
Sharding
A database scaling technique that splits data across multiple machines to increase write throughput and support horizontal growth.
CDN
Content Delivery Network: a network of edge servers that cache content closer to users, reducing latency and origin load.
GFS (Google File System)
A distributed file system Google built to manage large-scale data across clusters, used to store YouTube's video files.
BigTable
A low-latency distributed data storage system built on GFS, handling PB-scale data across thousands of machines.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗