Reputation: 1
I need to build a very simple service in java, that provides user/login specific client! httpsessions on request. Basically I want other services to be able to ask my sessionservice e.g. for 10 sessions and do some work with those... So far so good.
It gets more complicated when we start talking about leasing those sessions and releasing them when they are no longer required. So my sessionservice needs to keep track of the sessions currently on lease and the ones currently free. Like a thread- or connectionpool for that matter, but one that spans across multiple nodes (multiple jvms). But if i keep track in memory, if I take the service down for maintenance, it crashes or whatsoever, the state is lost, when it comes back up I might be handing out sessions allready in use. Also when I run the service in a cluster, state (leased sessions) must of course be consistent across all nodes.
Bottom line is, I can't have two or more services getting the same sessions.
Any good ideas on how to implement this would be much appreciated! Alternatives are also welcome as there is still room for gameplan changes.
I hope this makes sense to you guys, if not just let me know and I'll try to explain further.
Thanks.
Upvotes: 0
Views: 501
Reputation: 1909
By definition, a microservice must be stateless. All state must be pushed to a datasource.
So in your case, you could include something (ex: a HTTP header) in every request to identify the context.
If you want to share state, use something like memcache (key = the http header, value = the session content)
Upvotes: 1