# Scaling Containers by Resources and Network | Cycle.io

Canonical URL: https://cycle.io/learn/scaling-by-resources-or-network

## Scaling Containers by Resources and Network.

Containers run applications in lightweight, isolated environments that can move between hosts. One of the [benefits of using containers](https://cycle.io/learn/containerization-benefits) is that they can scale by resources and by network capacity, through horizontal scaling (running more container instances) and vertical scaling (giving each container more CPU and memory). This article covers the [fundamentals of scaling containers](https://cycle.io/learn/introduction-to-container-orchestration) and the factors that affect resource- and network-based scaling.

Scaling containers means adjusting the computational resources (such as CPU and memory) and network capacity (such as bandwidth and connection limits) available to containerized applications. The goal is to let applications handle more load without slowing down or becoming unavailable.

There are two primary methods for scaling containers:

1.  **Vertical Scaling**: Increasing the resources (CPU, memory) allocated to an individual container.
2.  **Horizontal Scaling**: Adding more container instances to distribute the load.

Each suits different workloads, and the two can be used together.

### Horizontal vs. Vertical Scaling

**Horizontal scaling** (scaling out) means adding more instances of an application, such as more containers, pods or servers, and spreading requests across them with a load balancer. Capacity grows with the number of instances, so no single machine sets a hard ceiling, and losing one instance removes only part of the capacity.

**Vertical scaling** (scaling up) means giving an existing instance more resources: more CPU, more memory or faster storage for a container, VM or server. The application runs unchanged and there is nothing new to load balance, but capacity is capped by the largest machine you can get, and the instance stays a single point of failure.

|     | Horizontal scaling (scale out) | Vertical scaling (scale up) |
| --- | --- | --- |
| What changes | Number of instances (containers, pods, nodes) | CPU, memory or I/O of one instance |
| Upper limit | Load balancer capacity, shared dependencies such as the database, and budget | The node or the largest machine size available; a container can't use more than its host has |
| Downtime | None when new instances join behind a load balancer | Container limits can often change live; a bigger VM or host usually means a restart or migration |
| Statefulness requirements | Instances should be stateless or keep state in a shared store (database, cache, object storage) | None; works for stateful services as they are |
| Cost pattern | Add or remove small units as load changes | Pay for the larger size all the time, sized for peak; the largest sizes get expensive |
| Failure impact | Losing one of N instances removes 1/N of capacity | Losing the instance takes the service down |
| Typical examples | Web and API tiers, queue workers, read replicas | Primary databases, monoliths, JVM services that need a larger heap |

#### When to use each

Scale vertically when:

-   The application can't run as several copies, such as a single-writer database primary or a monolith that keeps state in memory or on local disk.
-   A container is hitting its own limits (CPU throttling, out-of-memory kills) while the host still has free capacity. See [Allocating Resources for Containers](https://cycle.io/learn/allocating-resources-for-containers) for how requests and limits work.
-   The workload needs more memory per process, for example a cache or a large JVM heap.

Scale horizontally when:

-   The service is stateless or can move its state out of the container. [Stateless vs. Stateful Containers](https://cycle.io/learn/stateless-vs-stateful) covers what that takes.
-   You need redundancy, so one failed container or node doesn't cause an outage.
-   Load is spiky and you want to add and remove capacity in small steps.
-   Instances are hitting per-process limits such as connection or thread counts (see "Scaling by Connection Limit" below).

Most production services use both, an approach sometimes called diagonal scaling. Scale each container up to a sensible size first: enough memory that it isn't OOM-killed under normal load and enough CPU that it isn't constantly throttled. Then scale out by adding replicas of that size behind a load balancer, as described in [Load Balancing and High Availability](https://cycle.io/learn/load-balancing-and-high-availability). Stateful tiers often follow the same pattern: a larger primary database plus read replicas (see [Data Replication Strategies](https://cycle.io/learn/data-replication-strategies)).

### Resource-Based Scaling

[Resource-based](https://cycle.io/learn/allocating-resources-for-containers) scaling deals with adjusting the compute and memory resources for containers. Allocating resources well keeps containers from running out of memory, crashing or slowing down.

#### CPU Scaling

Containers can be scaled by adjusting the number of CPUs they have access to. Most container orchestration platforms allow you to define CPU limits and requests. Increasing CPU allocations can help containers handle more compute-intensive workloads.

#### Memory Scaling

A container's memory limit defines how much RAM it can use. If a container reaches its memory limit, it may be terminated by the system. Containers that do heavy data processing may need higher memory limits to avoid this.

#### Auto-Scaling Resources

Orchestration platforms such as Kubernetes offer features like Horizontal Pod Autoscaler (HPA) or resource monitoring to automatically scale containers based on predefined metrics (e.g., CPU utilization reaching 80%).

### Network-Based Scaling

Besides compute and memory, scaling containerized applications also depends on the network. How containers handle networking affects application performance, especially for high-traffic applications.

#### Scaling by Network Bandwidth

When containers handle network-intensive tasks, such as serving web requests or streaming data, bandwidth can become the limiting resource. Each container needs enough bandwidth to avoid network bottlenecks.

#### Scaling by Connection Limit

Some applications may hit connection limits when too many requests are made to the container. This can happen in databases or web services, where a maximum number of concurrent connections is set. Scaling horizontally by adding more container instances allows the application to distribute incoming connections across multiple containers, reducing the load on individual instances.

Platform Docs

Scaling and Auto-Scaling

Learn how to scale and auto-scale container instances across nodes, datacenters, and providers.

<https://cycle.io/docs/platform/scaling-and-auto-scaling>

### Example: Scaling a Container Up and Out

The examples below use a small stateless web app image called `my-web-app` that listens on port 8080 and returns its container hostname, so you can see which replica answered.

#### Vertical: raise a running container's limits

`docker update` changes the CPU and memory limits of a running container without restarting it:

```bash
docker run -d --name api --cpus 1 --memory 512m --memory-swap 512m my-web-app:latest
docker inspect --format '{{.HostConfig.NanoCpus}} {{.HostConfig.Memory}} {{.State.StartedAt}}' api
docker update --cpus 2 --memory 1g --memory-swap 1g api
docker inspect --format '{{.HostConfig.NanoCpus}} {{.HostConfig.Memory}} {{.State.StartedAt}}' api
docker exec api cat /sys/fs/cgroup/cpu.max /sys/fs/cgroup/memory.max
```

```
d7c4cddd8aac46f91eb71dd76de9cee641b469e7fe667b4b38a5c51e7854b41d
1000000000 536870912 2026-11-20T16:52:04.89446778Z
api
2000000000 1073741824 2026-11-20T16:52:04.89446778Z
200000 100000
1073741824
```

The CPU limit (in billionths of a CPU) and memory limit (in bytes) changed, the start time did not, and the cgroup files show the kernel is now enforcing 2 CPUs (200000 µs of CPU time per 100000 µs period) and 1 GiB of memory. A few things to watch:

-   Pass `--memory-swap` together with `--memory`. If the new memory limit is above the container's current swap limit, Docker refuses the change with `Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time`.
-   `--cpus` can't exceed the CPUs on the host (`Range of CPUs is from 0.01 to 2.00, as there are only 2 CPUs available` on a 2-CPU machine).
-   The change applies to that container only. Put the new values in your `docker run` command or Compose file too, or the next recreated container starts with the old limits.

#### Horizontal: run three replicas behind a load balancer

With [Docker Compose](https://cycle.io/learn/docker-compose), the scaled service must not set `container_name` or publish a fixed host port, because every replica needs a unique name and Docker can bind a host port only once. Publish the port on a load balancer instead. This `compose.yaml` puts nginx in front of the `web` service:

```yaml
services:
  web:
    image: my-web-app:latest
    expose:
      - "8080"

  lb:
    image: nginx:stable
    ports:
      - "8080:80"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - web
```

```
upstream web_pool {
    server web:8080;
}

server {
    listen 80;

    location / {
        proxy_pass http://web_pool;
    }
}
```

Start three replicas and send a few requests:

```bash
docker compose up -d --scale web=3
docker compose ps --format 'table {{.Name}}\t{{.Status}}'
for i in 1 2 3 4 5 6; do curl -s localhost:8080; done
```

```
NAME          STATUS
scale-lb-1    Up 1 second
scale-web-1   Up 10 seconds
scale-web-2   Up 15 seconds
scale-web-3   Up 6 seconds
65d4b89c5e97
c4a707b694e8
d1af07c3ae0e
65d4b89c5e97
c4a707b694e8
d1af07c3ae0e
```

Docker's embedded DNS returns one address per replica for the name `web`, and nginx round-robins across them. With this config, nginx resolves that name only when it starts, so after you change the replica count, restart the load balancer:

```bash
docker compose up -d --scale web=5
docker compose restart lb
```

Without the restart, nginx keeps sending traffic only to the original replicas after a scale-out. After a scale-in it keeps trying the removed addresses, and in our test those requests hung until the client timed out. You can instead have nginx re-resolve the name through Docker's DNS server (`resolver 127.0.0.11 valid=10s;` plus a variable in `proxy_pass`); in our tests that picked up new replicas without a restart but spread requests unevenly. Since nginx 1.27.3, open source nginx also supports the `resolve` parameter on an upstream `server` line, which tracks DNS changes without a restart when the upstream also has a `zone` and a `resolver` ([nginx docs](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#resolve)).

#### The same in Kubernetes

On [Kubernetes](https://cycle.io/learn/common-orchestrator-kubernetes), horizontal scaling changes a Deployment's replica count, and Services take the place of the nginx container:

```bash
kubectl scale deployment web --replicas=3
```

A HorizontalPodAutoscaler adjusts the replica count for you. As of November 2026, `autoscaling/v2` is the stable HPA API, and CPU utilization targets need the resource metrics API (usually provided by the Metrics Server add-on) and CPU requests on the containers ([Kubernetes docs](https://kubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale/)). This one keeps average CPU near 70% of requests with 3 to 10 replicas:

```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  minReplicas: 3
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
```

For vertical scaling, in-place Pod resize lets you change a running container's CPU and memory without recreating the Pod. It was alpha in Kubernetes 1.27, beta in 1.33 and has been stable since 1.35 ([Kubernetes docs](https://kubernetes.io/docs/tasks/configure-pod-container/resize-container-resources/)). It needs kubectl 1.32 or later:

```bash
kubectl patch pod worker-7d9c5b8f6-x2k4q --subresource resize --patch \
  '{"spec":{"containers":[{"name":"worker","resources":{"requests":{"cpu":"1"},"limits":{"cpu":"2"}}}]}}'
```

A resize applies to that one Pod. If a Deployment manages it, change the Deployment's resources too, or replacement Pods start with the old values. To automate vertical scaling, the VerticalPodAutoscaler (VPA) recommends and applies requests based on observed usage. VPA is not part of core Kubernetes and has to be installed separately; its `InPlaceOrRecreate` update mode, generally available since VPA 1.6.0 and requiring Kubernetes 1.33 or later, resizes Pods in place when it can and evicts them when it can't ([Kubernetes docs](https://kubernetes.io/docs/concepts/workloads/autoscaling/vertical-pod-autoscale/)):

```yaml
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: worker
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: worker
  updatePolicy:
    updateMode: "InPlaceOrRecreate"
```

The VPA project advises against running VPA and HPA on the same CPU or memory metric, since both would react to the same signal. A common split is HPA on CPU or request rate for the stateless tier, and VPA for workers or stateful services that run as a fixed number of replicas.

### Challenges in Scaling Containers

Scaling containers runs into a few common problems:

#### Resource Contention

Multiple containers running on the same node may compete for limited CPU or memory resources. Allocating resources carefully and monitoring usage keeps one container from slowing down the others.

#### Networking Overhead

As more containers are added, network complexity increases. Orchestration platforms manage internal networking, but misconfigurations or bottlenecks can lead to latency and packet loss.

#### Stateful vs. Stateless

Stateless services are easy to scale horizontally. Stateful applications (e.g., databases) are harder to scale, because their containers often hold session data or manage persistent storage.

### Best Practices for Scaling Containers

These practices help when scaling containers:

#### Use Auto-Scaling Features

Use the auto-scaling tools provided by your orchestration platform to automatically increase or decrease resources based on demand.

#### Monitor Resource Utilization

Continuously monitor CPU, memory, and network usage across your containers to spot bottlenecks early. Alerts on these metrics can help prevent downtime.

#### Optimize Networking

For high-traffic applications, check that the network setup can handle more instances and more traffic. This may include:

-   Load balancing across instances.
-   Allocating enough bandwidth to each container.
-   Reducing latency between containers.

#### Test Scaling Strategies

Regularly test vertical and horizontal scaling under different traffic levels to see how each affects your workload and where its limits are.

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
