Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
REST APIs
POST /tweet
-- messages
-- user_id
-- topic
-- timestamp
POST /follow/{user_id}
POST /like/{tweet_id}
GET /tweet/{user_id} # get tweet from a user
GET /toptweets/{k} # get top k tweets
The request starts from the client and goes to API gateway, then it goes to tweet service (for APIs like post a tweet, add likes to a tweet, get all tweets from a user) or user service (for APIs about the user, like follow a user)
When the user posts a tweet, the request goes to tweet service through API gateway, and the parsed data from tweet service will be stored in the DynamoDB database's tweet table, with clear info of tweet id, messages, user id, timestamp and etc.
When the user opens the feed, the feed service will return several most recent posts (sorted by timestamp) to the user from the user's followed people.
DynamoDB
Tweet table:
tweet id (primary key)
user id
topic
message
timestamp
likes amount
user likes the tweet []
Follow table
user id
followed user id
created at
User table
user id (primary key)
followers []