# Scalability and Load Balancing

## 1. Container Calculation

### Given

- Expected traffic: **15,000 requests/second**
- One container capacity: **500 requests/second**
- Safety margin: **30%**

### Step 1: Base Number of Containers

15000 / 500 = **30 containers**

### Step 2: Add Safety Margin

30 × 1.30 = **39 containers**

### Final Result

**39 containers** are required to safely handle 15,000 requests per second while maintaining a 30% capacity margin for traffic spikes and failover scenarios.

---

# 2. Cold Start Strategy

To minimize startup latency for new containers:

- Keep a small pool of warm containers ready to receive traffic.
- Use Kubernetes Horizontal Pod Autoscaler (HPA).
- Pre-pull container images on worker nodes.
- Configure Readiness Probes before accepting requests.
- Use Rolling Updates for zero-downtime deployments.
- Scale based on CPU utilization and request rate.

---

# 3. Ghaymah Block Storage for Stateful Workloads

Containers are ephemeral and lose local storage when restarted. Stateful workloads require persistent storage.

Ghaymah Block Storage provides persistent volumes that remain attached to applications even after pod or container recreation.

Typical stateful workloads include:

- PostgreSQL
- MySQL
- MongoDB
- Redis Persistence
- Elasticsearch
- Jenkins
- Kafka
- RabbitMQ

Benefits:

- Persistent storage
- High performance
- Volume reattachment after restart
- Snapshot support
- Backup and disaster recovery
- Independent lifecycle from containers

---

# Summary

| Requirement | Solution |
|------------|----------|
| Incoming Traffic | 15,000 req/s |
| Container Capacity | 500 req/s |
| Safety Margin | 30% |
| Required Containers | **39 Containers** |
| Cold Start | Warm Pool, HPA, Image Pre-Pulling, Readiness Probes |
