# Vertical scalability

Vertical scalability, also known as **scaling up**, refers to the process of increasing the capacity of a single server or system by adding more resources, such as CPU, memory (RAM), or storage. Instead of distributing the workload across multiple machines, vertical scaling enhances the power of one machine to handle more tasks.

Key features of vertical scalability:

* **Increased capacity**: By upgrading the hardware (e.g., faster processors, more memory), a system can handle more data or users.
* **Single node**: All processing and workload are managed on one server or machine.
* **Simplicity**: Vertical scaling is simpler than horizontal scaling (adding more machines), as it avoids the complexity of distributed systems.
* **Limitations**: There's a hardware limit to how much a machine can be upgraded. Once those limits are reached, vertical scaling is no longer feasible.

Vertical scalability is commonly used in scenarios where system architecture relies on a single server, but it can become expensive and has physical resource limitations compared to horizontal scaling.

Sources:&#x20;

* <https://www.digitalocean.com/resources/articles/horizontal-scaling-vs-vertical-scaling>
* <https://www.cloudzero.com/blog/horizontal-vs-vertical-scaling/#:~:text=of%20vertical%20scaling.-,What%20Is%20Vertical%20Scaling%3F,power%20to%20your%20current%20machines.>

Here a simple sample of how it looks like a vertical scalability:

<figure><img src="/files/uznMzAj2VER3vQpXArRy" alt=""><figcaption><p>Architecture of vertical scalability using NGINX as a load balancer</p></figcaption></figure>

To carry out a vertical scalability using NGINX as load balancer and host our WebMap application with docker is the following:

### **Prerequisites**

Before you begin, ensure you have the following:

* Docker installed on your system.
* Basic knowledge of Docker and containerization concepts.
* The web applications you want to load balance running in separate containers.

### Steps

1. **Set up docker environment**

If you haven't already, install Docker on your system. You can download it from [Docker engine](https://docs.docker.com/engine/install/). Once Docker is installed, start the Docker daemon.

2. **Create NGINX Load Balancer Container**

Before creating the NGINX Load Balancer Container, we need to create a local network into the docker in order to get a better response with the load balancer. Execute the following command:

```bash
docker network create -d bridge <NAME_NETWORK>
```

The *name-network* will be ***load-balancer***

In this step, we will create a NGINX container to act as a load balancer. You can use the [official NGINX image](https://hub.docker.com/_/nginx) from Docker Hub.

```bash
docker run -d -p <EXTERNAL_PORT>:<INTERNAL_PORT> --name <NGINX_NAME_CONTAINER> nginx
```

Explanation:

* \`-d\`: Run the container in detached mode.
* \`-p \<EXTERNAL\_PORT>:\<INTERNAL\_PORT>\`: Map port \<EXTERNAL\_PORT> on the host to port \<INTERNAL\_PORT> in the container.
* \`--name \<NGINX\_NAME\_CONTAINER>\`: Assign a name to the container.
* \`nginx\`: Pull and run the official NGINX image.

3. **Configure NGINX for Load Balancing**

NGINX configuration is essential for load balancing. You need to create an NGINX configuration file and mount it into the container.

Create an NGINX configuration file, for example: \`nginx.conf\`, with the load balancing settings. Below is a example to run a WebMAP app:

\`\`\` nginx.conf

```json
http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
	
    upstream all {
		ip_hash; //Sticky session mode
		server webmap-test-1;
		server webmap-test-2;
		# Add as much as you want servers
    }

    server {
         location / {
              proxy_pass http://all/;
	      proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
	      proxy_set_header Connection $connection_upgrade;
	      proxy_set_header Host $host;
         }
    }

}

events {}

```

\`\`\`

Now, start the NGINX container with the custom configuration file:

```bash
docker run -v /$(pwd)/nginx.conf:/etc/nginx/nginx.conf -d -p <EXTERNAL_PORT>:<INTERNAL_PORT> --network <NETWORK_NAME> nginx
```

\- \``-v /path/to/nginx.conf:/etc/nginx/nginx.conf`\`: Mount the configuration file into the container in read-only mode.

4. **Run Application WebMap Containers**

Ensure that your backend application containers are running. Replace \`webmap-test-1\` and \`webmap-test-2\` in the NGINX configuration with the actual names or IP addresses of your application containers.

You can create a WebMap Container following these steps: [Containerizing WebMap app](https://app.gitbook.com/o/0CInUMojLt1iS1J2bde7/s/-MEOm98BbzqckTUoLpXN/~/changes/TZGbJHQVF7QRzCw2Iav3/scalability/containerizing-a-webmap-.net-application-with-docker).

5. **Test Load Balancer**

Access the NGINX load balancer through your web browser or a tool like \`curl\`. NGINX will distribute incoming requests to your backend servers in a round-robin fashion.

Test the load balancing:

Open the explorer and paste: [http://localhost](http://localhost/):\<EXTERNAL\_PORT>

You should see responses from your application containers indicating that the load balancer is working.

### **Conclusion**

This setup can be easily expanded to include more backend servers and customize load balancing strategies to suit your application's needs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gapvelocity.ai/webmap/scalability/vertical-scalability.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
