title: Is Rails shared-nothing or can separate requests access the same runtime variables?
body: <p>PHP runs in a shared-nothing environment, which in this context means that every web request is run in a clean environment.  You can not access another request's data except through a separate persistence layer (filesystem, database, etc.).  </p>
  
  <p>What about Ruby on Rails?  I just read <a href="http://rubythis.blogspot.com/2006/11/gotcha-ruby-class-variable-scope-is.html" rel="noreferrer">a blog post</a> stating that separate requests might access the same class variable.</p>
  
  <p>It has occurred to me that this probably depends on the web server.  <a href="http://mongrel.rubyforge.org/wiki/FAQ" rel="noreferrer">Mongrel's FAQ</a> states that Mongrel uses one thread per request - suggesting a shared-nothing environment.  The FAQ goes on to say that RoR is not thread safe, which further suggests that RoR would not exist in a shared environment unless a new request reuses the in-memory objects created from the previous request.</p>
  
  <p>Obviously this has huge security ramifications.  So I have two questions:</p>
  
  <ol>
  <li>Is the RoR environment shared-nothing?</li>
  <li>If RoR runs in (or <em>might</em> run in some circumstances) a shared environment, what variables and other data storage should I be paranoid about?</li>
  </ol>
  
  <p><strong>Update: I'll clarify further.</strong>  In a Java servlet container you can have objects which persist across multiple requests.  This is typically done for caching data which multiple users would have access to, database connections, etc..  In PHP this can not be done at the application layer, it must be done in a separate persistence layer like Memcached.  So the twofold question is: which scenario is RoR like (PHP or Java) and if like Java, <em>which</em> data types persist across multiple requests?</p>