I personally use Redis, but you could shove your sessions into Mongodb since you're already using it.
Otherwise my preferred stack is very similar to yours, except I use Mako for templates and PostgreSQL/Redis for backend storage.
So here is how I was considering to build:
- sessions updated and validated by a demon process per node.
- each validation and update will be one call via ZeroMQ's Req/Rep pattern. With each call I can validate session and reset timestamp.
- after each validation I asynchly will replicate session across other nodes via ZeroMQ's Pub/Sub ( I don't care about extra memory)
- sessions will also persist in MongoDB (async), just in case each node is restarted, thus preserving session.
Btw, I only want to valid/invalidate a session token and keep authorization information. Any other small values I could simply keep in the cookies encrypted, e.g. User ID. Though I could keep session information in cookie as well, but this allows sessions to live forever and it's not good if I want to kick some user out.
It's easier to write my own with ZeroMQ and I can build with custom logic at demon level.
I don't have a good grasp of what you're trying to achieve and why, but my overengineering alarms are going off.
But your concern about growing table of sessions is valid, which I will handle by periodically archiving the old sessions so that index sizes remain small.
For extra reliability in MongoDB, I am thinking to use replica sets (active/passive) and journaling.
- uWSGI - performs better than gunicorn and has support for async apps using gevent
- nginix - front end server
- pyramid - web framework
- mongodb - database
- mongoengine - mongodb and python mapper
- zeromq - messaging and communication
- jinja2 - for template engine
- gevent - for async processing
- gevent-zeromq - to make zeromq non-blocking and gevent compatible
- socket-io - JS lib for realtime communication
I still need to develop robust session management. I considered various options and came to conclusion if I want something fast, truly distributed and not using sticky session I should come up with my own session manager demon hosted on each node. I would use ZeroMQ to communicate to it.