createTweet(user_id, tweet_id, content, timestamp, authorization_token)
getFeed(user_id, authorization_token) : get feed (timeline) for current user
follow(user_id, target_user_id)
Option 1 : Relational DB to store the tweet metadata and Object Store (S3, GCS) to store media files since they are large in volume.
Tweet table :
Follow table :
System is going to be read-heavy. For relational DB it could be difficult to scale and reduce complexity as the data increases in volume
For this reason, we can consider NoSQL databases :
Option 2 :
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
flowchart TD
B[client]-- read tweet --> S[app server]
S[app server] --> C[cache]
C -- get tweet metadata --> RD[Relational Database]
RD -- tweet details (URL) --> S
S -- send media url --> B
B -- request media --> CDN[Content Delivery]
CDN <-- pull CDN --> OS[Object Storage]
Write tweet:
sequenceDiagram
Client->>App-Server: write tweet
App-Server->>writeAPI: write_request
writeAPI->>RelationalDB: write tweet metadata
writeAPI->>ObjectStorage: write media
writeAPI->>Cache: store metadata
writeAPI->>App-Server: transaction complete
Read tweet:
(if present in the cache)
sequenceDiagram
Client->>App-Server: read tweet
App-Server->>readAPI: read_request
readAPI->>Cache: is present
Cache->>App-Server: tweet content
App-Server->>Client : tweet metadata
Client->>CDN: get media
CDN->>Client : tweer feed
(if not present in the cache)
sequenceDiagram
Client->>App-Server: read tweet
App-Server->>readAPI: read_request
readAPI->>Cache: is not present
readAPI->>relationalDB : get tweet metadata
relationalDB->>readAPI : tweet metadata
readAPI->>Cache: add tweet metadata
readAPI->>App-Server: tweet metadata
App-Server->>Client : tweet metadata
Client->>CDN: get media
CDN->>Client : tweet feed
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Scaling DB :
Improvement-1 : system is read-heavy - maintain read-only replicas of the relational DB
Improvement-2 : Sharding :
Creating timeline :
Cache:
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?