# Acts\_as\_stateless?

**URL:** <https://www.ruby-forum.com/t/acts-as-stateless/74355>\
**Category:** Rails\
**Created:** [December 22, 2005, 6:29pm UTC](https://www.ruby-forum.com/t/acts-as-stateless/74355 "2005-12-22T18:29:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [December 22, 2005, 6:29pm UTC](https://www.ruby-forum.com/t/acts-as-stateless/74355/1 "2005-12-22T18:29:19Z")

</div>

Is there such a thing that I could use to store sessions in the DB  
instead of in a cookie so that I can ensure users will be able to  
access their session data even across several load balancers? We use  
totally stateless machines here at work and I am worried about  
deploying a rails app in production that uses a volitile session  
stored on the machine.

## Any help is great! Happy Holidays, Mark

---

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [December 22, 2005, 6:38pm UTC](https://www.ruby-forum.com/t/acts-as-stateless/74355/2 "2005-12-22T18:38:23Z")

</div>

On Thu, Dec 22, 2005 at 09:26:26AM -0800, M Daggett wrote:

> Is there such a thing that I could use to store sessions in the DB  
> instead of in a cookie so that I can ensure users will be able to  
> access their session data even across several load balancers? We use  
> totally stateless machines here at work and I am worried about  
> deploying a rails app in production that uses a volitile session  
> stored on the machine.

There is the cookie that holds the session key and then there is the  
session  
data itself.

Rails already ships with a db session store.

rake create\_session\_table

Then edit your config/environement.rb (uncomment this line):  
config.action\_controller.session\_store = :active\_record\_store

And that’s it.

But if you actually don’t even want a cookie (session id passed along on  
every url?) then you’ll likely have to do some more work.

marcel

---

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [December 22, 2005, 6:41pm UTC](https://www.ruby-forum.com/t/acts-as-stateless/74355/3 "2005-12-22T18:41:24Z")

</div>

On Thu, 2005-12-22 at 09:26 -0800, M Daggett wrote:

> Is there such a thing that I could use to store sessions in the DB  
> instead of in a cookie so that I can ensure users will be able to  
> access their session data even across several load balancers? We use  
> totally stateless machines here at work and I am worried about  
> deploying a rails app in production that uses a volitile session  
> stored on the machine.

[http://wiki.rubyonrails.com/rails/pages/HowtoChangeSessionStore](http://wiki.rubyonrails.com/rails/pages/HowtoChangeSessionStore)

and though it is a bit old now:

[http://scott.elitists.net/sessions.html](http://scott.elitists.net/sessions.html)

Thats just for sessions though, I’m not sure stateless is the right  
phrase or if you’re asking for something else. Also, usually the  
director in a load balancing cluster can tie a client to a specific node  
until it is inactive for a length of time. If the cluster is only used  
for one application, you can probably tweak that timeout number and use  
a ram filesystem for session files.

Or go to one of the other alternative session stores.

Good luck!

-Matthew B.  
removed\_email\_address@domain.invalid :: 607 227 0871  
Resume and Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [December 22, 2005, 8:17pm UTC](https://www.ruby-forum.com/t/acts-as-stateless/74355/4 "2005-12-22T20:17:36Z")

</div>

Thanks Matthew and Marcel,  
This is very interesting. I will look into this further, this info is  
a great help. My ideal solution will be one where I can have n rails  
apps running concurrently working as a cluster so that they all pull  
the session data from a central DB. This will allow machines to go up  
and down without worrying about users losing their session (though it  
does make the db the single point of failure --which it often is).

On 12/22/05, Matthew B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–
