Send a request to each server in a consistent order and then back around
s1, s2, s3, s1, s2, s3, s1, ...
Round Robin Problems
- Cookies stored from 1 server may be useless if the client is redirected to a different server. This may force the user to re-authenticate each time, thus creating cookies for each server they need to authenticate on.
- If server A is storing the clients’ session in memory and then the client is directed to server B the later on.
- Can become unbalanced due to browser caching. A users’ browser may cache a servers' response. Now every time the user attempts to access that same resource, they will be sent to that same server instead of letting the load balancer direct the user.
- Can become unbalanced if a super needy user ends up using a lot of resources on a server yet the load balancer just keeps redistributing traffic in sequence.
Round Robin Solutions
- Have a cookie store information on what server it originated from. Then let the load balancer read that cookie and redirect the user back to that server. Note, one should not directly store the servers IP.
- Store sessions in a Database.
- Tell the browser not to cache response or reduce the cache lifetime.
Send the request to the server with the least connections
Still has the issue of user session persistence
Each server reports on its current load and the request is sent to the server with least load
All requests are sent to one server, and when that server is full, then they are all sent to the next server, and so on
The clients IP address is hashed and the hash determines which server to send the request to
The 5 9s of uptime
- 99% uptime
- 99.9% uptime
- 99.99% uptime
- 99.99% uptime
- 99.999% uptime (good luck with that)
Sharding vs Partitioning (in terms of DBs)
Partitioning is the dividing up of your data into separate units
Sharding is horizontal partitioning (partitioning across multiple machines)
- Divide load across multiple machines/DBs
- Resulting in faster reads and writes
- Easier to backup a separate isolated DB instead of a monolith
- Operations spanning multiple partitions = "you're gonna have a bad time"
Bonus - GZIP (GNU ZIP)
Method of compressing data before sending it to the client.
Useful for text files with lots of repeating words/phrases such as HTML, CSS, or JS, but not so good for image or video files which may already be optimized.
The browser automatically decides whether or not to accept zipped files by sending the "Accept-Encoding: gzip, deflate" header