What to store in the Cache?


so this chapter suggests storing the Post object itself in the cache as well, my question is that why not just store the PostID in the cache, it would reduce the size of cache significantly:

lets say: Cache = Hashtable{userID, sortedset(PostID)}
est size = 8 bytes + (8+20(Sortedset overhead)) * 500 + 20 (hashtable overhead) = 14 k bytes/ user * 300MillionUsers = 4.2 TB -> 42 machines (vs 1500 if we store the entire Post)

Later the Newsfeed service would hydrate this with the actual posts, on-demand.


CC @Design_Gurus

Hi @milo_t

We appreciate your effort and yes, your approach is correct. In this chapter, we were more focused on reducing time rather than space to give users a better experience as putting the whole object rather than reference so that data would lie in that cache and would be displayed quickly. Your approach is also fine, you can follow it.

Happy learning :slight_smile:

1 Like

Thanks @Shaheryaar_Kamal!