Do sessions work with multiple web speakers on Heroku?

If you are using a Rails 3 application with multiple web speakers on Heroku,

  • Each time you click the app, do you usually connect to another web dino?
  • Can sessions work on different web games?
  • Does it work for different Rails session stores (ActionDispatch :: Session :: CookieStore, ActiveRecord :: SessionStore and ActionDispatch :: Session :: CacheStore)
+7
source share
2 answers

In short, yes - sessions will work through several web speakers.

Sessions work through web speakers - because the design of the session support rails allows you to do this. In any case, the web dino model just needs to be scaled horizontally.

1. Every time you get into the application, do you usually connect to another web dino?

Based on heroku documentation:

The routing grid is responsible for locating the web speakers of your applications in a dynamic manifold and forwarding an HTTP request to one of these speakers. Dyno selection is performed using a random selection algorithm.

Thus, the choice of speaker is random ... but for this dinosaur your application must be installed. Therefore, if you have several speakers, you can connect to another dino (which is important, because it facilitates load balancing and high availability).

2. Can sessions work on different web games?

Yes. Most web stacks support sessions by doing the following:

  • Assigning a session identifier, which is a unique identifier, and is usually set as a session cookie, so the browser will always send the identifier with ANY HTTP request to the source host
  • Providing a store that maps the session identifier to actual session data

Thus, in this process, sessions can be supported, since each incoming HTTP request has a session identifier that is available to the web dino when it processes your request.

3. Does it work for different Rails session stores (ActionDispatch :: Session :: CookieStore, ActiveRecord :: SessionStore and ActionDispatch :: Session :: CacheStore)

ActionDispatch :: Session :: CookieStore Yes. The cookie storage stores encrypted session data as cookies. Thus, your browser sends all session data (encrypted) back to the host, which is then decrypted for use in your application.

ActiveRecord :: SessionStore Yes. A cookie storage stores encrypted session data in a database table. The identifier is then assigned as a cookie. Thus, your browser sends the identifier to the host, which is then used to download session data from the database. Since all web dynodes have a database connection, this means that it is also supported.

ActionDispatch :: Session :: cache storage Yes, but you need a cache storage service (for example, the MemCache addon). The cookie storage stores encrypted session data in the memcache storage, which is a common service for all web speakers. The identifier is then assigned as a cookie. Thus, your browser sends the identifier to the host, which is then used to download session data from the memcache.

+15
source

I don’t think Heroku is working hard to send consecutive requests to the same web dino. Maybe I'm wrong, and they are making some effort, but even if they do, it is unlikely to be reliable enough to rely on session management.

However, ActionDispatch :: Session :: CookieStore will definitely work because the data is stored in an encrypted client on the client side. ActiveRecord :: SessionStore will work because the data is stored in a database, which seems to be shared by all web speakers. ActiveDispatch :: Session :: CacheStore should work if you use a MemCached server that is common to all clients, or a similar shared cache.

The only thing that doesn’t work is some kind of file-based session storage in the local file system, and situations similar to many Heroku speakers, which is why this type of session storage is not common in modern web applications.

+5
source

All Articles