Scaling Applications Using Containers (I)

Learn how to scale applications using containers.

In this section, we’ll demonstrate how using containers and container orchestration platforms, such as Kubernetes, can help us write simpler Node.js applications that can delegate most of the scaling concerns like load balancing, elastic scaling, and high availability to the underlying container platform.

Containers and container orchestration platforms constitute a quite broad topic, largely outside the scope here. For this reason, here, we aim to provide only some basic examples to get started with this technology using Node.js. Ultimately, our goal is to encourage the exploration of new modern patterns in order to run and scale Node.js applications.

What’s a container

A container, specifically a Linux container, as standardized by the Open Container Initiative (OCI), is defined as “a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.”

In other words, by using containers, we can seamlessly package and run applications on different machines, from a local development laptop on our desks to a production server in the cloud.

Other than being extremely portable, applications running as containers have the advantage of having very little overhead when executed. In fact, containers run almost as fast as running the native application directly on the operating system.

In simple terms, we can see a container as a standard unit of software that allows us to define and run an isolated process directly on a Linux operating system.

For their portability and performance, containers are considered a huge step forward when compared to virtual machines.

There are different ways and tools to create and run an OCI-compliant container for an application. The most popular of them is Docker.

We can install Docker in our system by following the instructions for our operating systems on the official Docker documentation.

Creating and running a container with Docker

Let’s rewrite our simple web server application with some minor changes (app.js).

Get hands-on with 1200+ tech skills courses.