The blog of freelance Designer & Developer, David Rice.
25 Nov 2008
There aren’t that many resources about the relatively new option for session storage in Rails. So while I have been migrating a legacy application to Rails 2, I wanted to note some of my thoughts.
Cookie Storage
Pros
- Storage is now distributed to the client within the session cookie.
- Up to 4k of data can be stored within it securely thanks to the neat work done by the core team.
- It’s a simple solution to provide scalability by default, no more centralized drb, memcached, db, filesystem to store your sessions.
- Slight performance boost with the session not having to be retrieved, it is sent with the request.
Cons
- Session data is transmitted to the client, albeit encrypted and tamper proof.
- An extra overhead of roughly 162 Bytes per request in the http headers when sessions are turned on, due to the longer session_id.
- You can only store 4k.
Active Record Storage
Pros
- You can store as much session data as you want.
- If the session data is super secret, it’s never transmitted over the wire.
- Roughly 162 Bytes less per request in the http headers when session are turned on.
Cons
- Another moving part to manage (i.e. clearing the Active Record sessions table).
- Slight performance hit retrieving the session.
So, in conclusion the Cookie Storage is a great default for Rails as it will suit the vast majority of applications. I’ve found it great for recent projects, it mainly means you don’t really have to think about sessions anymore.
More Resources
- Ryan Daigle’s article about cookie session.
- Scott Baron’s excellent performance comparision.
- A great run-down on all of the other session storage options in a lot more detail over on Err the Blog.
- email me@davidjrice.co.uk
- phone me on +44 7590 538 303
If you need help with the Design, Build, Management, Hosting or Support of your project do get in touch, I'd love to hear from you!
Recently
- 22 Apr » HTML5 Validator.nu ruby gem
- 28 Sep » ActiveMerchant Support for Realex
- 09 Sep » Getting Real with Realex
- 04 Sep » Back in Black
- 25 Nov » Rails Session Storage Cookie Vs Active Record
- 06 Jun » Get Exceptional
- 21 Apr » git and github ftw
- 19 Apr » Co-Working Belfast, Put Your Money Where Your Mouth Is
- 28 Mar » Co-working Belfast Plan
- 26 Feb » Do Not Buy an Apple AirPort Extreme Base Station, They Crash and Burn
- 13 Feb » Ssh, Presentation in Progress