Lesson 2 · Unit 04
Design a news feed
Push or pull posts, tame the star account, page with cursors
What you practise
- Fan-out on write vs fan-out on read, the celebrity problem and the hybrid, ranking, pagination with cursors
Try a question from this lesson
Pick one
Ana follows 200 people. To show her feed, the server fetches the recent posts of each of the 200 and merges them. Where does this approach hurt?
Correct answer
Reading: 200 lookups on every feed load
Why
Posting is one cheap write, but every feed load pays for 200 lookups and a merge. Feeds are opened far more often than posts are written, so this design puts the cost on the common path.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Fan-out: on read or on write
Fan-out on read (pull) does the work when a feed is opened. Fan-out on write (push) does it when a post is made: the post's id is copied into a stored feed for every follower.
Push makes reading one lookup. The price is paid at post time, once per follower.
Fan-out on READ (pull)
post: 1 write
feed: ask every followee, merge
Fan-out on WRITE (push)
post: 1 insert per follower
feed: 1 read of a ready-made list11 more exercises in the app
- 2× type the answer
- 5× multiple choice
- 2× fill the blanks
- 1× true or false
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.