The Antiviral Effect

I am the author of "Coolest Friends", a viral (and at times antiviral) MySpace application about ranking your coolest friends. Patrick McKenzie's blog about his Bingo Card Creator software actually inspired me to detail my own development experiences.  He openly shares his challenges and rewards, and so I will attempt to stay within the same vein, starting with this post about how a bug in my app spread from user to user like a disease.

First, some background: MySpace applications are created using the OpenSocial API with large portions written in client-side Javascript. Any application can appear either as a full-page app ("canvas view") or as a box in someone's profile ("home view", "profile view").  Periodically MySpace introduces some changes to their site and releases support for newer versions of the API.

Coolest Friends grew from nothing in November 2008 to over 96,000 daily visits in June 2009. Then the trend flipped, my growth turned to steep decline. At first I assumed it was a temporary setback, but as the weeks progressed the decline continued at a worrying pace. The severity of the situation didn't really sink in until the decline was well underway. Only as the stats started to look like a straight line to zero did I really start to investigate. In only two months the app wounded deeply, down to just 58,000 daily visits. 

I use git, and keep outside notes of changes I make. My logs showed there had been a very basic but serious Javascript programming mistake on my part just when the trend flipped. To loop over arrays, I had used the "for i in array"-style of looping. This turns out to be dangerous, because in Javascript every object inherits all the properties of their "prototype object". So if the prototype of the array is changed, then that "for i in array" construct will loop over those new properties as well.

MySpace had introduced just such a change to the array prototype just as I was flying to Vietnam for a holiday with my friend. It took a good while before I could get on the net to discover and fix that bug, and the app had been broken for about two days when I finally got it working again. So with that fixed, what caused the further decline over the next two months?

I eventually tracked it down to an unintuitive bug. Naturally, masses of people had uninstalled the app while it had been broken. Those uninstalls intensified the effect of a second, unrelated bug. The box that the app displays in a user's profile displays the current ranking of each of the user's friends. To calculate the coolness scores, the app loops over each friend the profile box owner has. What I hadn't considered was the effect of a friend uninstalling the app! In that case the box wouldn't work, as the app would basically try to reference an undefined object.

So as users uninstalled the app, they caused their friends' profile boxes to stop working, which in turn caused them to uninstall the app, in turn causing their friends' profile boxes to stop working... I had implemented the antiviral effect!

Thanks to Sean Grove for editing this post.