Do The Simple Thing First: The Engineering Behind Instagram

From: http://www.fastcompany.com/3047642/tech-forecast/do-the-simple-thing-first-the-engineering-behind-instagram

When Instagram arrived in the iPhone App Store in October 2010, it reflected the work of a two-person development team: founders Kevin Systrom and Mike Krieger. Neither had classic software-engineering backgrounds. (At Stanford, Systrom focused on management science and Krieger studied symbolic systems.) And when it became a phenomenon—it's still the iconic example of an app that achieved blockbuster status almost the moment it existed—Systrom had to divert his attention to running the business, leaving the engineering to Krieger.

Instagram cofounder and CTO Mike KriegerPhoto: Gabriela Hasbun, courtesy of Facebook
"We knew just enough engineering to get us off the ground and build V1 of Instagram," says Krieger of those early days. A lot has happened since then, including Facebook's $1 billion acquisition of the company in April 2012. Today, it operates out of Facebook's Silicon Valley campus, with a team of almost 100 engineers. The service they build serves 300 million active users who post 70 million images a day.
But after all this time, the original engineering philosophy of the Kevin-and-Mike era endures: Do the simple thing first.
"When there were just two of us, we didn't have the time to do the fanciest, most complete thing," Krieger explains. "Doing the simple thing first started as a survival tactic, and became a mantra." Today, "'that phrase is burned into brains of all my engineers, which is awesome."
As Instagram launches an updated version with radically revised Search & Explore features, I chatted with Krieger and other staffers about the ongoing challenge of engineering an app known, above all, for straightforwardness and speed. It was never a cakewalk—and as the things Instagram does get more ambitious, it only gets tougher.
"Basically, the goal is just to inspire creativity," says product manager John Barnett. "To help people create things that they want to share with others, and that they're happy with. And doing that in a really simple, elegant way is actually really hard."

Instagram engineers at work at the company's headquarters on Facebook's campusPhoto: Harry McCracken for Fast Company

Simple By Necessity

When Systrom and Krieger started building Instagram, they worked out of a co-working space called Dogpatch Labs. Krieger remembers a neighboring startup badgering him about ambitious technical matters such as JSON optimization. His response? "Guys, you don't have a single customer or user yet." The duo made technical decisions for Instagram using a principle which favored practicality over perfection: "If it solves a problem and gets us closer to launch, let’s do it."
They didn't start out knowing everything required to create Instagram, but that was okay. Krieger educated himself on the fly, watching online videos to learn about engineering challenges as he confronted them. The issues presented by the app "weren’t fancy, glamorous problems," he says. "They were well-trodden by other places like Facebook and Twitter."

Early promotion for Instagram, circa 2011
For a while, Instagram remained famous for having a remarkably small staff given how huge its community of users had grown. At the time of the Facebook acquisition, with 30 million users, it had just six engineers, who Krieger said it had located "in all sorts of untraditional places." (One was a defector from a Dogpatch Labs startup seated near Instagram—not the one obsessed with JSON.)
"I wanted to bring on really great people, but they were hard to find," he remembers. "We were too busy to hire." That got easier when Instagram became part of Facebook. It wasn't just about funds. The new parent company's well-oiled recruiting system provided a steady flow of engineering talent, letting Instagram keep its team's quality high even once it was no longer minuscule.

