Setup:
We have two Laravel projects. One of them is acting as API client(Laravel 5.4) and another is the API server(Laravel 5.6). Both of them are hosted in AWS behind load balancer(2 instances, so 2 for client server, 2 for api server).
We are using https://github.com/tymondesigns/jwt-auth library in API server to authenticated the client requests through JWT token. Using Redis as cache driver.
What works?
When we use 1 instance in the API server load balancer, it works fine. In local environment of every developer of the team, it works fine.
Problem:
Once we increase the API server to 2 instances in AWS load balancer, it doesn't work anymore. The API server randomly returns Unauthenticated
with 401
status. It works sometime, but it send this Unauthenticated
response randomly. No idea why is it happening. We tried by increasing instances in our test server. It acts same, so it's seems to be exist with multiple server in load balancer. But why is it so? How can we solve this problem? We are not being able to reproduce this issue in local machine.