← Back to all fixes
AWS

ALB returns 504 Gateway Timeout

The Issue

Some requests hitting the ALB return 504 after 60 seconds.

Root Cause

ALB idle timeout (default 60s) is shorter than your app's response time. ALB closes the connection before the backend finishes.

How to Fix
  1. Increase ALB idle timeout: EC2 console > Load Balancers > your ALB > Attributes > Idle timeout
  2. Set it slightly above your slowest expected response time
  3. Also check if your target group health check is failing — unhealthy targets get 502/504
  4. Profile your app to reduce response time for slow endpoints
  5. For very long operations: return 202 Accepted immediately and process asynchronously