I assumed that as Instagram got bigger, it must have reached some technical crossroads which forced it to dump Systrom and Krieger's original version for something sturdy and scalable. Krieger disabused me of that notion. "People still find 'Kevin code' in the codebase," he says. "We're not refactoring or rewriting code just for its own sake. Software is like gardening—one day I’ll go behind the shed and clean up. But if nobody ever goes there, does it matter a lot?"
Despite the surprising degree of continuity, much has changed about Instagram's approach to engineering. Krieger says that venture capitalist Matt Cohler, an Instagram investor, was right when he told him early on that "your company is going to break every time it doubles." What can be done on an ad hoc basis when you have a handful of engineers—like committing new code to the codebase—gets tricky fast when dozens of people are involved.
Instagram addressed this conundrum in part by adopting Facebook's highly automated processes for deploying software. A year ago, it moved to a continuous system which has it rolling out new code to its servers 50 times a year. Using "canary" releases, updates go out to a subset of users at first, limiting the ability of buggy software to do damage. "If stuff blows up it affects a very small percentage of people," Krieger says.
The larger team pushing out code in a more formalized fashion has paid dividends. "We think that Instagram hasn't changed all that much," says product designer Josh Dickens. "But man, going back, from the first-run experience and all the way down the line, we're making some big, bold changes for Instagram." In the last six months, for instance, the app has added four new creative tools; in seven months, it's added seven filters.
"We definitely move very fast on Instagram, especially since the team is very small," says software engineer Mona Huang. (Small, of course, is a relative term—but for Huang, who interned on Facebook's newsfeed, Instagram looks dinky.) "With web development, we were releasing all the time, every day. With app development, we release once every two weeks. You do have to make sure things are in good shape before they go out."

Instagram is under no obligation to adopt the technologies that Facebook uses—and in some cases creates—for its own site and apps. "When we got there, people asked, 'Are you going to rewrite your site in PHP?,'" Krieger says. "No. It would slow us down." The service's back end is still written in Python with, especially in recent days, a dash of C++. It also utilizes a storage technology called Cassandra that Facebook invented, open-sourced, and then abandoned.
Still, there are times when embracing Facebook makes sense. Instagram has shifted thousands of servers from Amazon Web Services to Facebook data centers, a move which Krieger says is both cheaper and more efficient in terms of integration. And sometimes, just piggybacking on Facebook's far larger team of engineers makes sense. "If it takes us a month to adapt something it took Facebook a year to build, that’s 11 months were saving," he says.

Getting Big, Thinking Small

Today's Instagram may conduct itself in a more professional manner than when it was just Kevin and Mike, but passion and personal predilections make for a better product. "I love that our engineers are first and foremost Instagram users," Krieger says. One of the app's most productive overhauls came when the team filled a whiteboard with common actions, such as fetching a photo from the server—and then resolved to cut the time that each activity took by 50%. "In a month, we pretty much reduced the latency by half," he remembers. "That's a noticeable improvement for users."
Another aspect of keeping a small-group feel is making sure that engineers continue to talk to each other, even when as activities grow more far-flung and there are too many of them to cram into one conference room. On a monthly basis, team members share knowledge via 10-minute "lightning talks." "It helps solve problems in an Instagrammy way, but it's about team unity as much as improving code," says Krieger.

Of course, the "first" in "do the simple thing first" acknowledges that not everything can be accomplished in a simple fashion. For one thing, keeping the user interface simple ultimately trumps all else, including simple engineering. And as Instagram has delved into more and more sophisticated image-processing technologies, some of its engineering efforts have been complex by any definition.
For instance, when the company wanted to introduce a feature to let users adjust a photo's perspective, "we had multiple engineers going through multiple rounds of iteration," says software engineer Udeepta Bordoloi. "We had people who worked at Pixar, we had people from MIT. We spent lots of hours on the whiteboard going through the equations. We tweaked and tweaked and tweaked. We finally ended up with a solution that we’re happy with that probably satisfies 99.9% of the use cases." It involves only two on-screen sliders, down from five in one rough draft of the feature.

Enter Android

In 2012, Instagram arrived on its second platform: Android. Rather than merely doubling the engineering challenge, the fractured nature of Google's operating system increased it by an order of magnitude.

Instagram's first Android version
"There are some specific Android challenges we don’t have on iOS," Bordoloi says. "You just have such a wide range of devices. It’s not just trying to get the UI to fit the screen shapes and sizes. The other thing is that emerging markets are typically Android-heavy. We have to care a lot for low-memory devices, people who have low bandwidth. I personally take pride that on many of those not-so-good phones, we can do editing, and you don’t really have to wait, and we don’t reduce the resolution."
Technically, it's not so simple, but the end result keeps the classic Instagram sheen, especially in recent releases of the Android version. "It's a pretty big feat," says Barnett. "We spend a lot of time trying, for almost all devices, to give them tools. Not just saying 'You know what? The device is over a year old. They're not going to get perspective or structure.'"
"I've just been blown away consistently by our Android team," adds designer Dickens. "I'm like, 'Are you sure you can do this?' And they're like, 'Oh yeah, no problem!' It makes my job a lot easier."
One Instagram feature that isn't available on Android is Hyperlapse, which lets you shoot slick time-lapse Instagram videos using your iPhone's camera. That's because it isn't an Instagram feature, strictly speaking. Instead, it's a stand-alone iOS app tuned especially for Apple's camera.
The fact that Hyperlapse lives outside of Instagram lets the company keep the iOS and Android apps at parity. (Another stand-alone app, the collage tool Layout, debuted on iOS in March and on Android two months later.) But it has other engineering advantages as well. By breaking apart Instagram's world into multiple apps, "they’re easier to test," says Bordoloi. "There’s less surface area in each app, so the apps don’t break as often."


A Month Is Not Enough

The new Search & Explore features that Instagram is introducing today are some of the most sophisticated functionality that it's ever built—the sort of thing that you might think would have been impossible until the engineering team reached its current critical mass. But keeping with Instagram's original spirit, they didn't begin as an enormous undertaking. Actually, they started with one person trying to build something useful in a month.
"We have this thing at Facebook/Instagram called a Hackamonth, in which engineers can go and spend some time on a different team," says engineering manager Rodrigo Schmidt. "There was an engineer who wanted to try working with us for a month. We were getting started on the idea of trending, and were like, 'You can come in and do this in a month.' It's so funny in retrospect."

Once the project was underway, it ballooned. Tallying up what's popular, Schmidt says, was easy. The problem is that the most popular Instagram hashtags—such as #like and #love—are consistently the most popular hashtags. "For places, it's Disneyland, always," says software engineer Thomas Dimson. The bottom line: A plain-vanilla accounting of the highest-volume items would have been awfully boring. Or possibly offensive, since unfiltered results might also include pornography.
Instead of taking one person one month, implementing the trending engine—and related search features—was a long-term project for about 20 people. "Identifying the real trends and real events, and removing the bad things, is super hard," says Schmidt. "It took us months of tuning and months of refining the algorithms just to do that." For search, the engineers dumped Instagram's previous engine, Elasticsearch, in favor of a home-grown Facebook technology built for social-networking applications, Unicorn.

Instagram's new Search & Explore features
"All this is a back end we didn't have," Schmidt says. "A product infrastructure we didn't have. And a UI that we didn't have." Even the fact that the original Hackamonth project turned out to be hopelessly unrealistic was a lesson worth learning. "It was a month to figure out that this was a harder problem, which was good to find out," says Dimson.
As Instagram tackles additional projects on the scale of the new Search & Explore, it will need to get bigger. But maybe not all that much bigger all that fast. Of 145 software-engineering positions listed on Facebook's recruiting site as I write this, only two are at Instagram. Both job descriptions emphasize the fact that it's a lean outfit serving enormous numbers of users.
"Paradoxically, I'm trying to keep this team small while also growing," says Krieger. That strategy makes for an Instagram that can dream new dreams while remaining recognizable as Instagram. You could say it's doing the simple thing first.

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE