Horizontal scaling involves adding new instances of the application (for example, new servers or containers) to distribute the load among them. Vertical scaling means increasing resources on a single server (adding CPU, RAM, disks).
When choosing an approach, the following criteria are taken into account:
An example of horizontal scaling through Kubernetes:
apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 5 # number of pods — horizontal scale selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: myimage:v1
Key features:
Is horizontal scaling always better than vertical scaling?
No. For certain tasks (for example, for monolithic or stateful services), vertical scaling can be simpler and more efficient.
Does horizontal scaling require no modification to the application?
No. The application must be stateless, support session sharing (for example, using an external cache), and correctly respond to scaling.
Is database scaling always done horizontally?
No. Not all DBMS can be easily scaled horizontally. Classic relational databases often scale vertically (scale-up) or utilize sharding/replication.