This article is intended for sharing my experience of what I have learned about Alibaba Cloud Server Load Balancer (SLB) from Alibaba Cloud Academy. Although this is not a new topic to me, I took the ACA course to get my fundamentals right as I believe it is very important. I’ve also learned a lot of new things, especially topics related to Alibaba Cloud-specific technologies. I gained a deeper understanding on how Alibaba Cloud can help my organization increase its profit by reducing the operating costs.
If you are not familiar with load balancing and scaling, you should browse for free e-learning classes on this subject, and try the Alibaba Cloud Apsara Cloud Certifications to consolidate your knowledge.
What Is Load Balancer?
Load balancing might seem like a simple concept initially, but this works in conjunction with multiple other services/products, which gives us an opportunity to discuss about some other products.
There are several definitions out there but I would like to explain it in my own terms, it’s obvious that primary task is to balance the load (incoming requests between application/servers). To achieve this there are multiple algorithms/methods like Round Robin and Weighted Round Robin.
Based on the OSI model, the level where load balancing is happening varies as described below:
- Layer 4 Load Balancing — The ability to direct traffic based on data from network and transport layer protocols, such as IP address and TCP port.
- Layer 7 Load Balancing — The ability to make routing decisions based on application layer data and attributes.
There is also a relatively newer concept in load balancing called Global Server Load Balancing. This method handles the traffic distribution between multiple servers across multiple regions.
I would like to explain my understanding with an example
Think of the above situation where there are 3 clients that want to access your application, but our backend server can take the load of only one Client/Server. In this scenario we have 3 servers named Server 1, Server 2 & Server 3.
Problem: Since all the servers are exposed via different IP’s say IP1, IP2 & IP3.
- How will Client know which IP to choose?
- What happens when the service is down with the server associated to the user?
- How we can we monitor all the IP’s?
Here we have the Server Load Balancer (SLB) to the rescue. From server side, we have all the IP’s mapped to the Server Load Balancer and one public IP exposed. While configuring, we have the option of choosing how we want to distribute the requests to the server. In our scenario, since all the Servers takes the same load, we go with the ‘Round Robin’ algorithm. This shares all the requests equally.
All clients can now access the Servers over the SLB, preventing the issue of letting each user know what the IP of the SLB is. Also, we can monitor and provide additional security using the SLB IP, which is easier compared to the previous case of 3 IP’s
With Alibaba Cloud SLB, this means we have multiple other features available:
- You will be charged only for the public traffic. If your SLB is used within the private network, you get this service for free.
- You can put up Auto Scaling, which is another awesome feature, where the SLB monitors the traffic and using some configurations. It creates the Instances for you and handle the load. This reduces the manual work you need to do when in case of need.
- You will also get the monitoring facility right in the console. Thanks to SLB listeners and the Alibaba Cloud Team which gives a quick view of what is happening.
OK, enough talk. It’s time for a real demonstration.
There are 3 components you need to start with SLB
- Server Load Balancer Instance: A Server Load Balancer instance is a running entity of the Server Load Balancer service. To use Server Load Balancer, you must first create a Server Load Balancer instance.
- Listener: A listener defines how incoming requests are distributed. An SLB instance must contain at least one listener.
- Backend Server: The Elastic Compute Service (ECS) instances that are added to an SLB instance to respond to the distributed requests.
Login to the Alibaba Cloud Console & Navigate to the ECS Console.
To keep the context of the article I am not going through the creation of ECS instance. You can see that I have two instances named “SLB_BS_1” & “SLB_BS_2” in “Kuala Lumpur” Region.
We will navigate to the SLB Console provided using the quick link provided in the left-hand side menu.
SLB Instance Creation
If you are someone like me who haven’t created SLB. You will see something familiar to this.
Click on the “Create SLB Instance.” You will be redirected to the SLB Console.
If you see there is a minimal configuration during the SLB Creation, options are obvious.
Instance Type: If you choose “Internet” (which is public SLB) you will get charged and If you choose “Intranet” (Private SLB).
Instance Spec: For demonstration purpose I chose the Shared-Performance Instance. Unless prototyping, this “Instance Spec” is not recommended.
Click “Buy Now”. Then you console should show something similar to this.
If you click on the SLB’s Name, you will see there are no listeners. Click on “Add Listener”.
There are 4 steps while creating listener in Alibaba Console.
- Protocol & Listener
- Backend Servers
- Health Check
Protocol and Listener
Here you will select the protocol of your SLB, this decides whether you will be configuring the Layer-4 or Layer-7.
This will be the listening port to your SLB, the incoming traffic to the SLB. To make things simple I kept the same port as in my http web server on ECS Instances. I will leave the rest of the settings to default.
This is where you will associate the ECS instances to the SLB, click on “Add”. Under the “Servers Added” section.
Post this you will see a small window slides in with the ECS instances information in that SLB instance region. Click the instances to add
I will keep the “Enable health check” option checked as it gives the summarized information about my ECS Instances.
Click “Next” you will move the “Submit” Screen where all the configuration is checked and you will see success against all the items. Click “Ok.”
That’s it!! Congratulations, you have configured your first SLB. If you hit the SLB IP, then you should see the Webpage is served from one of the two ECS instances
When I hit for the first time it shows “This is from ECS Instance 02”
When I hit the same URI Again it shows “This is from ECS Instance 01”
I hope this brief tutorial helped understand the concepts and the steps involved in using Server Load Balancer (SLB) on Alibaba Cloud. To summarize,
- You can put SLB on the same PORT of two ECS Instances.
- SLB opens up to Auto Scaling through which we can reduce the manual effort of provision/deletion instances during peak/off-peak time.
- Alibaba Cloud SLB enables this with the basic protection which in great for organizations which are just starting off on cloud, that too without any configuration.
If you want to learn more about Alibaba Cloud or cloud computing in general, I recommend visiting the Alibaba Cloud Academy, and try the Alibaba Cloud Apsara Cloud Certifications to consolidate your knowledge.