Wednesday, January 31, 2018

Being an interviewer: System design - design instagram

January 31, 2018

Introduction


I do not have chance to sit in the classroom to learn the system design, and then I do not plan to learn system design today. But today the peer had super performance, first 40 minutes he passed through all four algorithms, including array, recursive, graph and then dynamic programming. So I asked him to have a system design question, design instagram with scalability.


System design best one


It is so enjoyable to learn through the best system design in the world.

Here is the transcript. And the best thing is that I can watch the video again and again, learn every step he developed the design. The interviewer has more than 10 years experience to work on search engine in the city of Seattle, USA.

Every time I feel stressed to learn system design, I just go back to watch the recording, and then learn from the best.

I remembered one time I met the senior developer working for Microsoft fifth time in mock interview. I told him that I work as an interviewer in another platform. And he asked me how much I get paid. I laughed about it.

Transcript starts here:
Design Instagram:-
Use cases:-
1. Upload photos to instagram
2. Download photos
3. Follower should be able to see my upload in their timeline
4. Home timeline
100M users
10M active users
3-4 photos per day
~200 people to follow
0-10M
Average size ~400KB
40M *400KB :- ~4tb of data stored per day
APIs :-
1. Upload(UserId, Raw photo, app Id)
2. HomeTimeline(UserId);
Data Model
User :- List<UserId> followers
Location , other UserMetadata , createdDate
Photo :-
Url of the thumbnail
Url of the full Image
UserId of the uploader
Timestamp of upload
Metadata about quality
Follower
User1, User2 :- User2 is following user1
timeLine
List<Post>
post :-
UserId
photo details :- photoId
10M followers :-
Upload -> load balancer(round robin) - > how many followers I have .
If followers is <1000 :- Update the in memory timeline for the 1000 users
if followers >1000 :- store this info in the UserLEvel Cache
Storing :- go through a thumbnail server and encoding server :- encode in hd /sd quality :
- Generate the photo Id :- Push to the timeline of my followers
shard key :- UserId :- hot user
timestamp :- hot node :- all writes are going
timestamp :- photoId :- help us retrieve the recent photos and avoid hot node in this case
end here.

Follow up 

Nov. 15, 2019
I like to review the notes again. I like to spend 10 minutes and learn from my own experience. What should I do in terms of system design? I did not have chance to write so many content in my Facebook onsite in August 2019. I was interrupted before I like to talk about diagram, distributed file system or storage.

No comments:

Post a Comment