Requirements


Functional Requirements:


  • Allow users to tweet messages up to 140 characters.
  • Enable users to follow other users.
  • Allow users to like tweets from other users.
  • Display tweets from followed users in the home feed.
  • Show top K popular tweets in the home feed based on likes and followers.



Non-Functional Requirements:


    List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...


Capacity Estimation

Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...




API Design

Tweet - tweet:

GET /tweet/v1/tid

POST /tweet/v1/

Delete /tweet/v1/tid


Tweet - Like:

GET /tweet/v1/tid/like

POST /tweet/v1/tid/like


User:

GET /user/v1/uid

POST /user/v1

PATCH /user/v1/uid


Follower:

GET /follower/v1/uid

ADD /follower/v1/uid



Workflow:

  1. Client login to Auth server
  2. A token is assigned for login afterward
  3. Login into server, checking below information in cache
    1. Followers
    2. Top Feeds in last 5 minutes
  4. If hit, just sent to client. Else fetch from Database then update Cache



Database Design

Tweet Table:

UID int, primary key

TID int

Timeline date, index

description String

Like int


User Table:

UID int, primary key

email var, index

Followers List

Following List



Detailed Component Design


Gateway/Load balancer: Responsible for auth, and direct request to the specific server.


Tweet Server(Web Server): Work with Tweet and Like API, when received a Tweet, it push to the queue(Kafka) and wait for Tweet Scanner to process.


Tweet Scanner(Serveless/Lambda): process the Tweet and store the result into Mongo DB.


DB:

Store the Tweet and User data.


Feed Server:

Process the feed if cache is not hit.