Load Balancer
Think of the host at the door of a busy restaurant. Guests do not pick a table themselves. The host sees which waiters have space and sends each guest to a free table. If one waiter goes home sick, the host stops sending guests to that waiter's tables. A load balancer is that host for your app servers. This page tells you what a load balancer does, how it picks a server, and what a tester can check.
6 min read6 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 6 sources6টি সোর্স · updated Nov 2026আপডেট: Nov 2026
One balancer, two rules, three serversএকটি ব্যালান্সার, দুটি নিয়ম, তিনটি সার্ভার
Send the same requests with Round Robin and with Least Connections, and watch the queues on servers of different speed.একই request Round Robin আর Least Connections দিয়ে পাঠান, আর আলাদা গতির সার্ভারে queue-গুলো দেখুন।
You’ll learnআপনি শিখবেন
- What a load balancer doesload balancer কী করে✓
- How Round Robin picks a serverRound Robin কীভাবে সার্ভার বাছে
- Why a slow server queues upধীর সার্ভারে কেন queue জমে
- How Least Connections differsLeast Connections কীভাবে আলাদা
- How to count requests per serverসার্ভার ধরে request কীভাবে গুনবেন
In plain words
A load balancer is a component that receives the incoming requests and spreads them across several backend servers. AWS calls these servers "targets". A target can be a virtual server, a container, or an IP address Source 1সোর্স 1. The load balancer also watches the health of each target and sends traffic only to the healthy ones Source 1সোর্স 1. Because of this, a load balancer makes an application more available and more tolerant of failures Source 1সোর্স 1.
A load balancer can do these jobs:
| Job | What it does |
|---|---|
| Traffic distribution | Spreads the requests across the servers Source 1সোর্স 1 |
| Health check | Sends test requests to each server at regular times Source 2সোর্স 2 |
| Failover | Takes a failed server out of service, and puts it back when it is healthy again Source 2সোর্স 2 |
| TLS termination | Does the encryption and decryption work, so the servers can focus on their main work Source 1সোর্স 1 |
| Routing rules | Sends requests to different server groups based on the content, for example the URL path Source 5সোর্স 5 |
| Draining | Stops new requests to a server that is leaving, and gives its open requests time to finish (on AWS, up to 300 seconds by default) Source 4সোর্স 4 |
The traffic of an https:// site is encrypted. "TLS termination" means that the load balancer ends the encrypted connection and decrypts the requests, so the app servers do not have to Source 1সোর্স 1. NGINX calls the same job "SSL termination" Source 6সোর্স 6.
How it picks a server
The load balancer uses a rule, called an algorithm, to pick the next server. NGINX, a web server that can also work as a load balancer, supports these methods Source 3সোর্স 3:
- Round Robin. The requests go evenly across the servers, one after the other, with server weights taken into account. This is the NGINX default Source 3সোর্স 3.
- Least Connections. The request goes to the server with the fewest active connections Source 3সোর্স 3.
- IP Hash. The client's IP address picks the server. So requests from the same address go to the same server, unless that server is not available Source 3সোর্স 3.
How a health check works
The AWS Application Load Balancer sends a test request to each server about every 30 seconds by default (for instance and IP targets) Source 2সোর্স 2. By default, 2 failed checks in a row make a server "unhealthy", and 5 good checks in a row make it "healthy" again Source 2সোর্স 2. The result of each check lasts for the whole interval Source 2সোর্স 2. So a server that breaks can still get traffic until it fails 2 checks in a row.
Watch one special case. If all the servers in a group are unhealthy in all enabled Availability Zones, the AWS load balancer fails open and sends requests to all of them anyway Source 2সোর্স 2.
Open the image in full sizeছবিটি পূর্ণ আকারে খুলুনসহজ English
A load balancer receives the requests that come in and spreads them across several servers. AWS calls each server a "target". A target can be a virtual server, a container, or an IP address Source 1সোর্স 1. It checks the health of each target and sends traffic only to the healthy ones Source 1সোর্স 1. This makes the app more available and more tolerant of failures Source 1সোর্স 1.
A rule picks the next server Source 3সোর্স 3:
- Round Robin. The servers get the requests one after the other. This is the NGINX default.
- Least Connections. The server with the fewest active connections gets the request.
- IP Hash. The IP address that sends the request picks the server. Requests from one address go to the same server, if that server is available.
On the AWS Application Load Balancer, a health check is a test request to each server, about every 30 seconds by default (for instance and IP targets). By default, 2 failed checks in a row make a server "unhealthy", and 5 good checks in a row make it "healthy" again Source 2সোর্স 2. If all servers in a group are unhealthy in all enabled zones, AWS sends requests to all of them anyway Source 2সোর্স 2.
বাংলা ব্যাখ্যা
Load balancer হলো এমন একটি component, যা আসা request-গুলো গ্রহণ করে এবং কয়েকটি backend server-এর মধ্যে ভাগ করে দেয়। AWS এই server-গুলোকে "target" বলে। একটি target হতে পারে একটি virtual server, একটি container, অথবা একটি IP address Source 1সোর্স 1। Load balancer প্রতিটি target-এর health খেয়াল রাখে এবং শুধু healthy target-এ traffic পাঠায় Source 1সোর্স 1। এর ফলে application বেশি available থাকে এবং failure ভালোভাবে সামলাতে পারে Source 1সোর্স 1।
Load balancer আরও কিছু কাজ করতে পারে। এটি https traffic decrypt করতে পারে (TLS termination), যাতে app server-কে এই কাজ করতে না হয় Source 1সোর্স 1। এটি URL path-এর মতো content দেখে request আলাদা server group-এ পাঠাতে পারে Source 5সোর্স 5। আর যে server সরে যাচ্ছে, তার খোলা request-গুলো শেষ করার সময় দিতে পারে (draining; AWS-এ default হিসেবে সর্বোচ্চ 300 সেকেন্ড) Source 4সোর্স 4।
পরের server বাছাই করতে load balancer একটি নিয়ম, অর্থাৎ algorithm, ব্যবহার করে Source 3সোর্স 3। Round Robin-এ request-গুলো একটির পর একটি server-এ সমানভাবে যায়, তবে server weight হিসাবে ধরা হয়; এটি NGINX-এর default। Least Connections-এ request যায় সবচেয়ে কম active connection থাকা server-এ। IP Hash-এ client-এর IP address দেখে server ঠিক হয়, তাই একই address-এর request একই server-এ যায়, যদি না সেই server unavailable থাকে।
AWS Application Load Balancer default হিসেবে (instance ও IP target-এর জন্য) প্রায় প্রতি 30 সেকেন্ডে প্রতিটি server-এ একটি test request পাঠায়। Default হিসেবে পরপর 2টি check fail করলে server "unhealthy" হয়, আর পরপর 5টি check সফল হলে আবার "healthy" হয় Source 2সোর্স 2। তাই একটি নষ্ট server পরপর 2টি check fail করার আগ পর্যন্ত traffic পেতে পারে। একটি বিশেষ ক্ষেত্র মনে রাখুন: সব enabled zone-এ group-এর সব server unhealthy হলে AWS load balancer তবুও সবগুলোতে request পাঠায় Source 2সোর্স 2।
When you need it
- You run more than one app server. See Horizontal Scaling.
- You need high availability: the system must stay usable when one server fails.
- You want to stop sending traffic to unhealthy servers.
- You want the traffic spread evenly across the servers.
- You want to deploy without downtime. You can add and remove servers without a break in the flow of requests Source 1সোর্স 1.
সহজ English
You need a load balancer in these cases:
- You run more than one app server. See Horizontal Scaling.
- The system must stay usable when one server fails. This is called high availability.
- You want to stop the traffic to servers that are not healthy.
- You want to spread the traffic evenly across the servers.
- You want to deploy a new version with no downtime. With a load balancer, you can add and remove servers, and the requests continue to flow with no break Source 1সোর্স 1.
বাংলা ব্যাখ্যা
নিচের যেকোনো একটি অবস্থা আপনার system-এর সাথে মিলে গেলে, আপনার একটি load balancer দরকার:
- আপনি একাধিক app server চালান। এ বিষয়ে আরও জানতে Horizontal Scaling পাতাটি দেখুন।
- আপনার high availability দরকার, অর্থাৎ একটি server fail করলেও পুরো system ব্যবহারযোগ্য থাকতে হবে।
- আপনি unhealthy server-এ traffic পাঠানো বন্ধ করতে চান।
- আপনি চান, traffic সব server-এর মধ্যে সমানভাবে ভাগ হোক।
- আপনি downtime ছাড়া, অর্থাৎ service না থামিয়েই, নতুন version deploy করতে চান। Load balancer থাকলে request-এর প্রবাহ না থামিয়েই আপনি server যোগ করতে বা সরিয়ে নিতে পারেন Source 1সোর্স 1।
A real-life example
The LMS runs on three app servers. App Server 3 has a memory problem, and it stops answering.
The load balancer sends its regular health check, and App Server 3 fails it. The load balancer marks App Server 3 as unhealthy and stops sending traffic to it. Students continue to use the LMS through App Server 1 and App Server 2. After the team restarts App Server 3, it passes the health checks again, and the load balancer sends it traffic again.
সহজ English
The LMS runs on three app servers. App Server 3 has a memory problem, and it stops answering.
The load balancer sends its regular health check. App Server 3 fails the check. The load balancer marks App Server 3 as unhealthy and stops sending traffic to it. The students continue to use the LMS through App Server 1 and App Server 2.
Then the team restarts App Server 3. The server passes the health checks again. Now the load balancer sends traffic to it again.
বাংলা ব্যাখ্যা
ধরুন, LMS তিনটি app server-এ চলে। App Server 3-এ একটি memory সমস্যা হয়েছে, তাই এটি আর সাড়া দিচ্ছে না।
Load balancer তার নিয়মিত health check পাঠায়, আর App Server 3 সেই check-এ fail করে। তখন load balancer App Server 3-কে unhealthy হিসেবে চিহ্নিত করে এবং সেখানে traffic পাঠানো বন্ধ করে দেয়। শিক্ষার্থীরা App Server 1 আর App Server 2-এর মাধ্যমে LMS ব্যবহার করতে থাকে।
এরপর team App Server 3 restart করে। Server-টি আবার health check pass করে। তখন load balancer আবার সেখানে traffic পাঠাতে শুরু করে।
Common mistakes
- The health check only says "I am alive". A
/healthendpoint that always returns200 OKcan pass while the server cannot reach the database. Then users get errors from a "healthy" server. - The health check is too heavy. If the check calls every dependency, one slow service can mark all servers unhealthy at the same time.
- The deploy kills a server too early. During draining, the AWS load balancer gives the open requests time to finish, up to 300 seconds by default Source 4সোর্স 4. If the server closes the connection before the drain ends, the client gets a 500-level error Source 4সোর্স 4.
- Sticky sessions hide a stateful app. A sticky session ties a user's session to one server Source 4সোর্স 4. This hides the real problem. See Stateless Service.
- Only one load balancer. If you run your own single load balancer, it is a new single point of failure.
সহজ English
Look out for these common mistakes:
- The health check only says "I am alive". A
/healthendpoint can always return200 OK, also when the server cannot reach the database. Then users get errors from a server that looks "healthy". - The health check is too heavy. If the check calls every service that the server needs, one slow service can make all servers unhealthy at the same time.
- The deploy stops a server too early. On AWS, draining gives the open requests time to finish, up to 300 seconds by default Source 4সোর্স 4. If the server closes the connection before the drain ends, the user gets a 500-level error Source 4সোর্স 4.
- Sticky sessions hide a stateful app. A sticky session ties the session of a user to one server Source 4সোর্স 4. This hides the real problem. See Stateless Service.
- Only one load balancer. If you run your own single load balancer, it becomes a new single point of failure.
বাংলা ব্যাখ্যা
এই সাধারণ ভুলগুলোর দিকে খেয়াল রাখুন:
- Health check শুধু বলে "আমি বেঁচে আছি"। একটি
/healthendpoint সবসময়200 OKদিতে পারে, এমনকি server database-এ পৌঁছাতে না পারলেও। তখন একটি "healthy" server থেকেও user-রা error পান। - Health check খুব ভারী। Check যদি প্রতিটি dependency call করে, তাহলে একটি ধীর service একই সময়ে সব server-কে unhealthy করে দিতে পারে।
- Deploy খুব তাড়াতাড়ি server বন্ধ করে দেয়। Draining-এর সময় AWS load balancer খোলা request-গুলো শেষ করার জন্য সময় দেয়, default হিসেবে সর্বোচ্চ 300 সেকেন্ড Source 4সোর্স 4। Drain শেষ হওয়ার আগে server connection বন্ধ করলে client একটি 500-level error পায় Source 4সোর্স 4।
- Sticky session একটি stateful app-কে আড়াল করে। Sticky session একজন user-এর session-কে একটি নির্দিষ্ট server-এর সাথে বেঁধে রাখে Source 4সোর্স 4। এতে আসল সমস্যাটি চাপা পড়ে যায়। Stateless Service পাতাটি দেখুন।
- মাত্র একটি load balancer। আপনি যদি নিজের একটিমাত্র load balancer চালান, তাহলে সেটিই একটি নতুন single point of failure হয়ে যায়।
What a tester can check
Tutorial advice
These test ideas are the tutorial's own advice.
- Server down. Stop one app server during a load test. Measure how long until the errors stop, and compare it with the health check interval and the failure count.
- Server back. Start the server again. Check that it gets traffic again only after it passes the health checks.
- Honest health check. Break the database connection of one server. Check that its health check fails and that the load balancer removes it.
- Spread of traffic. Send many requests and count the responses per server, from logs or a response header. Compare the count with the algorithm.
- Deploy under load. Deploy a new version while a load test runs. Look for 5xx errors at the moment each server is removed.
- All servers sick. In a test environment, make every server fail its health check. Write down what users see.
সহজ English
These test ideas are the tutorial's own advice.
- Server down. Stop one app server during a load test. Measure the time until the errors stop. Compare that time with the health check interval and the number of failed checks.
- Server back. Start the server again. Make sure that it gets traffic again only after it passes the health checks.
- Honest health check. Break the database connection of one server. Make sure that its health check fails and that the load balancer removes it.
- Spread of traffic. Send many requests. Count the responses for each server, from the logs or from a response header. Compare the count with the algorithm.
- Deploy under load. Deploy a new version during a load test. Look for 5xx errors at the moment when each server is removed.
- All servers sick. In a test environment, make every server fail its health check. Write down what users see.
বাংলা ব্যাখ্যা
নিচের test ধারণাগুলো এই tutorial-এর নিজস্ব পরামর্শ।
- Server down। Load test চলার সময় একটি app server বন্ধ করুন। Error থামতে কত সময় লাগে, তা মাপুন। সময়টি health check interval আর failure count-এর সাথে মিলিয়ে দেখুন।
- Server ফিরে আসা। Server-টি আবার চালু করুন। দেখুন, health check pass করার পরেই কেবল এটি আবার traffic পায় কি না।
- সঠিক health check। একটি server-এর database connection ভেঙে দিন। দেখুন, তার health check fail করে কি না এবং load balancer তাকে সরিয়ে দেয় কি না।
- Traffic-এর বণ্টন। অনেক request পাঠান। Log বা response header থেকে প্রতিটি server-এর response গুনুন। সংখ্যাটি algorithm-এর সাথে মিলিয়ে দেখুন।
- Load-এর মধ্যে deploy। Load test চলার সময় একটি নতুন version deploy করুন। প্রতিটি server সরানোর মুহূর্তে 5xx error আসে কি না, খেয়াল করুন।
- সব server অসুস্থ। একটি test environment-এ প্রতিটি server-কে তার health check-এ fail করান। User-রা কী দেখেন, তা লিখে রাখুন।
Key words
| Word | Meaning |
|---|---|
| Load balancer | A component that spreads requests across several servers |
| Target | One backend server (or container, or IP address) that gets requests |
| Health check | A regular test request that shows if a server works |
| Failover | Moving traffic away from a failed server to the healthy ones |
| TLS termination | The load balancer decrypts the https traffic for the servers |
| Round Robin | Requests go to the servers one after the other |
| Least Connections | The request goes to the server with the fewest active connections |
| Draining | Giving open requests time to finish before a server leaves |
| Sticky session | All requests of one user's session go to the same server |