Scaling
Scaling
Adjusting system capacity. Divided into vertical scaling (a bigger server) and horizontal scaling (more servers).
Scaling
Adjusting system capacity. Divided into vertical scaling (a bigger server) and horizontal scaling (more servers).
Scaling is increasing or decreasing the processing capacity of a system. It is an essential technique for responding to traffic increases, optimizing costs, and maintaining service availability.
Vertical scaling (Vertical/Scale-Up) increases the resources (CPU, RAM) of a single server. It is simple, but has physical limits and may require downtime. Horizontal scaling (Horizontal/Scale-Out) distributes the load by increasing the number of servers. It can be expanded without downtime, but state management is complex.
In cloud environments, Auto Scaling implements metric-based automatic scale-out/scale-in. For example, an instance is added when CPU utilization exceeds 70% and removed when it falls below 30%. Kubernetes HPA (Horizontal Pod Autoscaler) is a representative example.
In practice, a Stateless design is used to make horizontal scaling easy. Sessions are stored in Redis and files in S3 so that each instance operates independently. Databases are scaled horizontally with read replicas, and sharding is applied for write distribution.
# Kubernetes HPA (Horizontal Pod Autoscaler)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-app
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
behavior:
scaleDown:
stabilizationWindowSeconds: 300 # 축소 전 5분 대기
policies:
- type: Percent
value: 10
periodSeconds: 60 # 분당 10%씩 축소
scaleUp:
stabilizationWindowSeconds: 0 # 즉시 확장
policies:
- type: Percent
value: 100
periodSeconds: 15 # 15초마다 100%까지 확장
---
# AWS Auto Scaling (Terraform)
resource "aws_autoscaling_group" "web" {
name = "web-asg"
min_size = 2
max_size = 20
desired_capacity = 4
vpc_zone_identifier = var.subnet_ids
launch_template {
id = aws_launch_template.web.id
version = "$Latest"
}
target_group_arns = [aws_lb_target_group.web.arn]
tag {
key = "Name"
value = "web-instance"
propagate_at_launch = true
}
}
resource "aws_autoscaling_policy" "scale_up" {
name = "scale-up"
scaling_adjustment = 2
adjustment_type = "ChangeInCapacity"
cooldown = 300
autoscaling_group_name = aws_autoscaling_group.web.name
}
Senior: "Traffic for Black Friday is expected to be 5 times the usual level, so let's discuss a scaling strategy."
Junior: "How about raising minReplicas to 10 in advance and setting the HPA max up to 50? And we revert it after the event."
Interviewer: "What are the differences between horizontal scaling and vertical scaling, and the pros and cons of each?"
Candidate: "Vertical scaling is easy to implement and allows the existing architecture to be maintained, but it has physical limits and cost-efficiency problems. Horizontal scaling allows unlimited expansion and has high availability, but state management and distributed system complexity increase."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Reviewer: "The scaleDown policy seems too aggressive. If the traffic pattern fluctuates, thrashing can occur."
Developer: "I'll increase stabilizationWindowSeconds to 300 seconds and change it to scale down by 10% at a time."