Scaling Up the Service

Learn how to scale your app using Docker Swarm.

Scaling up by Swarm

Currently, each of our services has been backed by a single task (and therefore container). We can instruct Swarm to increase or decrease the number of containers backing a service. This is known as scaling the service.

From the previous discussion, it should be clear how Swarm implements scaling. Imagine that the swarm receives a new definition of the web service which specifies three containers. The orchestrator sees that only one task has been scheduled and that therefore two more containers are required. It proceeds to create two new tasks, scheduling them across the available nodes in the cluster.

The node (or nodes) allocate the tasks, then start up one container for each task they have been assigned. And voilà, we have scaled up our service to three containers.

Updating our app

If we scale our app currently, it will be hard to tell the difference. How will we know that requests are being handled by different containers? So some changes to our app will be needed to make this more obvious.

File welcome_controller.rb

Update app/controllers/welcome_controller.rb as follows:

Get hands-on with 1200+ tech skills courses.