System requirements


Functional:

1) able to post a message.

2) ability to like and comment.

3) ability to share the post.

4) support for images in the post.

5) System feed

6) Ability to follow users.

7) Shows like count only.



Non-Functional:

1) High availability of the system

2) low latency

3) Faster loading of the pages/feed.





Capacity estimation

say i get 1000 posts per hour.

and have 100 million users.

each post can have maximum of 300 characters.

each character 1byte so 1 post can have 300bytes.

per day 1000 * 300 bytes * 24 = 72,00,000bytes = 7.2mb / day

storage estimation

if we want to estimate the data for say 10 years, we need atleast 7.2mb*360*10 = 25gb

If we consider comments, it can have same and say each post can have an average of 100 comments.

so 1000*100*300*24 = 72,00,00,000 = 720mb/day

for 10 years

720*360*10 = 2.52TB ~3TB (considering user data)

our system will be more read heavy..

say 1: 100

so 1000 posts put means 100 times of that in get requests

100000/requests per hour

24,00,000 per day. 2.4 million requests per day.

bandwidth estimation

incoming request data :

1000 posts

and each post might have an avg of 30 comments within 1hr

(1000 * 300 * 30)/hour = 2.5kb/s

read requests 1: 100 ratio considering

250kb/s









API design

create_post(data, auth_token, timestamp)

delete_post(post_id, auth_token)

update_post(post_id, new_data, auth_token)

like_post(post_id, auth_token)

post_comment(post_id, data, auth_token, timestamp)

follow_user(user_id, auth_token)

unfollow_user(user_id, auth_token)



Database design

since we dont have lot of object relation data, we can go with nosql.

classDiagram

User <|-- Post

Post <|-- Comment

User <|-- Followers

class Followers {

String userId;

String followerId;

}

class Post {

String postId;

String userId;

DateTime createdDateTime;

DateTime lastUpdatedDateTime;

int likesCount;

String content;

}

class Comment {

String commentId;

String postId;

String userId;

String comment;

DateTime createdDateTime;

DateTime lastUpdatedDateTime;

}

class User{

String user_id,

String name,

Date dob

}




High-level design

user visits page: feed should be generated and should be shown






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?