Requirements

  • Store/Get Images
  • Like + Comment + Like a comment on Image (Can we comment on a comment? i.e. recursive comments?)
  • Follow someone
  • Publish a news feed

Data access pattern

Data access pattern --

* Get all the posts made by a user + sort by timestamp
* Get all the comments made on a post + sort by timestamp
* Get the number of likes on a post/comment
* Get list of users who have liked a post
* Get all posts made by a user's followers and sort by timestamp

Data schema

TODO — what database to use? and did you decide on the same?

  • Likes Table: ID, Type, Active, ParentID, UserID, timestamp
    [ParentID — can be a comment or a post,
    Active — means is active or deleted
    Type — comment or a post]
  • Post Table: UserID, PostID, text, Image URL, timestamp
  • Comment Table: ID, text, timestamp, PostID

How to get number of likes for comment/post?

Approach # 1

  • select (*) from like where PostID = ‘abc’;
  • very slow

Approach # 2

  • hold “likes” in a column in likes/posts table

Post Table: UserID, PostID, text, Image URL, timestamp, likes
Comment Table: ID, text, timestamp, PostID, likes

  • whenever there is a like on the post insert in like table and do +1 in likes column
  • this column is an aggregated value and doesn’t belong with posts/comments table data.

Approach #3

  • Create an Activity table [ParentID, Likes]

Following/Follower feature

Data access pattern --

* Who follows user Hawking?

Select * from following where followeeId = 'Hawking';

* Which users does user Hawking follow?

Select * from following where followerId = 'Hawking';
Following Table

High Level Design

Design 1 — Not scalable at posts service level

Design 2 — Precompute

  • Problem here is that when a celerity creates a post there will be lot of cache update + lot of notifications

Design 3 — Precompute with celebrity problem

TODO

  • More detailed read to resolve celebrity problem — push vs pull vs hybrid? — algorists
  • Image upload and processing flow
  • Image render flow + CDN integeration

Resources

  • Arpit bhiyani
  • Interview ready
  • Alex xu template
  • scaler videos
Unlisted

--

--