The Oracle Cloud Infrastructure Load Balancing service distributes traffic from one entry point to multiple servers reachable from your virtual cloud network (VCN). The service provides a load balancer with your choice of a public or private IP address, and provisioned bandwidth.
A load balancer improves resource use, facilitates scaling, and helps to ensure high availability. You can configure multiple load balancing policies and application-specific health checks to ensure that the load balancer directs traffic only to healthy instances. The load balancer can reduce your maintenance window by draining traffic from an unhealthy application server before you remove it from service for maintenance.
The Load Balancing service enables you to create a public or private load balancer within your VCN.
A public load balancer has a public IP address that is accessible from the internet.
A private load balancer has an IP address from the hosting subnet, which is visible only within your VCN.
You can configure multiple listeners for an IP address to balance transport layer 4 and layer 7 (TCP and HTTP) traffic. Both public and private load balancers can route data traffic to any backend server that is reachable from the VCN.
Let’s look a little closer at layer 4 load balancers (network load balancers), layer 7 load balancers (application load balancers), and the differences between them.
A network load balancer distributes traffic based on IP address and destination ports. It handles only layer 4 (TCP) traffic; it’s not built to handle anything at layer 7, such as content type, cookie data, custom headers, user location, or application behavior. A network load balancer is a context-less load distribution. It handles only the network-layer information contained within the packets.
An application load balancer distributes traffic based on multiple variables, from the network layer to the application layer. An application load balancer is a context-aware load distribution that directs requests based on any single variable as easily as requests based on a combination of variables. Applications are load balanced based on their behaviour.
An application load balancer works on layer 7, so it supports both HTTP and HTTPS. It can distribute HTTP and HTTPS traffic based on host-based or path-based rules. It also has a configurable range of health check status codes. The following diagram shows a logical representation of an application load balancer in Oracle Cloud Infrastructure (OCI).
Figure 1: Application load balancer on OCI
The basic difference between these two types of load balancer is the layer in which they work. The network load balancer performs request forwarding, whereas the application load balancer routes the request after examining the contents of the HTTP request header. In short, the application load balancer performs content-based routing.
Another major difference is that layer 7 load balancers ensure the availability of the application, whereas layer 4 load balancers do not; they act only on the TCP layer variables.
A layer 7 load balancer can determine availability based on not only a successful HTTP GET of a particular page but also on the verification that the content is as was expected based on the input parameters.
The Load Balancing service lets you route incoming requests to various backend sets. You can perform the following actions:
When used with A records that you create in your DNS system, you can assign virtual hostnames to any listener that you create for your load balancer. Each hostname can correspond to a backend set, and that backend set can route traffic to specific backends that host different applications. Here are some advantages of virtual hostnames:
You can define exact virtual hostnames, such as app.example.com, or you can use wildcard names. Wildcard names include an asterisk (*) in place of the first or last part of the name. When searching for a virtual hostname, the service chooses the first matching variant in the following priority order:
Some applications have multiple endpoints or content types, each distinguished by a unique URI path—for example,
/``cgi``/. You can use path route rules to route traffic to the correct backend set without using multiple listeners or load balancers.
A path route is a string that the Load Balancing service matches against an incoming URI to determine the appropriate destination backend set. Path route strings have the following characteristics:
Creating a highly available web service requires creating at least two instances in two availability domains and then using the Load Balancing service to balance the traffic between them. To do this, you perform the following high-level tasks:
To create the instances and an associated VCN, see the instructions in Setting Up a VCN in Oracle Cloud Infrastructure.
To deploy a web service that has two different routing paths and also accepts a cookie header, you can follow the instructions in GitHub. However, you can use any web server that accepts cookie-based session persistence.
To balance traffic between these two instances, let’s use a public load balancer. The following diagram provides a high-level view of a simple public load balancing system configuration. Far more sophisticated and complex configurations are common.
Figure 2: OCI public load balancer architecture
To create a load balancer, follow these steps. For detailed information about the Load Balancing service, see the documentation.
Figure 3: Load balancer details
Figure 4: Session persistence
Figure 5: Load balancer listener
After the load balancer is created, you are redirected to the details page. There, you can get the public IP address of the load balancer, as shown in the following image.
Figure 6: Load balancer IP address
Copy the IP address, open a browser, and paste it in the address bar. You will see the first instance in availability domain 1. Refresh the page to see that you’re accessing the same instance again; the cookie is working.
This illustrates how you can use HTTP-cookie-based session persistence and how the Load Balancing service can handle application-parameter-based load balancing.
This blog post gave you an overview of layer 4 and layer 7 load balancing capabilities and how Oracle Cloud Infrastructure can load balance traffic by using IP parameters and application parameters. It described how you can create two instances in two different availability domains within a region and then load balance the application traffic using application layer parameters such as cookie-based persistence.
Oracle Cloud Infrastructure provides Enterprise features for developers to build modern cloud applications. Try the Oracle Cloud Free Tier with 300$ credits for a 30 Day Free Trial. Free Tier also includes a number of “Always Free” services that are available for an unlimited period of time even after your free credits expire.