Junior — Middle
How do you distribute load among servers during horizontal scaling of a system?
sobes.tech AI
Answer from AI
When horizontally scaling, the load is distributed among servers using load balancers. Main approaches:
- Round Robin: requests are evenly distributed to servers in turn.
- Least Connections: requests are directed to the server with the fewest active connections.
- IP Hash: requests from the same client are always directed to the same server.
Example of configuring a simple load balancer on Nginx:
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
This approach allows for even load distribution and ensures system fault tolerance.