What Is Layer 4 Load Balancing? | NGINX Load Balancer (2022)

Layer4 load balancing uses information defined at the networking transport layer (Layer4) as the basis for deciding how to distribute client requests across a group of servers. For Internet traffic specifically, a Layer4 load balancer bases the load-balancing decision on the source and destination IP addresses and ports recorded in the packet header, without considering the contents of the packet.

There are seven networking layers in all, defined by the Open Systems Interconnection [OSI] Reference Model. For more information, see Layers in the OSI and Internet Models below.

For more information about load balancing, see Application Load Balancing with NGINXPlus.

Layer 4 Load Balancing and NAT

Today the term “Layer4 load balancing” most commonly refers to a deployment where the load balancer’s IP address is the one advertised to clients for a web site or service (via DNS, for example). As a result, clients record the load balancer’s address as the destination IP address in their requests.

(Video) What is Layer 4 Load Balancer?

When the Layer4 load balancer receives a request and makes the load balancing decision, it also performs Network Address Translation (NAT) on the request packet, changing the recorded destination IP address from its own to that of the content server it has chosen on the internal network. Similarly, before forwarding server responses to clients, the load balancer changes the source address recorded in the packet header from the server’s IP address to its own. (The destination and source TCP port numbers recorded in the packets are sometimes also changed in a similar way.)

Layer4 load balancers make their routing decisions based on address information extracted from the first few packets in the TCP stream, and do not inspect packet content. A Layer4 load balancer is often a dedicated hardware device supplied by a vendor and runs proprietary load-balancing software, and the NAT operations might be performed by specialized chips rather than in software.

Layer4 load balancing was a popular architectural approach to traffic handling when commodity hardware was not as powerful as it is now, and the interaction between clients and application servers was much less complex. It requires less computation than more sophisticated load balancing methods (such as Layer7), but CPU and memory are now sufficiently fast and cheap that the performance advantage for Layer4 load balancing has become negligible or irrelevant in most situations.

Comparing Layer 4 and Layer 7 Load Balancers

Layer7 load balancers operate at the highest level in the OSI model, the application layer (on the Internet, HTTP is the dominant protocol at this layer). Layer7 load balancers base their routing decisions on various characteristics of the HTTP header and on the actual contents of the message, such as the URL, the type of data (text, video, graphics), or information in a cookie.

(Video) Load balancing in Layer 4 vs Layer 7 with HAPROXY Examples

Taking into consideration so many more aspects of the information being transferred can make Layer7 load balancing more expensive than Layer4 in terms of time and required computing power, but it can nevertheless lead to greater overall efficiency. For instance, because a Layer7 load balancer can determine what type of data (video, text, and so on) a client is requesting, you don’t have to duplicate the same data on all of the load-balanced servers.

Modern general-purpose load balancers, such as NGINXPlus and the open source NGINX software, generally operate at Layer7 and serve as full reverseproxies. Rather than manage traffic on a packet-by-packet basis like Layer4 load balancers that use NAT, Layer7 load balancing proxies can read requests and responses in their entirety. They manage and manipulate traffic based on a full understanding of the transaction between the client and the application server.

Some load balancers can be configured to provide Layer4 or Layer7 load balancing, depending on the nature of the service. As mentioned previously, modern commodity hardware is generally powerful enough that the savings in computational cost from Layer4 load balancing are not large enough to outweigh the benefits of greater flexibility and efficiency from Layer7 load balancing.

How Can NGINX Plus Help?

NGINXPlus and NGINX are the best-in-class load balancing solutions used by high-traffic websites such as Dropbox, Netflix, and Zynga. More than 350 million websites worldwide rely on NGINXPlus and NGINX Open Source to deliver their content quickly, reliably, and securely.

(Video) What is Layer 4 load balancing?

As a software-based load balancer, NGINXPlus is much less expensive than hardware-based solutions with similar capabilities. The comprehensive load balancing capabilities in NGINXPlus enable you to build a highly optimized application delivery network.

When you insert NGINXPlus as a load balancer in front of your server farm, it increases your entire website’s efficiency, performance, reliability, and scale. NGINXPlus helps you maximize both customer satisfaction and the return on your IT investments.

Layers in the OSI and Internet Models

For Internet traffic, referring to “Layer4” and “Layer7” load balancing is a convenient shorthand, but not strictly accurate. If you’re interested, read on.

The notion of seven networking layers comes from the Open Systems Interconnection (OSI) Reference Model. The model separates network functions into seven abstracted layers, commonly referred to by their numbers (Layer1 through Layer7). At each layer there are standards that define how data is packaged and transported. Among other things, the standards define how to segment the stream of bits that constitute a request or response into discrete packages called protocol data units (PDUs). The standards also define the metadata added to each PDU in the form of a header; the metadata might specify the addresses of the origin and destination hosts, for example.

(Video) Getting Edgy: Layer 4 vs Layer 7 Load Balancing

Assigning different aspects of network functionality to different layers simplifies the processing at each layer, because a protocol only has to know how to deal with its own layer’s PDUs, and what metadata to include in the header so that the protocols at the adjacent layers can repackage the PDUs at their own level of data segmentation.

The distribution of network functions among the basic protocols for traffic on the World Wide Web–which are collectively referred to as the Internet protocol (IP) suite–does not conform exactly to the OSI model. This is because the IP suite was defined and implemented before the finalized OSI model was published in 1984. Nonetheless, the various protocols in the IP suite do perform distinct functions that roughly correspond to OSI layers.

There are multiple protocols defined at each level, but the following are the protocols and levels relevant to load balancing of website traffic:

  • Internet Protocol (IP) operates at the internetwork layer (Layer3). Its PDUs are called packets, and IP is responsible for delivering them from a origin host to a destination host, usually across the boundaries between the multiple smaller networks that make up the Internet. Each device that is directly connected to the Internet has a unique IP address, which is used to locate the device as the recipient of packets.
  • Transmission Control Protocol (TCP) operates at the transport layer (Layer4). TCP effectively creates a virtual connection between the host where the browser is running and the host where a server application is running. Because of the unreliable nature of networks, IP packets can be lost, corrupted, or arrive out of order. TCP has mechanisms for correcting these errors, transforming the stream of IP packets into a reliable communication channel. Each application is assigned a unique TCP port number to enable delivery to the correct application on hosts where many applications are running.
  • Hypertext Transfer Protocol (HTTP) operates at the application layer (Layer7). It defines how data is encoded for communication between web browsers and web servers (or any application that understands HTTP encoding).

As this list makes clear, referring to “Layer4 load balancing” of Internet traffic is a convenient shorthand, but the more accurate term is “Layer3/4 load balancing”–because the load balancer bases its decision on both the IP addresses of the origin and destination servers (Layer 3) and the TCP port number of the applications (Layer4). The more exact term for “Layer7 load balancing” might be “Layer5 through7 load balancing” because HTTP combines the functions of OSI Layers5, 6, and 7.

(Video) What is Layer 7 Load Balancer?

FAQs

What is a layer 4 load balancer? ›

A layer 4 load balancer manages transaction traffic at the transport layer using the UDP and TCP protocols, basic information such as response times and server connections, and a simple load balancing algorithm.

What is Layer 4 and 7 load balancing? ›

An L4-7 load balancer manages traffic based on a set of network services across ISO layers 4 through 7 that provide data storage, manipulation, and communication services.

What is difference between L4 and L7 balance? ›

L4 load balancing delivers traffic with limited network information with a load balancing algorithm (i.e. round-robin) and by calculating the best server based on fewest connections and fastest server response times. L7 load balancing works at the highest level of the OSI model.

What is the difference between layer 3 and layer 4? ›

Layer 4 (Transport): This layer coordinates data transfer between system and hosts, including error-checking and data recovery. Layer 3 (Network): This layer determines how data is sent to the receiving device. It's responsible for packet forwarding, routing, and addressing.

What is Layer 4 used for? ›

Layer 4 of the OSI model, also known as the transport layer, manages network traffic between hosts and end systems to ensure complete data transfers. Transport-layer protocols such as TCP, UDP, DCCP, and SCTP are used to control the volume of data, where it is sent, and at what rate.

What is the function of layer 4? ›

Layer 4 of the OSI Model: Transport Layer provides transparent transfer of data between end users, providing reliable data transfer services to the upper layers. The transport layer controls the reliability of a given link through flow control, segmentation and desegmentation, and error control.

How does l4 load balancer works when do we use them? ›

Layer 4 Load Balancing and NAT

When the Layer 4 load balancer receives a request and makes the load balancing decision, it also performs Network Address Translation (NAT) on the request packet, changing the recorded destination IP address from its own to that of the content server it has chosen on the internal network.

What is l7 load balancing? ›

What is layer 7 load-balancing? A layer 7 load-balancer takes routing decision based on IPs, TCP or UDP ports or any information it can get from the application protocol (mainly HTTP). The layer 7 load-balancer acts as a proxy, which means it maintains two TCP connections: one with the client and one with the server.

What are the layer 4 protocols? ›

Unlike layer 3, there are really only two protocols of note found in layer 4: Transmission Control Protocol (TCP) and User Datagram Protocol (UDP).

What is Layer 4 and Layer 7 in AWS? ›

Application Load Balancers are used to route HTTP/HTTPS (or Layer 7) traffic. Network Load Balancers and Classic Load Balancers are used to route TCP (or Layer 4) traffic.

Is firewall a layer 4? ›

A firewall generally works at layer 3 and 4 of the OSI model. Layer 3 is the Network Layer where IP works and Layer 4 is the Transport Layer, where TCP and UDP function. Many firewalls today have advanced up the OSI layers and can even understand Layer 7 – the Application Layer.

What is layer 3 load balancing? ›

Server load balancer (SLB) provides traffic load distribution functionality for this release of the switch firmware. Load distribution can be performed at layer 2 or layer 3 of the networking protocol stack. This release provides support for only load distribution at layer 3.

What is the function of layer 4 switching? ›

Layer 4 of the OSI Model coordinates communications between systems. Layer 4 switches (L4 switches) are capable of identifying which application protocols (HTTP, SNTP, FTP, and so forth) are included with each packet, and they use this information to hand off the packet to the appropriate higher-layer software.

Which protocol is used in Layer 3 or 4? ›

The most significant protocol at layer 3 (also called the network layer) is the Internet Protocol, or IP. IP is the standard for routing packets across interconnected networks--hence, the name internet.

What is a port in layer 4? ›

Ports are a transport layer (layer 4) concept. Only a transport protocol such as the Transmission Control Protocol (TCP) or User Datagram Protocol (UDP) can indicate which port a packet should go to. TCP and UDP headers have a section for indicating port numbers.

What is Layer 2 Layer 3 and layer 4? ›

The layers are: Layer 1—Physical; Layer 2—Data Link; Layer 3—Network; Layer 4—Transport; Layer 5—Session; Layer 6—Presentation; Layer 7—Application.

What is a layer 4 segment? ›

Layer 4 Transport Layer

A data segment is a Service Data Unit, which is used for encapsulation on the fourth layer (transport layer). It consists of protocol elements that contain Layer 4 information control. When addressing the data segment assigned a Layer 4 address, so a port.

What is a layer 4 header? ›

Layer 4 – The Transport Layer

The Transport Layer provides transparent transfer of data between hosts and is responsible for end-to-end error recovery and flow control. Flow control is the process of adjusting the flow of data from the sender to ensure that the receiving host can handle all of it.

What is 4 layered architecture? ›

The four layers of four-tier architecture are presentation layer (PL), data service layer (DSL), business logic layer (BLL), and data access layer (DAL).

What is a layer 4 address? ›

Techopedia Explains Layer 4

Layer 4 provides the host-to-host or end-to-end transfer of data and communication services for applications that use the layered structure of the OSI model. Layer 4 provides such services as connection-oriented data stream support, flow control, multiplexing and reliability.

What is the layer 5? ›

Layer 5 refers to the fifth layer of the Open Systems Interconnect (OSI) Model, and is known as the session layer. As the name suggests, this layer is dedicated to connection sessions and is the layer that establishes and manages the connections between two or more applications.

What is l5 load balancer? ›

A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase capacity (concurrent users) and reliability of applications.

Is envoy l4 or L7? ›

Envoy is an L7 proxy and communication bus designed for large modern service oriented architectures.

