alexedwards / scs

HTTP Session Management for Go
MIT License
2.13k stars 166 forks source link

Performance of Find() #111

Closed benfiveblocks closed 3 years ago

benfiveblocks commented 3 years ago

I implemented a custom session store based on memstore, that also save to disk on Commit() and Delete(). This provides good performance for Find(), and also preserves sessions between server updates. This works well for me because I have a single web server. How can I keep the good performance for Find(), and also support cross-server sessions? E.g. Gorilla can store sessions in cookies.

alexedwards commented 3 years ago

Hi,

The scope of this package is limited to stateful sessions, so storing session data in a cookie is out of scope and you'll need to use something like Gorilla sessions.

If you're running multiple web servers, then you have two main options:

  1. Set up your load balancer to use 'sticky sessions' so that requests with the same session are always routed to the same server.
  2. Use an alternative session store with a backend that is available to all your webservers. Using Redis and the Redisstore SCS implementation is probably the fastest.