I have always used the session
scope in my cfml application to do things like store the currently logged in user
object. It's great!
user.isLoggedIn()
, user.hasPremiumAccess()
, user.hasRole('admin')
In attempting to migrate my application to a clustered (cloud) environment, I realize that relying on the session
scope is less than ideal since each instance of the running application has its own server memory. I know I could use "sticky sessions," but I would rather not since that would restrict something like Amazon Elastic Beanstalk from freely spinning up and down instances of the application (based on load).
I also know I could use the client
scope to store simple values in a cluster-friendly way, but what about complex data, like the user object I described? How would you store the user object, or what other approach might I use?
I can make application changes as needed.
** EDIT ** to be clear, it's not that I CAN'T use sticky sessions, it's that I don't WANT to use sticky sessions (or session replication). The reason is so that I can leverage the full scalability benefits of not relying on server/instance memory to manage session state. This approach allows a service such as Elastic Beanstalk to freely create and tear down app-server instances without affecting the user at all. Using sticky sessions does not allow this.
Some possible solutions I have considered include:
- Serializing/Deserializing "state" of user object user to store in client scope and "reinitializing" user on each page load
- Serializing/Deserializing "state" of user object user to store in NoSQL db and "reinitializing" user on each page load