Activity Feeds with Redis
The how:
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”
Original title and link: Activity Feeds with Redis (NoSQL databases © myNoSQL)