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