Load Balancing Flashcards
What is load balancer?
Definition:
A server mainly used as request dispatcher/router
mainly:
1.Distribute incoming client requests to computing resources(application servers /databases).
2.Returns the response from the computing resource to the appropriate client.
Load balancers can be implemented with hardware (expensive) or with software such as HAProxy.
Load balancer Trade-offs
Advs:
- Auto failover
- distribute load accordingly
- eliminate server SPF -> increase availability/reliability
Disadvantage(s)
- can become a performance bottleneck
a. when not enough resources
b. not configured properly - Can be the SPF -> using multiple increase complexity
- even using 1 increased complexity
Load Balancing algorithms?
When to use which?
Load balancers can route traffic based on various metrics, including:
- Random
- Least loaded
- Sticky Session/cookies - all future request for the same session are send to the same server
- Round robin or weighted round robin
- Layer 4
- Layer 7
Layer 4 And Layer 7 load Balancing
Layer 4 load balancing
Layer 4 load balancers look at info at the transport layer to decide how to distribute requests. Generally, this involves the source, destination IP addresses, and ports in the header, but not the contents of the packet. Layer 4 load balancers forward network packets to and from the upstream server, performing Network Address Translation (NAT).
Layer 7 load balancing
Layer 7 load balancers look at the application layer to decide how to distribute requests. This can involve contents of the header, message, and cookies. Layer 7 load balancers terminates network traffic, reads the message, makes a load-balancing decision, then opens a connection to the selected server. For example, a layer 7 load balancer can direct video traffic to servers that host videos while directing more sensitive user billing traffic to security-hardened servers.
At the cost of flexibility, layer 4 load balancing requires less time and computing resources than Layer 7, although the performance impact can be minimal on modern commodity hardware.
Differences Between Forward Proxy and Reverse Proxy
Forward proxy is used by the client such as a web browser whereas reverse proxy is used by the server such as a web server.
Forward proxy can reside in the same internal network as the client, or it can be on the Internet.
Forward proxy can be used by the client to bypass firewall restrictions in order to visit websites that are blocked by school, government, company etc. If a website blocked an IP range from visiting the website, then a person in that IP range can use forward proxy to hide the real IP of the client so that person can visit the website and maybe leave some spam comments.
Forward proxy can also act as a cache server in an internal network. If a resource is download many times, then the proxy can cache the content on the server so next time when another computer download the same content, the proxy will send the content that is previously stored on the server to the computer.
Reverse proxy (web server)
- Is a web server that
- centralizes internal services
- provides unified interfaces to the public.
Requests from clients are forwarded to a server that can fulfill it before the reverse proxy returns the server’s response to the client.
Additional benefits include:
- Increased security - Hide information about backend servers, blacklist IPs, limit number of connections per client
- Increased scalability and flexibility - Clients only see the reverse proxy’s IP, allowing you to scale servers or change their configuration
- SSL termination - Decrypt incoming requests and encrypt server responses so backend servers do not have to perform these potentially expensive operations
Removes the need to install X.509 certificates on each server - Compression - Compress server responses
- Caching - Return the response for cached requests
- Static content - Serve static content directly
HTML/CSS/JS
Photos
Videos
Etc
Disadvantage(s): reverse proxy
- increase complexity
- using 1 can be SPF, using more can increase complexity
Load balancer vs reverse proxy
- Deploying a load balancer is useful when you have multiple servers. Often, load balancers route traffic to a set of servers serving the same function.
- Reverse proxies can be useful even with just one web server or application server, opening up the benefits described in the previous section.
- Solutions such as NGINX and HAProxy can support both layer 7 reverse proxying and load balancing.