Very interesting and relevant issue for Tornado. There are a lot of ways to implement it, a tornado is so good that out of the box there is no imposed solution, you can give free rein to your imagination and sharpen everything as tasty as possible for your project.
I propose such an option (I omit the extra code to show only the essence):
class BaseHandler(tornado.web.RequestHandler): ... def get_current_user(self): user = None user_json = self.get_secure_cookie("mysite_cookie_user") if not user_json: return None logging.info("User ID:%s is get response", str(user_json)) try: user = tornado.escape.json_decode(user_json) except Exception: logging.info("Error get user cookie") return user def get_visiter_settings(self): settings_json = self.get_secure_cookie("mysite_cookie_settings") try: cur_settings = tornado.escape.json_decode(settings_json) logging.info("Visiter settings:%s is get response from cookie.", str(cur_settings)) except Exception: logging.info("Error get settings from cookie.") logging.info("Init new cookie settings.") cur_settings = { "visitor_uuid": str(uuid.uuid4()), "option1": "foo", ... "option10": "bar"} self.set_secure_cookie("mysite_cookie_settings", json.dumps(cur_settings)) logging.info("New cookie settings initialize.") finally: return cur_settings class MainHandler(BaseHandler): @tornado.web.asynchronous @tornado.gen.coroutine def get(self,*args, **kwargs): current_user = self.get_current_user() visiter_settings = self.get_visiter_settings()
Session hashes can be stored for example in Redis.
In handlers, session status can be received and updated using keys generated by current_user and visiter_settings ["visitor_uuid"].
For example, for guests of a session to determine by visitor_uuid, for those authorized by current_user +, they can be linked to their existing session by visitor_uuid.