A company runs a stateful web application on EC2 instances in an Auto Scaling group with a dynamic scaling policy based on CPU utilization. The application maintains session state in memory on each instance. Users report that they are frequently logged out and lose their session data during scaling events. What should the company do to resolve this issue?
ElastiCache provides a centralized session store that persists across instance terminations, ensuring session continuity during scaling events.
Why this answer
Option C is correct because storing session state externally in ElastiCache decouples session data from individual EC2 instances. This ensures that when instances are terminated or added during scaling events, users retain their session state regardless of which instance serves their request. ElastiCache provides a low-latency, in-memory cache that is ideal for session persistence in stateful web applications.
Exam trap
The trap here is that candidates often confuse sticky sessions (session affinity) with true session persistence, not realizing that sticky sessions only route traffic to the same instance but do not protect against instance termination during scaling events.
How to eliminate wrong answers
Option A is wrong because changing to a simple scaling policy does not address the root cause of session loss; simple scaling still terminates instances and does not preserve in-memory session state. Option B is wrong because sticky sessions (session affinity) on the Application Load Balancer only route a user to the same instance, but if that instance is terminated during scale-in, the session is lost and the user cannot be reconnected to the same instance. Option D is wrong because increasing the cooldown period only delays the next scaling activity but does not prevent session loss when instances are eventually terminated.