Blog

Future Proofing – How Gangnam Style Broke YouTube’s Math

Dec 10, 2014

When I graduated college in the late 90's it was the leading edge of the first Dot Com boom. The web was starting to heat up, languages like C++ and the emerging Javascript were rapidly growing, but the graduates of my school in far Northwestern Massachusetts had a special skill that was very much in demand: we knew COBOL. Our Principals of Programming Languages class covered a broad array of languages and the full stack from microcode and assembly up through functional languages like Standard ML the parenthetical nightmare of LISP and on to the (then) new Object Oriented languages (aside: I discovered that I had a strange ability to deliver incredibly short, but incredibly slow, microcode. I had bragging rights for having implemented a 68030 OS in 143 lines of microcode </end old-timer geek brag>). Along that path was COBOL. It wasn't pretty, it wasn't particularly powerful, but it was used by nearly every classic business application and especially those used in banking.

In 1997, knowing how to fix banking computers was a really, really valuable skill and it was all because of the Millenium Bug (aka Y2K). Most readers will remember it, but for those of you born after the year 2000, back when people started writing modern computer code in the 1970's memory was severely constrained and any opportunity you had to save space you took. That meant that years were better written in two digits instead of four (75 instead of 1975) and all of your date math was based on that assumption. The problem was when the year 2000 rolled around the math would go sideways as the date would roll over from 99 to 00. The solution was to go through millions of lines of code and update every reference to two digit dates to four digits. It cost a lot.

Flash forward 15 years and we are in a new world of virtually unlimited memory and incredible scale. But 'virtually' is not 'literally', and YouTube just bumped into their version of the Millenium Bug: the 32-bit integer limit on view counts. You see, back in 2005 when YouTube launched they never thought that a single video would be viewed more than 2 billion times (2,147,483,647 to be precise) and thus when they wrote the video count code they used a 32-bit signed integer* and that's the maximum play counts they can track.

But of course, back in 2005 nobody had heard of Psy's Gangnam Style either.

Sometime this week, Gangnam Style passed 2.147 billion views and now, in response to Psy's gettin' jiggy wit it (yeah, I'm from that era), Google has had to update the code so that play counts are now 64-bit signed integers instead of 32-bit. YouTube can now track views up to 9,223,372,036,854,775,807 (yeah, that's 9 quintillion and change...). I think we'll be safe for a while but years from now, some kid learning what will then be another seemingly obscure programming language will get a very good job updating YouTube's playcounts from 64-bit to 128-bit.

It turns out the butt that broke the internet was Psy's, not Kim's.

 

*note: had they used an unsigned integer they would have gotten about twice as many views. What, after all, is a negative play count? I don't know but you can have over two billion of them before you hit the bottom...

http://beta.twobulls.com/wp-content/uploads/2017/05/twobulls-avatar2.jpg
noah@two-bulls.com
Share on LinkedInTweet about this on Twitter

________________________________________________/\\\_______________________/\\\\\\_____/\\\\\\_________________ _______________________________________________\/\\\______________________\////\\\____\////\\\_________________ _____/\\\______________________________________\/\\\_________________________\/\\\_______\/\\\_________________ __/\\\\\\\\\\\__/\\____/\\___/\\_____/\\\\\____\/\\\_________/\\\____/\\\____\/\\\_______\/\\\_____/\\\\\\\\\\_ _\////\\\////__\/\\\__/\\\\_/\\\___/\\\///\\\__\/\\\\\\\\\__\/\\\___\/\\\____\/\\\_______\/\\\____\/\\\//////__ ____\/\\\______\//\\\/\\\\\/\\\___/\\\__\//\\\_\/\\\////\\\_\/\\\___\/\\\____\/\\\_______\/\\\____\/\\\\\\\\\\_ ____\/\\\_/\\___\//\\\\\/\\\\\___\//\\\__/\\\__\/\\\__\/\\\_\/\\\___\/\\\____\/\\\_______\/\\\____\////////\\\_ ____\//\\\\\_____\//\\\\//\\\_____\///\\\\\/___\/\\\\\\\\\__\//\\\\\\\\\___/\\\\\\\\\__/\\\\\\\\\__/\\\\\\\\\\_ _____\/////_______\///__\///________\/////_____\/////////____\/////////___\/////////__\/////////__\//////////__

Please rotate your device