DEV Community

Cover image for Scaling servers on the fly with few lines of code
Tipicalls
Tipicalls

Posted on

Scaling servers on the fly with few lines of code

You sometimes do not need complex architecture to scale servers automatically…

Why would you pay for some Cloud scaling services and learn how to use these if you could do it for free with just a few lines of code?

Moreover, you may want to scale your servers up and down based on something very specific that your application tracks, like number of logged users, network bandwidth, local weather… or scale only at a very specific day and time… In these cases, having the hands on your scaling mechanism let you create, remove servers based on whatever you need to.

In our free meeting and team collaboration platform Tipicalls, we had a scaling need for all the servers handling the audio and video pieces of the meeting rooms, and we wanted to scale based on the CPU usage on these servers.

So first we needed, on the conferencing servers, to build a service running and tracking the real-time CPU usage and pushing such information into our database.

This can be achieved with a simple NodeJS file called by a service every minute or 2:

So now you have, in your DB, the information of the current CPU being used by all your servers in real time.

Now you need to create a kind of Orchestrator, removing or creating servers based on this information.

To do so, create a server.js file in NodeJS getting info from your DB:

Here we are tracking CPU, but keep in mind you can track anything you want and write scaling rules based on anything. You can build much more complicated rules. You could for instance create scaling rules based on network bandwidth usage, this way you make sure that you never get billed for extra network usage being above your bandwidth threshold!

So with just few lines you have now your own orchestrator creating and removing servers on the fly automatically.

To create servers automatically, most of the Cloud providers now are offering the possibility of building servers using a predefined image you may have built first yourself.

The remaining steps to have your server created are to be able to give it an IP address, create a DNS redirection for it, and start the instance based on such image. The instance will need also to create its own SSL certificate when first started too.

I will show you all these steps in this article here, so this one does not get too long.

James,

Visit Tipicalls.com, our free meeting and team collaboration platform

Top comments (0)