How do Layer 4 DDoS attacks work? ›

Transport Layer (4)

Layer 3 (network layer) and 4 (transport layer) DDoS attacks rely on extremely high volumes (floods) of data to slow down web server performance, consume bandwidth, and eventually degrade access for legitimate users. These attack types typically include ICMP, SYN, and UDP floods.

What is L3 L4 network? ›

As discussed in the listener section, network level (L3/L4) filters form the core of Envoy connection handling. The filter API allows for different sets of filters to be mixed and matched and attached to a given listener.

What is l7 layer? ›

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. A Layer 7 load balancer terminates the network traffic and reads the message within.

What is difference between NLB and ALB? ›

The ALB operates on layer 7, which means the ALB inspects the details of every incoming HTTP request. In contrast, the NLB works on layer 4. All the NLB cares about is forwarding the incoming TCP or UDP connection to a target. The NLB does not inspect an incoming HTTP request, for example.

Is IP a Layer 4 protocol? ›

But as usual, when referring to the TCP/IP model, the layer name and number are based on OSI, so any TCP/IP transport layer protocols are considered Layer 4 protocols. The key difference between TCP and UDP is that TCP provides a wide variety of services to applications, whereas UDP does not.

What are the 4 parts of the 4 layer model? ›

The TCP/IP model is a four-layer model that consists of the Application, Transport, Internet, and Network Access layers. The application layer protocol suite includes HTTP, FTP, SMTP, and DNS.

What is Layer 4 TCP? ›

Layer 4 is the Transport layer. The transport layer creates virtual Transfer Control Protocol (TCP) or User Datagram Protocol (UDP) connections between network hosts. This layer sends and receives data to and from the applications running on its host.

What is difference between ELB and ALB? ›

ELB only allows routing via a single port, while ALB supports distribution through multiple ports and lambda functions. Lambda functions enable users to manage and run various functions, build websites through serverless coding, and create customized ALB targets through serverless methods.

What is Layer 7 used for? ›

Layer 7 of the OSI model, or the application layer, supports communications for end-user processes and applications, and the presentation of data for user-facing software applications.

Is VPN a layer 4? ›

As a rule, a traditional VPN sits on Layer 3, the network lay- er, and primarily applies the IPsec standard.

Do routers operate at Layer 4? ›

Routers operate on the third layer of the OSI Model, the Network-Control Layer. Rather than passing packets based on the Media Access Control (MAC) Layer addresses (as bridges do), a router examines the packet's data structure and determines whether or not to forward it.

How many bits is a Layer 4 port? ›

full-duplex data transmission. Source Port 16 bits. Destination Port 16 bits.

Is layer 2 or Layer 3 better? ›

The layer 2 and Layer 3 differs mainly in the routing function. A Layer 2 switch works with MAC addresses only and does not care about IP address or any items of higher layers. Layer 3 switch, or multilayer switch, can do all the job of a layer 2 switch and additional static routing and dynamic routing as well.

What is layer 2 load balancing? ›

A load balancer splits the load between the available servers and devices to minimize overhead on a single server or device. At layer 2, load balancing can distribute traffic among the machines on the same network. But, as we discussed, it only routes traffic based on MAC addresses.

What is the difference between Layer 1/2 and 3? ›

In summary, Layer 1 is the base layer of a blockchain network which allows layer 2 blockchains to build on top of it. This decongests the main chain providing higher transaction speeds and lower fees. Layer 3 blockchain hosts decentralized applications (DApps).

What is the difference between the duties of layer 3 and Layer 4 of network? ›

The network layer is the third layer of the OSI model which provides communication between hosts of different networks. The transport layer is the fourth layer of the OSI model which is responsible for the process to process delivery of data.

What is L3 and L4 switch? ›

Its Very Simple, L2 switches forwards the MAC address with low latency and L3 switch forwards IP address and also acts as a router with high speed scalability and L4 switches are same as a L3 switch and also acts a firewall like filtering and forwarding the data.

Is a switch a layer 4 device? ›

A network switch is a physical device that operates at the Data Link layer of the Open Systems Interconnection (OSI) model -- Layer 2.

What are the 3 types of ports? ›

There are different types of ports available: Serial port. Parallel port. USB port.

