Skip to content

Issue with NLB pointing to ALB with target as EC2 instance

0

I have implemented a ALB with NLB for the application running inside the EC2 and pointed the NLB IP to the DNS provider. After multiple request to the website received 502 error (0.002 0.000 -1 502 - 477 595) in the ALB logs and the application started loading for a while. In ALB log i can see a 502 error once, Timeout and Interval has been set at maximum more than required.

Why NLB used is cpanel does not allow CNAME records for root/apex domain, So i placed a NLB infront of ALB and used the NLB IP in the cpanel pointing to the domain name.

KIndly suggest why one 502 error causes the application to load for a long time?

2 Answers
0

When you have an NLB in front of an ALB pointing to EC2 instances, a 502 error typically indicates that the ALB couldn't establish a successful connection with the target EC2 instance. This single 502 error could cause prolonged loading times for several reasons:

  1. Connection pooling behavior: The ALB maintains a single back-end connection with each EC2 instance, regardless of how many clients are connecting through it. If this connection encounters an issue (resulting in a 502), the ALB may need to establish a new connection, which takes time.

  2. Connection limits: Your EC2 instance or application server (like Tomcat) might have connection limits configured. If these limits are reached, new connection attempts will be refused, causing delays as the ALB attempts to establish new connections.

  3. TCP connection management: When using an NLB with an ALB, the NLB must use a TCP listener (not TLS) when the target is an ALB. The ALB then handles the HTTPS termination. If there are any issues in this connection chain, it can cause delays.

  4. Health check recovery: After a 502 error, the load balancer might temporarily mark the target as unhealthy, requiring successful health checks before routing traffic back to it, causing delays.

  5. Connection timeouts: The ALB has idle timeout settings that determine how long a connection can remain inactive before being closed. If these settings aren't aligned with your application requirements, it could lead to premature connection closures and subsequent delays.

To resolve this issue:

answered a year ago

AWS
SUPPORT ENGINEER

reviewed a year ago

0

From what you described, that single 502 error from the ALB likely means your EC2 app either didn’t respond in time, crashed, or closed the connection unexpectedly. Even if it happened just once, it can create a cascading effect—especially if the backend service is overloaded or stuck. That’s probably why your site seemed to “hang” or load slowly after that.

Also worth noting: NLB doesn’t really “understand” if the ALB behind it is unhealthy—it just forwards packets. So if your NLB isn’t doing health checks, it might keep sending users to an ALB that’s routing traffic to a struggling EC2 instance. That can cause intermittent slowness or page hangs even after the first failure.

some notes:

Set up health checks at the NLB level pointing to the ALB (or a health endpoint). Checked EC2 logs to see if the app was crashing or running out of resources. Tuned ALB timeouts and deregistration delay, so bad instances were drained properly. Would recommend digging into CloudWatch metrics and the app logs to see what happened around the time of that 502—it’s usually just the symptom, not the root cause.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.