miércoles, 17 de agosto de 2011

How LinkedIn used Node.js and HTML5 to build a better, faster mobile app

This morning, LinkedIn launched its gorgeously overhauled mobile app. We’ve already told you all about the new features, but for developers, the most exciting part is what’s going on under the hood.

The app is two to 10 times faster on the client side than its predecessor, and on the server side, it’s using a fraction of the resources, thanks to a switch from Ruby on Rails to Node.js, a server-side JavaScript development technology that’s barely a year old but already rapidly gaining traction.
Also, the development time was unusually fast.
“It was fast by all standards,”  LinkedIn’s mobile development lead Kiran Prasad told VentureBeat. “I’ve worked at startups and big companies like Yahoo, and yeah, it was fast.”
Part of the development speed was due to the fact that the team knew ahead of time exactly what needed to be built. “We really, soundly knew what we wanted to do at the beginning,” said Prasad. “To build a product when you have two years’ worth of data on user behavior makes it a lot faster.”

Using HTML5 for the mobile web & native apps

One part of the development speed was due to the way the team used HTML5 in the web app and reused a bunch of the same code in the native applications for iOS and Android.
“There’s this battle between HTML5 web apps and native apps. But we’ve interspersed HTML5 in the native app, where web-based content excels. The things that are hard to do in HTML5 are a scrolling infinite list, so we went native with that.”
The reuse of HTML5 code across all three applications (mobile web, iOS and Android) will speed up iterations of the app, too. “We can grow our feature set more quickly without having to do a whole new client build,” Prasad said.
In addition to HTML5, the team also used a handful of lesser-known free and open-source tools, such asBackbone and Underscore, in developing the apps.
“The way our mobile web app works is it’s all rendered on the browser side. The value of that is you send less data back and forth, so it’s much faster.”
Also, the app is insanely lightweight. “If you take our entire app and you combine all the framework pieces and zip it, it’s under 50K,” said Prasad.
“We don’t use the browser’s caching system, so once you’ve brought the app down, unless we’ve changed something in the app, the most you have to download is 1K. So especially for international users, it’ really important to not make a bunch of extra traffic.”
To speed up performance on the mobile web app, Prasad told us, “Connections are all stored locally, also for speed and so if you’re offline, you can still access them.”

How Node rules the roost — unless you’re crunching data

We quizzed Prasad about his team’s use of Node.js, the Joyent-sponsored, server-side Javascript technology that’s been all the rage among many startup-centric developers we know.
“On the server side, our entire mobile software stack is completely built in Node,” said Prasad. “We use a ton of technologies at LinkedIn, but for the mobile server piece, it’s entirely Node-based.
“One reason was scale. The second is, if you look at Node, the thing it’s best at doing is talking to other services. The mobile app has to talk to our platform API and database. We’re not doing massive data analytics. Node showed us huge performance gains compared to what we were using before, which was Ruby on Rails.”
The improvements the team saw were staggering. They went from running 15 servers with 15 instances (virtual servers) on each physical machine, to just four instances that can handle double the traffic. The capacity estimate is based on load testing the team has done.
Still, Prasad admits Node isn’t going to be the best tool for every job. “We have a recommendation engine that does a ton of data crunching; Node isn’t going to be the best for that,” he said.
But with a technology so relatively new (Node didn’t truly take off until mid-2010), is LinkedIn concerned about bring a somewhat untested technology to an already at-scale app?
“There’s definitely that concern,” said Prasad, who himself has been using Node since January 2010, before he worked at LinkedIn.
“We did an analysis of a number of platforms — Ruby, Node, Java, Scala. We’ll continue to use it and see how it does. That’s how we’ll make our technology choices. In our culture, we’re encouraged to try new technologies. No one’s going to shoot you in the head for trying something new.”
On the other hand, getting to play with a trendy new technology is like candy for most developers, and Prasad said the opportunity was definitely a hiring incentive. LinkedIn brought some V8 engineers on board, and the company’s Ruby on Rails developers converted
“If you look at the community of Node devs,” said Prasad, “there are a lot of transplants from the Rails world.”
To learn more about the bottlenecks and tech issues the team encountered while working with HTML5 and Node, stay tuned to the LinkedIn engineering blog for a series of technical posts.
via venturebeat.com