retrystorm · Learn · Interview practice · Glossary · Components

Home › Interview practice › React to a Post

React to a Post

Every new post must be indexed for search, announced to followers and counted for analytics. Each subscriber has its own deadline, so size each one for its own.

When a writer publishes a post, three things have to happen, each by a different service:

  • Notify the writer's followers, which readers expect within a second.
  • Search: index the post, which can take a few seconds.
  • Stats: count it for analytics, which can lag by half a minute.

Each service is a subscriber to the posts topic: it gets its own copy of every post, with its own backlog, and works through them at its own pace. Each copy takes a worker about 100 ms.

What it does

  • Read: a reader opens a post.
  • Write: a writer publishes a post, and the app publishes it to the topic.

Workload

A steady 300 rps for 15 seconds, 70% reads / 30% posts, against 10 000 posts. That's 90 posts a second, so each subscriber gets 90 copies a second.

How to build it

The app servers and the database are fixed. The topic and the three subscribers' workers are already on the canvas: the topic is named posts, and the workers notify, search and stats. You connect them, and choose each worker's tier and instances. A worker connected to the topic is a subscription.

  1. Build the path: client, load balancer, app server, database. Then make the app publish posts to the topic, and connect the topic to each of the three workers.
  2. Run it and read each subscriber's own wait. One slow subscriber doesn't slow the others, but each has its own deadline.
  3. Give each subscriber only what its deadline needs: workers cost the same whether they're idle or not.

Part of Chapter 33: Pub/sub.

About · Contact · Privacy · Terms of use