One of the common issues we ran into when running an application on a multi-server environment is how to manage sessions. especially an AWS auto-scaling architecture.
In this article, we’re going to discuss some approaches we used in our manage environments to overcome such issues.
AWS application load balancer “ELB” has a nice feature by offering session stickiness, with this feature the load balancer will ensure the same visit will be redirected to the same server on each request, and thus no need to distribute the session on all servers.
from the title, we conclude that we need to store sessions in one location that can be accessed and shared across all servers.
EFS is network storage that can be mounted on ec2 or even on-premise servers, it supports parallel mounting which is a powerful feature the standard NFS servers do not support.
so the idea will be defining session files to be saved on one location and access by all servers, in PHP applications, for example, you can define the session storage file by using the session_save_path function.
Some applications support session management in database natively like Magento, and since the database is centralized storage for all application servers. this will give us centralized storage management.
This is our favorite and recommended method to handle sessions, and it can be achieved aby Memcache or Redis
session.save_handler = redis
session.save_path = tcp://127.0.0.1:6379
There are a few ways to handle sessions, we highly recommend using Redis or Memcache for session management for the reasons we demonstrated above, even its an additional cost, you can use these services in parallel for caching and reducing the load on the database,
We are a Professional AWS Managed company of experienced talented engineers. We are top skilled in AWS Architecture, DevOps, Monitoring and Security Solutions.