title: Architecture for Redis cache & Mongo for persistence
body: <p>The Setup:
  <br />
  Imagine a 'twitter like' service where a user submits a post, which is then read by many (hundreds, thousands, or more) users.</p>
  
  <p>My question is regarding the best way to architect the cache &amp; database to optimize for quick access &amp; many reads, but still keep the historical data so that users may (if they want) see older posts.  The assumption here is that 90% of users would only be interested in the new stuff, and that the old stuff will get accessed occasionally.  The other assumption here is that we want to optimize for the 90%, and its ok if the older 10% take a little longer to retrieve.</p>
  
  <p>With this in mind, my research seems to strongly point in the direction of using a cache for the 90%, and then to also store the posts in another longer-term persistent system.  So my idea thus far is to use Redis for the cache.  The advantages is that Redis is very fast, and also it has built in pub/sub which would be perfect for publishing posts to many people.  And then I was considering using MongoDB as a more permanent data store to store the same posts which will be accessed as they expire off of Redis.</p>
  
  <p>Questions: <br />
  1. Does this architecture hold water?  Is there a better way to do this? <br />
  2. Regarding the mechanism for storing posts in both the Redis &amp; MongoDB, I was thinking about having the app do 2 writes:  1st - write to Redis, it then is immediately available for the subscribers.  2nd - after successfully storing to Redis, write to MongoDB immediately.  Is this the best way to do it?  Should I instead have Redis push the expired posts to MongoDB itself?  I thought about this, but I couldn't find much information on pushing to MongoDB from Redis directly.</p>