# Auto-Scaling Guide {#auto-scaling-guide}


Configure auto-scaling for Ever Gauzy deployments.


## Kubernetes Horizontal Pod Autoscaler {#kubernetes-horizontal-pod-autoscaler}


```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: gauzy-api-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: gauzy-api
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
```


## Scaling Strategies {#scaling-strategies}


| Strategy       | Trigger              | Best For          |
| -------------- | -------------------- | ----------------- |
| CPU-based      | CPU > 70%            | Compute-heavy API |
| Memory-based   | Memory > 80%         | Data processing   |
| Request-based  | RPS > threshold      | Traffic spikes    |
| Custom metrics | Queue depth, latency | Advanced scaling  |


## Database Connection Scaling {#database-connection-scaling}


When scaling API pods, adjust connection pool:

```
max_connections = (replicas × pool_size) + buffer
```

| Replicas | Pool/Pod | Max DB Connections |
| -------- | -------- | ------------------ |
| 2        | 20       | 50                 |
| 5        | 20       | 110                |
| 10       | 20       | 210                |


## Docker Swarm Scaling {#docker-swarm-scaling}


```bash
docker service scale gauzy-api=5
```


## Related Pages {#related-pages}


- [Scaling & HA](https://sourcey-gauzy.pages.dev/devops/scaling/index.md) — scaling overview
- [Load Testing](https://sourcey-gauzy.pages.dev/devops/load-testing/index.md) — performance testing
- [Performance Benchmarks](https://sourcey-gauzy.pages.dev/reference/performance-benchmarks/index.md) — benchmarks
