⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠
Text Elements
Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad miveniam, quis nostrud exercitaullamco laboris nisi ut aliquip ex ea ommodo consequat. Duis aute irure dolor in reprehenderit i
Lorem ipsum dolor s, consectetur adipng d do eiusmopor incididunt ut labore et dolore magna aliqua. Ut enim ad miveniam, quis nostrud exercitaullamco laboris nisi ut aliquip ex ea ommodo consequat. Duis aute
Application server
upload image
save image
Possible extensions:
- Device could do compression before sending photo to the server.
- More details on how to handle sharding.
posts
image_link: url user_id: ID created_at: timestamp description: str
save metadata
follow user
Graph DB
store follower relationship
each user vertex has indegrees from people that are following them and outdegrees to people that they follow.
How to get the feed for a user?
- Get all the users that the user is following.
- Grab 50 most recent posts from all those users.
- Send list of posts back to the user.
- User can make requests to download actual image files on a scrolling basis.
How to implement?
Push:
- Have a feed generation service that listens for new images posted, and then performs the above steps, writing the post_id to each follower’s feed in the cache.
- This has the downside that for users with millions of followers, millions of updates will need to be made to our feed cache when they upload a photo.
Pull:
- For celebrities, we can instead just have users pull the new photo_ids when they go to view their feed.
- This way, there isn’t an immediate spike when a celebrity posts a photo.
- We could maintain a list/filter of accounts that should use this “pull” paradigm instead of push; could be something as simple as if they have >100K followers.
Feed Generation Service
user ids are shared
request feed
computed feeds
Key
Key
Value
Value
Cache
listen to image writes
find all followers who need to have this image in their feed
write post_id to correct feeds
Load Balancer
Application server
replicate object storage for durability
shard photo storage by geography, because most access patterns are likely geographically bound.
Feed Generation Service
CDN
User checks CDN first for photo. On a cache miss, grab from object store and write back-through into the CDN cache.
cache recent posts locally on device.