System requirements


Functional:

Users can create accounts and log in.

Users can follow and unfollow other users.

Users can post updates with text and images.

A user’s feed should display the latest posts from the users they follow, sorted by recency.

The feed should support pagination.



Non-Functional:

The system should handle a high number of concurrent users (scalability).

Ensure low latency for fetching the news feed (performance).

Posts should be highly available (availability).



Capacity estimation

Assuming a daily active user count to be 100M and read to write ratio as 10:1.

We can see that there will be 10M writes daily.

Assusming a post can have 280 characters and 2 images per post, 5 mb each.

Since we are allowing images to be uploaded. I'll be using amazon s3 or blob for image management and storage.

I'll be using NoSQL DB as primary storage for the system owing to high availablility for a social media platform and high scale of data that needs to be handled.


Here are the calculations for the storage:

Since a post can be 280 characters long, so 280 bytes of data per post. Adding other metadata and things, lets assume total data per post will be 1KB. Now, there are 10M writes per day. So total data obtained per day will be:

1KB*10M=10GB data per day

Also we will be having images as well. So total data for images: 10MB*10M~100TB.

Assuming we will be storing the data for 5years:

total data obtained over 5 years are:

data from posts:10GB*365*5=18TB

data from images: 100TB*365*5=~180PB


API design

Here are the most commonly used APIs for this system:

APIs for authentication:

  1. /signup

Type: POST

Params: email, password, name, mobile No.

2. /signin(/login)

Type: POST

Params: email, password

APIs for feed:

  1. /updates?userid={userId}&limit=20
  2. Type: GET

APIs for user:





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...






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...






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...






Failure scenarios/bottlenecks

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






Future improvements

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