The main purpose of Memcached is to provide an easy to use distributed caching engine in a multinode environment. But, imagine that you have a web application with sticky sessions running on several app servers and want to have some kind of session failover. You want to have a scalable solution for that – just add more servers to handle an increasing number of sessions. This can be processed by sessions that are stored for backup in Memcached node: if a one server dies all the others will take over the work of the dead one and fetch the sessions from Memcached and serve this session from thereon.
The memcached session manager and Jelastic will help you to implement this. The memcached session manager installed in a server holds all sessions in its own jvm. Additionally, after a request was finished, the session is sent to a memcached node for backup. When the next request for this session has to be served, the session is available and can be used. After the second request is finished the session is updated in the memcached node. Now lets imagine the server dies. The next request will be routed to another one. This application server is asked for a session it does not know. It will now lookup the session in the memcached node (based on an id that was appended to the sessionId when the session was created). It will fetch the session from memcached and store the session in its own jvm: it is responsible for that session from now on. After the server answers this request it also updates the session in the memcached node. So the server’s failover is handled completely.
To use memcached for session replication follow the given instruction:
Create the environment
1. Go to jelastic.com and sign up if you haven’t done it yet or log in with your Jelastic credentials by clicking the Sign In link on the page.
2. Ask Jelastic to create a new environment.
3. In the Environment topology window choose two or more servers you want to use (for example, two instances of Tomcat 7) and Memcached node. Type the name of the environment (for example, memcachedreplication) and click Create.