Skip to content

The Day Gangnam Style Broke YouTube's Math

YouTube's view counter was a 32 bit integer with a ceiling of 2,147,483,647. Nobody imagined a video could get there. Then one did.

Episode 33 minute read

A ceiling nobody thought to raise

When YouTube's engineers first built the view counter, they stored it as a signed 32 bit integer, the workhorse number type of computing. A signed 32 bit integer can represent values up to 2,147,483,647, about 2.1 billion. When the counter was built, that was not a limit; it was infinity with a spare order of magnitude. No video, the reasonable assumption went, would ever be watched two billion times. YouTube later said exactly that: it had never thought a video would be watched in numbers greater than a 32 bit integer could hold.

Then PSY's Gangnam Style was uploaded in July 2012, and the video did something no YouTube video had done before: it kept climbing for years. It passed a billion views within months of its upload, crossed two billion in June 2014, the first video to reach that milestone, and by early December 2014 it had passed 2,147,483,647, the most the old counter could ever have shown. YouTube's public statement was playful: the video had been viewed so many times that the counter had to be upgraded to a 64 bit integer, whose signed maximum is 9,223,372,036,854,775,807, over nine quintillion. The page carried an Easter egg to match, a counter that spun when a visitor moused over it. The lore that the counter visibly broke live is an exaggeration, and YouTube said as much: the 64 bit counter had gone in months earlier, because the team saw the number coming and updated its systems to prepare for it. The truth is better for engineers than the lore. A team watched a fixed assumption approach its limit and re engineered ahead of the collision. The number itself, 2,147,483,647, deserves the fame the moment gave it.

What integer overflow actually is

A 32 bit integer is a row of 32 binary switches. One switch conventionally carries the sign, leaving 31 to carry magnitude, and 2 to the 31st power minus 1 is 2,147,483,647. The full range of a signed 32 bit integer runs from negative 2,147,483,648 to positive 2,147,483,647, and when a program tries to count past the top in the common wrapping implementations, the value does not stop politely: it wraps around to the bottom of that range. Counters go negative. Comparisons invert. Logic built on "bigger means more" turns inside out. In safer configurations the program halts instead, which is its own outage. Either way, the failure arrives precisely when the system is at its most successful, because reaching the ceiling requires success at scale. No report says YouTube's counter ever did any of this, and that is the point: the wrap is what the counter was replaced to avoid.

That is what makes this bug family so instructive, and why this series will return to the number. The same class of defect, a value outgrowing the box it was declared in, has blown up rockets and lost spacecraft. Those incidents get their own episodes and their own records. This page is the record for one of them, the friendly one, and states nothing about the others.

What it teaches

Every fixed size number in a system encodes a prediction about the future: this value will never exceed X. Most of those predictions are made silently, at type declaration, without review, and they are the only predictions in engineering that come with a guaranteed failure mode if wrong. The YouTube case is the friendly version because the team saw the asymptote and moved first, which is exactly the practice worth copying: inventory your counters, know their ceilings, and monitor approach velocity the way you monitor disk space. The unfriendly versions of this story are told later in the series. Success is a load. Design your integers for the success you claim to want, then add a couple of orders of magnitude for the success you did not dare claim.

Sources

5 sources

Every figure in this article traces to one of the following: the same record the episode cites.

  1. YouTube's statement on the Gangnam Style view counter

    YouTube (Google+ post, archived by the Internet Archive)2014

01Zof Console

姿勢、操作、次に注意が必要なことを 1 つの面で確認できます。

エンジニアリング、QA、SREの各チームが毎日開く認証済みのホーム。品質の姿勢、進行中の実行、モジュールごとのカバレッジ、そして次に注目すべきことが分かります。

運用上の KPI

実行数、カバレッジ、リスク

出荷先のあらゆる環境に対応します。

ワークスパイン

仕様・テスト・スケジュール

仕様から計画された回帰まで。

ガードレール

RBAC・SSO・監査

指定された人間に起因するすべての行為。

LIVE/console
Zof AI ホーム コマンド センターには、94% パスでの 12 件の実行、3 つの未解決の重大な問題、84% のカバレッジ、4 つのモジュール トレーサビリティ バー、仕様パイプライン、今後のスケジュール、アクティブ実行サイドバー付きの推奨される次のアクションが表示されます。
ホーム ビュー · チェックアウト サービス · ステージング · 製品からライブでキャプチャ。
The Day Gangnam Style Broke YouTube's Math | Zof AI