Member-only story

System Design Interview: mini Twitter

Eileen Pangu
6 min readApr 24, 2020

--

How would you design Twitter? It’s essentially the same question as designing Facebook, Linkedin, or many other social media services. The key scenario in question is usually that a user can follow or unfollow other users. Any user can tweet stuff. A user should be able to see tweets, displayed in a certain order, from the users she is following — the so-called timeline. And the core discussion point is designing for scale. I like simple design questions. Interviewers often like them too because the goal of the system design interview is to let the candidates drive the conversation rather than interviewers explain the questions at length. So, without further ado, let’s dive in.

Users

First and foremost, we have users, so we need a user table. Each row in the user table represents one user, storing a unique uid and the user profile. In addition, we’ll also store the number of followers and followees of the user. All the social media services show the number of a user’s followers and followees. So this is for fast lookup. And as we’ll see later, this also provides information for optimization.

Relationships

Secondly, users have relationships. We use two tables, one for following, the other for followed by. When user A starts following user B, four table rows will be updated. “A following B” and “B followed by A” will be added to the following and followed by tables respectively. A’s followee number and B’s follower number will both increment by 1. The transaction update…

--

--

Eileen Pangu
Eileen Pangu

Written by Eileen Pangu

Manager and Tech Lead @ FANG. Enthusiastic tech generalist. Enjoy distilling wisdom from experiences. Believe in that learning is a lifelong journey.

No responses yet