Horizontal scaling and load balancing
Why one server is never enough, and how a load balancer turns many servers into one.
15 min readOne server has a ceiling
Every server can handle only so many requests per second before its CPU, memory or connections run out. Past that point latency does not grow slowly: requests queue up, time out and fail. Buying a bigger machine (vertical scaling) helps for a while, but it is expensive, has a hard limit, and is still a single point of failure.
Scale out instead of up
Horizontal scaling runs many identical copies of a service. To make that work the service must be stateless: any instance can handle any request because session data and files live in shared stores, not on the instance itself.
- Keep state in databases, caches or object storage
- Make instances disposable: they can be added or killed at any time
- Plan capacity with headroom: aim to run below about 70% utilisation
The load balancer
A load balancer sits in front of the instances and spreads requests across the healthy ones. It runs health checks, removes instances that stop responding, and lets you deploy one instance at a time without downtime. Common strategies are round robin, least connections and consistent hashing when requests for the same key should land on the same instance.
Back-of-the-envelope capacity
Estimate before you draw. Requests per second = daily requests / 86 400, times a peak factor of 2 to 5. Divide by what one instance can handle and add headroom. In SystCode, the Feedback panel does this maths live: watch the utilisation of each component as you add instances.
Key takeaways
- Stateless services scale horizontally; stateful ones need special care
- A load balancer adds capacity and removes a single point of failure at the same time
- Always estimate peak requests per second before choosing how many instances you need
Sign in to track lessons and earn badges.