retrystorm · Learn · Interview practice · Glossary · Components

Home › Interview practice › News Feed

News Feed

Design Inkwell Home: a fast, fresh feed for every reader, when most writers have a few followers and a few have thousands.

Design Inkwell Home, the page every reader opens first: the newest posts from the writers they follow. It has to open fast, show new posts within a couple of seconds, and cope with the writers who have thousands of followers.

What it does

  • Read: a reader opens their home feed.
  • Read: a reader opens a trending post, one of the most popular writers' newest.
  • Write: a writer publishes a post.

How feeds work

Assembling a feed when it's opened is slow, because it gathers from every writer the reader follows. A feed that was built ahead of time sits in the feed store and reads in a few milliseconds, but then every new post has to be copied into the feed of each of the writer's followers.

Workload

A steady 1 000 rps for 15 seconds, over 100 000 feeds, from four clients:

  • readers: 650 rps opening feeds, spread evenly over all feeds.
  • trending: 250 rps opening trending posts, mostly the same few.
  • writers: 98 posts a second from ordinary writers.
  • celebs: 2 posts a second from five celebrities, whose posts every reader wants right away.

What's fixed

The app servers, the posts database's speed and a worker's speed are fixed. Building a reader's feed from the posts database takes about 80 ms. Most writers have 30 followers, and the 1% with the biggest audiences, the first 1 000 keys, have 2 000. Copying a post into one follower's feed takes a worker about 5 ms.

How to build it

You choose the rest: which stores, how big, how many workers, and above all what each request does. Select a connection out of the app server and its Routing section can send only some keys down it: reads or writes of keys from one number up to another. Keys below 1 000 belong to the heavy writers.

Steps

  1. Build the path for readers and writers, and connect all four clients to the load balancer. Run it as it is.
  2. Compare feeds built when read (pull) with feeds built when written (push), and read what each costs.
  3. Then give the heavy writers their own route.

Part of Chapter 37: News Feed.

About · Contact · Privacy · Terms of use