Introduction to HTTP(S) Load Balancing

Lab Details:

  1. This lab walks you with a demo of the HTTP Load Balancer.

  2. In this lab, we will discuss different types of Load Balancer.

  3. Duration: 60 minutes

Note: Do not refresh the page after you click Start Lab, wait for a few seconds to get the credentials.
In case while login into Google, if it asks for verification, please enter your mobile number and verify with OTP, Don't worry this Google Account will be deleted after the lab.

What is HTTP(S) Load Balancer?

  • Before understanding details about HTTP(S) load balancing, let us try to understand the architecture behind networking, which is based on the OSI model. You might have heard it before also but today we will discuss the OSI model at a high level. It'll help you understand things easily.

  • We have 7 layers in the OSI model, which goes from bottom to top from the sender's end and top to bottom at the receiver's end.

  • Layer 1 - Physical Layer, which is your actual cables

  • Layer 2 - Data Link Layer, which will provide you a physical non-changing address called MAC Address, The data link layer translates the physical's raw bit stream into Frames. Basically, Frames are a serial collection of bits. Header and trailer to the frame at this layer. The header which is added to the frame contains the hardware destination and source address called MAC Address.

  • Layer 3 - Network Layer, A Network layer adds the source and destination address to the header of the frame. Addressing is used to identify the device on the internet which is called IP Address. 

  • Layer 4 - Transport, This layer can be termed as an end-to-end layer as it provides a point-to-point connection between source and destination to deliver the data reliably. It adds Port to the packets. To understand in a better way, Suppose you have a lot of processes running on your system like Google, Amazon, Yahoo, etc. Actually, your system as a client is trying to communicate with these servers to take your segment to the correct process on that server and bring that back response to the correct process on your computer, it happens using Port Numbers which help you determine which request belongs to which process. Think IP address as your Society and Port number as your House number.

  • Layer 5 - Session layer which is used to establish, manage, and terminate the session

  • Layer 6 - Presentation layer which is used to translate, encrypt and compress data.

  • Layer 7 - Application layer which is used to allow access to network resources.

  • Load Balancing can be done using different methods, i.e. Layer 4 — TCP, UDP, and Layer 7 — HTTP, HTTPS 

  • We are discussing common facts about all Layer 7 Load Balancers(LBs) and Layer 4 Load Balancers(LBs). In the demo, we will create a simple HTTP Load Balancer. You can create HTTPS Load Balancer in case you own a domain, we have attached a document on how to do that as well.

  • Layer 4-LBs act almost as transport layer aware routers that do no packet manipulation and are faster than Layer 7-LBs that perform a number of manipulation to packets and also have session affinity feature ensuring connections that result from the same source are always served from the same backend. Layer 7-LBs are more common and are often always software whereas Layer 4 - Load Balancers are less common, and tend to be implemented in dedicated hardware.

  • One important note about Layer 7-LBs is their ability to terminate the SSL traffic. This is a limitation for most Layer 4-LBs as they cannot determine if incoming packets are wrapped in SSL and therefore fail to terminate SSL traffic. L7 Load Balancers can have CA certificates installed within them that can verify the authenticity of the service instead of storing and handling them backends. The processing strain from having to encrypt and decrypt such requests is pushed onto Layer 7 - Load Balancers to decrypt such data and re-encrypt the packet for transmission to the backend server. This often results in high latency and can be problematic at times.

  • Within Layer 7 - Load Balancers, the packet is inspected, although this can be a costly process in terms of latency, it has additional features like balance traffic based on content. For example, your company has a pool of backends that have been fitted with some high-end instances optimized for video processing. Another pool may contain low-power CPUs that are optimized for static websites. Layer 7 - Load Balancers can use the URL path e.g. to serve the most appropriate backend to send incoming traffic to the ones with high-end instances, whereas requests to a different URL such as can be transferred to the low-power instances, all thanks to the Layer 7 - Load Balancers ability to intelligently split traffic.

  • Another interesting feature of Layer 7 - Load Balancers is the fact of session affinity or connection stickiness. It is the tendency for a connection where the traffic from the same source continues to be served from the same backend. So if your IP is and you connect to Youtube servers, that are configured with Layer 7-LBs, there is a high chance your tutorial on 'How to get GCP Certified Profession', is being served by the exact same server even if you switch to any other video. This way you receive an uninterrupted consistent connection, which improves the quality of service. Session affinity provides a best-effort attempt to send requests from a particular client to the same backend for as long as the backend is healthy.

Architecture Diagram:


Simple HTTP Load Balancing (click to enlarge)

The flow of the above diagram explained below:

  1. An IPv4 user sends a request to the Public IP provided in the forwarding rule.

  2. The forwarding rule then directs the request to the target HTTP proxy.

  3. As we are using a Simple host and path rule, the target proxy determines that the single backend service receives all requests.

  4. The load balancer then determines the instance group and directs the incoming request to the VM instance in the group.

  5. Finally, the VM instance responds to the request by the user.

Lab Tasks:

  1. Login into GCP Console.

  2. Creating an Instance Template.

  3. Creating an Instance Group.

  4. Creating a Firewall Rule.

  5. Reserving an External IP address.

  6. Creating Target pools.

  7. Creating forwarding rules.

  8. Creating a health check.

