How to choose Load Balancer ( AWS and GCP )
Introduction ( TL;DR )
If you are familiar with Google Cloud Platform or AWS, you must be aware of famous software-based load balancers, all they do is, efficient distribution of network or application traffic across multiple servers. They usually sit in between client devices and backend servers.
Now there are several options for selecting a Load Balancer from popular Cloud Providers. Today, let's discuss the differences between a Load Balancer based on layers of the OSI Model: Layer 4 and Layer 7.
Enough intro…
Layer 4 Load Balancer
Layer 4 is nothing but the Transport Layer of the OSI Model. This is Network Load Balancer in AWS and TCP/UDP Load Balancer in GCP.
Layer 4 load balancers usually route traffic based on IPs, TCP, or UDP ports, do not care about the content of the message, and deals with the delivery of the packets. The load balancer delivers traffic by combining this limited network information with a load balancing algorithm such as round-robin and by calculating the best destination server based on the least connections or server response times.
Benefits
- Control routing rules based on IP or TCP/UDP packets
- A simple approach for Packet-Level load balancing
- Messages are neither inspected nor decrypted, allows them to deliver messages quickly, efficiently, and securely.
- Preservers client source IP
Drawbacks
- Not possible to route traffic based on media-type, localization rules.
- It is fast but can’t perform any action on the protocol above layer 4.
- Cannot access features of Application Layer, eg. routing based on the path
Layer 7 Load Balancer
These load balancers work on top of the application layer of the OSI model. AWS calls them Application Load Balancer and in GCP, these are HTTP(s) load balancer.
Dealing with the actual content of each message, HTTP is the predominant Layer 7 protocol for website traffic on the Internet. Layer 7 load balancers route network traffic in a much more sophisticated way than Layer 4 load balancers, particularly applicable to TCP‑based traffic such as HTTP.
While the need for encryption incurs a performance penalty for layer 7 processing, this can be largely reduced through the use of SSL offload functionality.
Layer 7 Load Balancer supports a unique feature called Session Affinity or Sticky Session which can identify unique client sessions to provide server persistence, sending all client requests to the same server for greater efficiency.
A device that performs Layer 7 load balancing is often referred to as a reverse‑proxy server.
Benefits
- Control routing rules based on IPs, TCP or UDP ports, or any information it can get from the application protocol (mainly HTTP)
- It is capable of performing optimizations and changes to the content (such as compression and encryption)
- Session Affinity or Sticky Sessions for identifying servers
- SSL/TLS offloading
Drawbacks
- More CPU‑intensive than packet‑based Layer 4 load balancing.
- Little slower than Layer 4 LB because of the complex underlying algorithm.
Decision Tree ( GCP )
Resources
- https://en.wikipedia.org/wiki/OSI_model
- https://cloud.google.com/load-balancing/docs/network
- https://cloud.google.com/load-balancing/docs/https
- https://aws.amazon.com/elasticloadbalancing/application-load-balancer/
- https://aws.amazon.com/elasticloadbalancing/network-load-balancer/
- https://aboutssl.org/what-is-ssl-offloading/
- https://www.nginx.com/resources/glossary/reverse-proxy-server/