Load Balancer
Implement a load balancer for web servers. It provide the following functionality:
Add a new server to the cluster => add(server_id)
.
Remove a bad server from the cluster => remove(server_id)
.
Pick a server in the cluster randomly with equal probability => pick()
.
Motivations:
Finite memory of server
Load Balancers can provide a service that has no downtime and better maintenance.
For example, say you needed to update your website. A load balancer allows you to do this without shutting down your entire system.
Handle and sustain more total connections (as the demand for the product increases).
Maximize resources, and minimize response time.
Further Possible Designs (scheduling algorithms):
Round Robin
Fewest number of connections
Fewest current load on the basis of...
Current CPU occupation
Current memory occupation
Randomized algorithm:
Uniform selection, or fit a beta distribution that best models the constraints of your system.
Weighed Sampling on the basis of certain performance metrics of the server like memory capacity or CPU performance.
Other Issues:
Requests made by same user should be cached to the same server Id.
Complexity: O(1) time for all operations, O(N) space
Implementation 1
Complexity: O(1) time for add, removal, but O(n) for select -> which potentially might be unscalable depending on the constraints of the system design.
Implementation 2
Last updated
Was this helpful?