Launching Lab Environment:

  1. Launch the lab environment by clicking on . This will create a GCP environment with the resources and roles required for this lab.

  2. Once the lab environment is ready,  will be active. Click on , this will open Google Sign-In page. (Make sure you are using an Incognito mode).

  3. On your previous tab, Click on   and copy your credentials to Sign-in to the console. 

  4. Once logged in, you will be redirected to the GCP Console.

Note : If you have completed one lab, make sure to sign out of the GCP account before starting a new lab. If you face any issues, please go through FAQs and Troubleshooting for Labs.

Creating an Instance Template:

  1. Click on the hamburger icon on the top left corner 

  2. Select Compute Engine under Compute Section 

  3. Select Instance templates 

  4. Click on Create instance template.                                                                                 

  5. Enter the name of your instance template like whizlabs-instance-template 

  6. Select the N1 series from the Series dropdown.                                                                                                                                            

  7. Select machine type as n1-standard-1. Do not choose any other machine type, doing so might get your access to labs blocked.

  8. Under this mentioned tab, Go to the Startup script

  9. Enter the given bash script to get these packages installed on the startup of the instance.

    #! /bin/bash
    apt-get update -y
    apt-get install apache2 -y
    apt-get install php7.0 -y
    a2ensite default-ssl
    a2enmod ssl
    mv /var/www/html/index.html /var/www/html/index.php
    vm_hostname="$(curl -H "Metadata-Flavor:Google" \"
    echo "Welcome to Whizlabs, given text is served from: $vm_hostname" | \
    tee /var/www/html/index.php
  10. Click on create to finally create your instance template.

  11. You can now see the instance template created.

Creating an Instance Group:

  1. Select Instance groups from the left sidebar 

  2. Click on Create instance group.                                                                                                                                                                                                                                          

  3. Enter the name of your instance group like whizlabs-instance-group 

  4. Select single zone for practice purpose

  5. Choose region as us-central1 and zone as us-central1-a 

  6. Choose your instance template which you created in the previous steps.                                  

  7. Select autoscaling mode as Autoscale

  8. Choose metric type as CPU utilization and enter Target as 80 which means once your CPU utilization goes above 80%, new instances should add up.

  9. Enter minimum instances as 1 and Maximum as 5.

  10. Click on Create to finally create your instance group.

  11. You can now see your instance group listed.

Creating a Firewall Rule:

  1. Click on the hamburger icon on the top left corner 

  2. Select VPC network under Networking section 

  3. In the left sidebar, click on Firewall 

  4. Click on Create firewall rule 

  5. Enter the firewall rule name like http-allow

  6. Choose the network as default 

  7. Enter priority number as 1000

  8. Choose direction as Ingress as we are allowing all incoming HTTP traffic

  9. Choose Allow as we want to allow the incoming traffic

  10. Choose target as All Instances in the network which means the same rule will apply for all the instances in the network

  11. Enter the Source IP range as which means all traffic

  12. Enter the port as 80 and check TCP as we are allowing HTTP traffic, HTTP port is 80

  13. Click on create to create the firewall rule

Creating an External IP address:

  1. Now, choose External IP addresses from the left sidebar. 

  2. Click on Reserve static address                                                                   

  3. Enter the name like whizlabs-ip

  4. Choose the tier as Premium because we are creating Global Forwarding Rules.

  5. Choose IPv4 as IP version

  6. Select type as Global. At this point we are just reserving the IP address and not attaching it to our load balancer, once we configure the load balancer, then we will attach IP.

  7. Click on Reserve to reserve your Static IP address

  8. Select Network services under the Networking tab 

  9. Click on Create load balancer.                                                                                                                                                        

  10. Choose HTTP(s) Load Balancing and click on Start configuration.       

  11. Choose the Internet-facing option and click on continue.                                                                                

  12. Enter the load balancer name like whizlabs-lb

  13. Click on Backend Configuration.

  14. In backend configuration, click on the shown drop-down menu.

  15. Click on Create a backend service

  16. Enter any name like whizlabs-backend.

  17. Choose the instance group which you created earlier                                               

  18. Enter the port number as 80 and 8080

  19. Click on the health check drop-down menu

  20. Click on Create a health check                                                                         

  21. Enter any name like whizlabs-health. Keep the other option as is and click on Save.

  22. Click on Create.

  23. Leave host and path rules as is.

  24. Choose frontend configuration                                                                                                               

  25. Enter any name like whizlabs-frontend.

  26. Choose the protocol as HTTP and choose network tier as Premium.                                                                                                                                             

  27. Click on IP Address field

  28. Choose your reserved IP address. This forwarding rule will redirect you to your instances in the Instance group         

  29. Click on Done.

  30. Click on Create to finally create your load balancer

  31. You can see your load balancer listed 

  32. Copy the Static IP which you selected in the Forwarding Rule 

  33. Enter the IP into the URL to get the output 

  34. In case you want to create HTTPS Load Balancer, you can follow the Setup HTTPS Load Balancer in Supporting Document.

Completion and Conclusion:

  1. In this lab, you have created an HTTP Load Balancer.

End Lab:

  1. You have successfully completed the lab.

  2. Once you have completed the steps click on  from your whizlabs dashboard.

Join Whizlabs_Hands-On to Read the Rest of this Lab..and More!

Step 1 : Login to My-Account
Step 2 : Click on "Access Now" to view the course you have purchased
Step 3 : You will be taken to our Learn Management Solution (LMS) to access your Labs,Quiz and Video courses

Open Console