System requirements


Functional:

List functional requirements for the system (Ask the chat bot for hints if stuck.)...


Compose and share tweets.

Favorite tweets.

Follow other users.

Track updates of other users.




Non-Functional:

List non-functional requirements for the system...


High Availability

Low latency

Eventual Consistency

Partition Tolerance




Capacity estimation

Estimate the scale of the system you are going to design...


500 mil DAU

Storage = 250 bytes X 4 tweets per day X 500 mil

= 500 GB/day




API design

Define what APIs are expected from the system...


POST /api/v1/users

{

userId,

userName,

emailId,

phone No,

dob,

gender

}


POST api/v1/tweets

{

tweetId,

userId,

tweetDescription,

timestamp,

likesCount,

shareCount,

}


POST api/v1/follow

{

followerId

}




Database design

Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...


User {

userId,

userName,

emailId,

phone No,

dob,

gender

}


Tweet

{

tweetId,

userId,

tweetDescription,

timestamp,

likesCount,

shareCount,

mentions

}





High-level design

You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...







Request flows

Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...


When new User joins, or a new user follows another user, request goes from client to API gateway to User Service to relational database PostgreDB.


When a user tweets, request goes to API gateway to Post Service then both to Cassandra and Kafka. Feed Generation Service reads tweet from kafka, gets user followers and generates feed and puts it in Feed Cache for all users.







Detailed component design

Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...






Trade offs/Tech choices

Explain any trade offs you have made and why you made certain tech choices...

Database SQL vs NoSQL.

Cassandra was chosen for storing tweets as high write/read volume is required. Cassandra scales well, so it is well suited for those operations.


For User data RDBMS is used as it supports strong consistency




Failure scenarios/bottlenecks

Try to discuss as many failure scenarios/bottlenecks as possible.


Thundering Herd Problem





Future improvements

What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?