Search code examples
laravelamazon-web-servicesaws-application-load-balancer

Application breaks while adding multiple instances on Application LoadBalancer in AWS


Scenario: If we have a single EC2 instance registered in loadbalancer (Target group) then it works fine. But registering another instance on Target Group breaks the Application.

If we deregister one of the instances then again works fine.

Both instances have a similar codebase and it works perfectly fine while testing individually and on loadbalancer as well.

Any Suggestions and feedbacks are much more appreciated.


Solution

  • What you described looks like a problem with sessions, which means that your requests can jump from one to another server, losing the session data and breaking the application (seen this happening multiple times).

    In order to fix that, you can enable Stickiness on your target group:

    1. Go to the target group
    2. Open Attributes tab
    3. Click on Edit button
    4. Check Stickiness checkbox and for type choose Load balancer generated cookie
    5. Set the duration that you want
    6. Click Save changes button