Do we need Spring Cloud LoadBalancer when using Kubernetes on AWS?
Earlier (Before Kubernetes became popular) In Spring Cloud microservices, the architecture looked like this: Client |API Gateway |Spring Cloud LoadBalancer |-------------------------| | |Order1 Order2 Order3 The application itself…
Earlier (Before Kubernetes became popular)
In Spring Cloud microservices, the architecture looked like this:
Client
|
API Gateway
|
Spring Cloud LoadBalancer
|
-------------------------
| | |
Order1 Order2 Order3
The application itself needed to know that there were multiple instances.
For example:
@LoadBalanced
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
or later with Spring Cloud LoadBalancer.
The load balancing happened inside the application (client-side load balancing).
Modern Enterprise (Kubernetes + AWS)
Now the architecture is usually:
Internet
|
AWS Application Load Balancer
|
Kubernetes Ingress
|
API Gateway Pods
|
Kubernetes Services
|
Product Pods
Everything is handled by the infrastructure.
- AWS ALB distributes requests to Kubernetes nodes/Ingress.
- Kubernetes Service distributes requests to pods.
- Kubernetes DNS resolves service names.
Your Spring Boot code simply exposes REST APIs.
No load-balancing code is needed for incoming requests.
Example
Suppose you have:
payment-service
Pod1
Pod2
Pod3
Your Order Service calls:
http://payment-service/pay
You don’t specify:
Pod1
or
Pod2
or
10.10.2.45
Kubernetes automatically sends the request to one of the healthy pods.
So is Spring Cloud LoadBalancer obsolete?
Not completely.
It is still useful in some scenarios:
1. Without Kubernetes
If you’re running microservices on:
- Virtual Machines
- EC2 instances
- Docker Compose
- Bare-metal servers
then Spring Cloud LoadBalancer is still useful.
2. Kubernetes
Usually no.
Kubernetes already provides:
- Service Discovery
- DNS
- Load Balancing
- Failover
Using Spring Cloud LoadBalancer would often duplicate functionality.
Do enterprise developers configure AWS ALB?
Usually DevOps or Platform Engineers do.
Developers typically:
- Write Spring Boot APIs.
- Create a
Deploymentmanifest. - Create a
Servicemanifest. - Optionally define an
Ingressresource.
The infrastructure team or cloud platform provisions and manages the AWS ALB.
Typical responsibilities
| Component | Developer | DevOps/Platform |
|---|---|---|
| Spring Boot APIs | ✅ | |
| Docker image | ✅ | |
| Kubernetes Deployment | ✅ (often) | ✅ |
| Kubernetes Service | ✅ (often) | ✅ |
| AWS ALB | ✅ | |
| Auto Scaling | ✅ | |
| SSL Certificates | ✅ | |
| DNS | ✅ |
In your interviews
If someone asks:
Do we need Spring Cloud LoadBalancer when using Kubernetes on AWS?
A strong answer is:
“Generally, no. Kubernetes Services already provide internal load balancing across pods, and AWS Application Load Balancer handles external traffic. Spring Cloud LoadBalancer is more useful in environments without Kubernetes or when client-side load balancing is specifically required.”