I have 2 EC2 instances running Glassfish app server (running the exact same deployed application) and these run under an Elastic Load Balancer. This is working great but I am worried about caching inconsistencies with the EJBs.
Situation: Client sends request to ELB which forwards to EC2 instance 1. Some EJB object, let's call it EJB1, gets cached. Client --> ELB --> EC2-1 (EJB1 cached)
A short time later Client sends another request but this gets forwarded now to EC2 instance 2. EJB1 now is cached on that instance. Client --> ELB --> EC2-2 (EJB1 cached)
A short time later Client sends another request and is forwarded to EC2 instance 1. EJB1 is still in cache but is not up to date, thus causing a cache inconsistency. Client --> ELB --> EC2-1 (EJB1 cached)
Unfortunately I haven't been able to actually see this issue yet but I feel that it's a possibility. Other than turning caching of EJBs off, what is the proper way to prevent this from happening?
Thanks.