https://m.youtube.com/playlist?list=PLy_2fgXkPiZuMaG9Jmp8PAwimIumf19hp&si=EnYgEVHAHFErgNEG
- Weighted Scheduling Algo
- Round Robin Scheduling
- Least Connection First Scheduling:
It's like the round robin, but it forward the requests to the server with least requests not roundly.
There are other algos beside those!
- HAProxy: TCP or HTTP (Default is TCP).
- NGINX: HTTP load balancer with SSL termination support and TCP, UDP too (Default is HTTP).
- mod_athena: Apache based HTTP load balancer (Default is HTTP).
Hardware load balancers are implemented on EITHER Layer 4 (Transport Layer) OR Layer 7 (Application Layer) of OSI model (Open Systems Interconnection).
A- Layer 4 Based Configurations:
- network address translators (NATs).
- DNS load balancing.
- Direct routing.
- Tunnel or a IP tunneling.
- In this type it makes use of TCP, UDP or SCTP transport layer protocols (network-layer information), and distribute traffic based on IP addresses and port numbers.
B- Layer 7 Based Configurations:
- Application delivery network (ADN).
- In this type it makes use of HTTP exists on the layer7 and make the decision according to the actual content of the message (URLs, cookies, scripts).
- For example, if the request coming is for image, it will got to the image server, and if the request is for PHP, it will go to the PHP server, and so on.
- And Layer 7 load balancers are using 3 techniques for that:
Sources:
https://www.thegeekstuff.com/2016/01/load-balancer-intro/
Access Control List (ACL):
- ACL is a rule or condition that's created to make decision about how to handle the incoming requests, like checking matching URL path, evaluating the HTTP headers, checking the IP address or a custom defined pattern.
acl url_blog path_beg /blog
url_blog: The name of the ACL.
path_blog: Is a keyword in HAProxy representing the path beginning.
** This acl rule is checking if the path_beg is /blog **
use_backend blog_backend if url_blog
Usage of ACL: Here iam using the acl url_blog to rout the coming request to blog_servers
if the acl condition is TRUE
Backend:
- Is a set of servers that receives the requests and they are defined in the backend section in the HAProxy configuration.
backend web-backend
balance roundrobin
server web1 web01.your_domain.com:80 check
server web2 web01.you_domain.com:80 check
backend blog-backend
balance roundrobin
mode http
server blog1 blog1.your_domain.com:80 check
server blog2 blog2.your_domain.com:80 check
balance: Specifying the load balancing algo used
mode: Specifying the mode used, wether HTTP (Layer 7) or TCP (Layer 4)
check: Checking wether the servers are healthy or not, so if it's not healthy
it will stop sending requests to it until it become healthy again.
Frontend:
- Defines how requests should be forwarded to backends. and it's defined in the frontend section in the HAProxy Configurations.
- It consists of:
- Set of IP addresses & a port
- ACLs
- use_back rules, which defines which backend server to process the request, And/Or default_backend rule that handles the default route
- In this case the user connects directly to the web server with no load balancing, which can cause many issues like the server will not be able to handle the load alone and can goes down, or the experience will be so slow.
- In this case we will multiple the servers and use load balancer to balance the requests between them using Layer 4. and the backend section in HAProxy (for example) will handle this and send the request to the specified server.
- It will forward the requests based on the IP range and port (If request comes in for http://yourdomain.com/anything) then the traffic will forward to the backend that handles the yourdomain.com on port 80 and it's simpler than Layer 7.
-
In this case we will multiple the servers and use load balancer to balance the requests between them using Layer 4. and the backend section in HAProxy (for example) will handle this and send the request to the specified server.
-
It forwards the coming requests bases on the content need of the request, and the mode here is HTTP
frontend http bind *:80 mode http acl url_blog path_beg /blog use_backend blog-backend if url_blog default_backend web-backend
roundrobin Algorithm leastconn Algorithm (Lease Connection First Scheduling) Weighted Scheduling Algorithm roundrobin Algorithm (This will insure that the same user will connect to the same server, this is achieved through appsession)
- In the previous designs the load balancer was a SOF (Single Point of Failure), so we have to redundant the load balancer like in the coming image to achieve the high availability.
- Here we are achieving the Active/Passive HA by using two load balancers, one is active and another is passive with a health detector in between and once the health detector detects that one load balancer is not working properly, it will forward the requests to the another one until the first back to work normally, then it will forward the requests to it again.