Horizontal Scaling and Load Balancing
Codesphere allows you to create multiple containers and load balance between them with just a couple clicks.
To do this, we’ll create multiple workspaces for our project, which will serve as our containers. Then, we can connect these different workspaces to the same domain. From there, Codesphere will automatically distribute requests evenly between our containers.
To create our containers, we simply need to make identical workspaces for our production environments and deploy all of them from Codesphere. In this example we’ll create two containers from the Hello, React! template app.
Make sure that all of our workspaces are on a paid plan so that they will be live even when we aren’t actively working in the workspace:
Then in each of our workspaces, let’s deploy our apps with:
yarn install && yarn start
To connect our workspaces, select the Edit button under Verified Domains and select our two containers in the workspaces dropdown for our domain
From there, our workspaces are connected to our domain!
Codesphere will now automatically evenly distribute visitors to each of the two containers using a Round Robin Load Balancer. Note that we can do this for however many containers we need!