ruby: All content tagged as ruby in NoSQL databases and polyglot persistence
One brief note about architecture: since it’s impractical to simply query the activity of 500 friends, there are two general approaches for building scalable news feeds:
- Fan-out on read (do these queries ahead of time and cache them)
- Fan-out on-write (write follower-specific copies of every activity so when a given user asks for a feed you can retrieve it in one, simple query)
And why Redis:
First off, why Redis? It’s fast, our data model allows us to store minimal data in each feed entry, and Redis’ data-types are pretty well suited for an activity feed. Lists might seem like an obvious choice and could work for a basic feed implementation, but we ended up using sorted sets for two reasons:
- If you use a timestamp as the score parameter, you can really easily query for feed items based on time
- You can easily get the union of multiple sorted sets in order to generate an aggregated “friend feed”
Silver: database cacher, indexer and searcher
Probably because Silver was released by a publisher, this new open source library got some press today:
Enter Silver. Silver is designed to be a simple, lightweight wrapper for all your calls to a database that you want to cache or index with Redis. It is completely database/web-service agnostic so you should be able to use if for anything you can imagine caching.
Couple of thoughts about this new Ruby library:
- it is not a transparent caching layer that can be used in your application. Basically you’ll have to rewrite your app to use it.
- there is not way to update the cache
- the indexer is — in their own words — “stupidly simple fuzzy text search”
Project is hosted on GitHub.
redis-store: Redis-backed Tomcat session store
Definitely not benefiting from the same media buzz, Jonathan Leibiusky pushed to GitHub a Redis-backed Tomcat session store. Plugging this into your Tomcat would require just updating the
<Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="true" maxActiveSessions="1" minIdleSwap="1" maxIdleSwap="1" maxIdleBackup="1"> <Store className="org.apache.catalina.session.RedisStore" host="localhost" port="6379" password="something" database="0" /> </Manager>
Tomcat default session store is disk, so if your app is a heavy session users, you’ll probably see a boost in performance.
For the moment I haven’t tried this myself and I suppose it’ll need some extensive testing before going into production. ↩