What is Layer 2 layer 3 and Layer 4? ›

The layers are: Layer 1—Physical; Layer 2—Data Link; Layer 3—Network; Layer 4—Transport; Layer 5—Session; Layer 6—Presentation; Layer 7—Application.

Is ELB a layer 4? ›

ELB works at both layer 4 (TCP) and 7 (HTTP) and is the only load balancer that works in EC2-Classic, in case you have a very old AWS account. Also, it's the only load balancer that supports application-defined sticky session cookies; in contrast, ALB uses its own cookies, and you have no control over that.

Is Azure Load Balancer layer 4? ›

Azure load balancer overview

An Azure load balancer is a Layer-4 (TCP, UDP) load balancer that provides high availability by distributing incoming traffic among healthy VMs. A load balancer health probe monitors a given port on each VM and only distributes traffic to an operational VM.

What are the 4 protocol layers? ›

4 The TCP/IP Protocol Stack is made up of four primary layers: the Application, Transport, Network, and Link layers (Diagram 1). Each layer within the TCP/IP protocol suite has a specific function. When the layers of the model are combined and transmitted, communication between systems can occur.

What is l3 load balancer? ›

Server load balancer (SLB) provides traffic load distribution functionality for this release of the switch firmware. Load distribution can be performed at layer 2 or layer 3 of the networking protocol stack. This release provides support for only load distribution at layer 3.

What is a Layer 4 header? ›

Layer 4 – The Transport Layer

The Transport Layer provides transparent transfer of data between hosts and is responsible for end-to-end error recovery and flow control. Flow control is the process of adjusting the flow of data from the sender to ensure that the receiving host can handle all of it.

Is a router Layer 3 or Layer 4? ›

Router is a ubiquitous hardware applied in home and small business networks. It allows communication between devices that attached to it and the internet. A router can forward traffic (packets) based on layer 3 information using IP address.

How does l4 Load Balancer works when do we use them? ›

Layer 4 Load Balancing and NAT

When the Layer 4 load balancer receives a request and makes the load balancing decision, it also performs Network Address Translation (NAT) on the request packet, changing the recorded destination IP address from its own to that of the content server it has chosen on the internal network.

Which AWS Load Balancer works at OSI Layer 4? ›

Network Load Balancer operates at the connection level (Layer 4), routing connections to targets (Amazon EC2 instances, microservices, and containers) within Amazon VPC, based on IP protocol data.

What is Layer 4 in Azure? ›

Azure Load Balancer operates at layer 4 of the Open Systems Interconnection (OSI) model. It's the single point of contact for clients. Load balancer distributes inbound flows that arrive at the load balancer's front end to backend pool instances.

Is F5 Layer 7 load balancing? ›

F5® BIG-IP® Local Traffic Manager™ (LTM) enables both fixed and mobile service providers to simplify network architecture, optimize network performance, and secure it from potential threats with strategic points of control in the network that provide Layer 4–7 load balancing and policy-based routing.

What is Layer 7 load balancing? ›

What is layer 7 load-balancing? A layer 7 load-balancer takes routing decision based on IPs, TCP or UDP ports or any information it can get from the application protocol (mainly HTTP). The layer 7 load-balancer acts as a proxy, which means it maintains two TCP connections: one with the client and one with the server.

What are the protocols in l3 l4 layers? ›

Layer 3+4 (Protocol Suites)
  • AppleTalk.
  • DECnet.
  • IPX/SPX.
  • Internet Protocol Suite.
  • Xerox Network Systems.

Videos

1. What is a Load Balancer?
(IBM Technology)
2. AWS NLB - Network Load Balancer DEMO | Layer 4 Load Balancing | Comparison
(knowledgeindia AWS Azure GCP tutorials)
3. Load Balancers 101
(the roadmap)
4. Load Balancing 101 - What is a load balancer?
(Progress Kemp)
5. you need to learn Load Balancing RIGHT NOW!! (and put one in your home network!)
(NetworkChuck)
6. What is Load Balancing? ⚖️
(Gaurav Sen)

Top Articles

Latest Posts

Article information

Author: Allyn Kozey

Last Updated: 12/04/2022

Views: 6012

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.