Building microservices with Node.js

Why build monoliths when you can compose applications from services? Here are some guiding principles for using Node.js and the Seneca framework to create microservices apps

Microservices architecture may be the most important trend in modern enterprise application development. Instead of massive monolithic applications, with their hefty maintenance and infrastructure overheads, microservices-based applications break up functionality into a suite of small services, linking them via APIs. That approach enables elements of an application to be updated and scaled separately.

The most important feature of a microservices architecture is its array of APIs, often built using familiar HTTP-based RESTful techniques, pushing JSON payloads between services. Each service is a single element of functionality and can be built using the most appropriate technology. One might be written In C#, another integrated into a NoSQL database, another a JavaScript UI running in a browser. The result is a service architecture that works well with modern mobile-first application development methodologies and can be easily integrated into a continuous development devops process.

Many popular websites and services are built using a microservices model; Amazon serves as a prime example. At Amazon, small devops teams are responsible for building and maintaining the services that run the site, with 200 or so services coming together to deliver the Amazon home page. The microservices model also means it’s possible to improve service performance one service at a time, a process that Box calls “ratcheting”: setting targets for developers to improve service responsiveness as the company defines targets for agile development sprints.

Component-based models like microservices are a way of delivering composable applications, with services reused across applications thanks to well-documented, explicit APIs. While this is an efficient way of designing applications, it’s not an efficient way to deliver them. There are overheads in RESTful API calls, especially when you’re using them as a mechanism for handling remote procedure calls.

Part of that is the overhead of running a Web server to handle your services, with separate instances needed for each separate service running on a server. That can be an issue if you’re planning on building a high-density set of services, with each microservice running in a separate container or VM. That’s where a lightweight server comes in to play, replacing the heavyweight Apache or IIS with a more service-oriented item.

One option is Node.js (or its compatible fork, io.js). It’s lightweight, responsive, and designed to work well with common Web data types, including JSON. Its combination of features makes it an ideal host for microservices, enabling you to build services quickly using Node.js as a switching service that processes and routes JSON between APIs. It’s often easiest to think of Node.js as a software router, handling messages and processing responses -- an ideal structure for a lightweight service architecture.

To continue reading this article register now