Node.js is the next big thing – it seems like everybody is saying it. Since its creation in 2009 by a developer named Ryan Dahl, Node.js has exploded in popularity. Node.js has the most starred repositories on GitHub after Bootstrap, and total Google searches for “Node.js” surpassed “Ruby on Rails” last year. It’s downloaded more than 35,000 times a day, with well over a million total downloads to date.
Even if you’re not a developer, it’s worth knowing a little about Node.js – how it works, why it’s important, and (most importantly) whether you should use it to build your websites or web apps.
What exactly is Node.js?
Why is it important?
Node.js makes resource-intensive websites and web apps faster and more scalable. It does that by using an event-driven, asynchronous model. Let’s take a minute to break down what that means:
The HTTP request-response model
The entire Internet works on the same basic model – the HTTP request-response model. Basically, whenever you click on something or navigate somewhere online, your computer sends a request to the server along with instructions. The server processes that request and gives your computer a response – the information (the web page or document, for example) that you asked for.
How synchronous events handle requests
With synchronous events, the server responds to each request in the order in which it was made. In other words, it receives a request, finds the response, and serves it back – if other requests come in while this is happening, it waits until it’s done serving the response, and then takes care of the next one.
And that’s the problem – the wait time. Some websites and web apps host millions of users at a time, with millions and millions of simultaneous connections, which means lots and lots of waiting. Since most of the wait time in websites and web apps comes from I/O operations (people making lots of requests), those sites need to buy more servers to be able to process everything in real time.
How asynchronous events handle requests
With asynchronous events, each server doesn’t have to wait for each request to be served. Instead, the server receives a request and starts searching for a response, but meanwhile it just moves on and starts processing all the other requests too – if it takes the server 5 seconds or 5 minutes to answer the initial request, it doesn’t really matter, because the server has already started with the other requests.
And whenever a response comes in on any one of those requests, that’s the one it serves up next – on an as-needed basis. That way no particular request is ever bottlenecking the I/O operations of the server.
The waiter analogy
One popular way to visualize asynchronous vs. synchronous events is with a restaurant analogy. In a “synchronous” restaurant, a waiter would be assigned to a table, take the table’s order, wait until the table’s food is ready, and then serve it to them (preparing the food is the I/O operation). After that entire process is done, the waiter would move on to the next table. Obviously that creates a lot of time where the waiter is just…waiting.
An “asynchronous” restaurant would assign a waiter to multiple tables – the waiter can take orders from all of his tables and bring them to the kitchen, and then just serve up the orders as soon as they come out of the kitchen (no matter which order was placed first). That’s obviously how restaurants really do operate, and it’s a much more efficient use of the waiter.
And that’s what Node.js brings to the table. It’s a simple idea, but it’s powerful. And it’s what gives Node.js an advantage – it allows for a vast reduction in the number of servers needed to run a high-traffic site or app (and therefore a vast reduction in costs), while still offering an increase in speed.
So how can I take advantage of Node.js?
Node.js is especially ideal for websites and web apps that require a lot of simultaneous connections with a lot of I/O operations (or that plan to eventually require them – don’t forget about considering your future needs).
That could mean a lot of different applications. On a larger scale, it could mean multiplayer social games, social media sites with tons of users, or websites with occasional traffic spikes.
On a more moderate scale, it could mean rewriting websites or apps that are running slowly, reducing your number of servers to cut costs, building proprietary collaborative apps for your business, integrating and connecting your business’s various systems, or porting legacy desktop apps to the web for increased accessibility and functionality – these are all areas where Node.js could offer a solution.
The bottom line is that Node.js is fast, scalable, relatively easy to learn, and you’re going to be hearing a lot more about it as it continues to swell in popularity.
At ROI·DNA, we’re ahead of the curve on Node.js – we’ve been building with it for years, and we know how to take advantage of all the benefits it offers. If you’re interested in building your website or app with Node.js, or you’re not sure which platform to choose, get in touch with us – our team of Node.js developers can give you the rundown.
Coming up next – a few success stories from companies seeing huge benefits by switching to Node.js.