Assuming that 30% of the Post Include some form of media which in average 1MB per files.
Average Read Request Payload Size is 500 Bytes
Average Write Request Payload Size is 1.2KB
Request per Second - 10000 requests
#Requets/Hr - 3.6 millions requests
#Requets/day - 86.4 millions requests
#Requets/Month - 2,592 Billions requests
#Requets/Year - around 32-35 millions requests, if we assume a 5-8% increase in Application usage for the year
Numbers of write based on this estimation with a 1 to 50 ratio is 640 Millions Write/Request where 180 millions would be write request with Media Attachment and 420 Millions would be Simple write request
POST /api/users{ "nickname": "user123", "email": "[email protected]", "dob": "1990-01-01", "first_name": "John", "last_name": "Doe", "gender": "male"}201 Created with user information.GET /api/users/{user_id}{ "user_id": "123", "nickname": "user123", "email": "[email protected]", "dob": "1990-01-01", "first_name": "John", "last_name": "Doe", "gender": "male"}PUT /api/users/{user_id}{ "nickname": "new_nickname", "email": "[email protected]", "dob": "1991-01-01", "first_name": "Jane", "last_name": "Doe", "gender": "female"}POST /api/tweets{ "user_id": "123", "tweet_url": "http://example.com/media.jpg", "hashtags": ["#fun", "#twitter"], "tagged_users_id": ["456", "789"]}201 Created with tweet information including tweet_id.GET /api/tweets/{tweet_id}{ "tweet_id": "101", "user_id": "123", "tweet_url": "http://example.com/media.jpg", "number_of_likes": 10, "hashtags": ["#fun", "#twitter"], "tagged_users_id": ["456"]}GET /api/tweets/searchquery (string for text search), user_id (optional)[ { "tweet_id": "101", "user_id": "123", "content": "Learning API design!", "timestamp": "2023-01-01T12:00:00Z" }]POST /api/favorites{ "user_id": "123", "liked_tweet_id": "101"}201 Created with confirmation of liked tweet.GET /api/users/{user_id}/favorites[ { "liked_tweet_id": "101", "timestamp": "2023-01-01T12:00:00Z" }]POST /api/follows{ "follower_id": "123", "followee_id": "456"}201 Created indicating successful follow.GET /api/users/{user_id}/followers[ { "follower_id": "789", "timestamp": "2023-01-01T12:00:00Z" }]GET /api/users/{user_id}/following[ { "followee_id": "456" }]GET /api/hashtags[ { "hashtag_id": "1", "hashtag_content": "#fun" }]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...
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
In this instance, let's focus on the core functionalities. More specifically, the Tweet Management, Likes/Favorites Management, and Follower/Followee Management
Tweet Management:
This component handle the creation, retrieval, and management of tweets. It allows user to submit, retrieve tweets and/or search for tweets based on criteria or attributes
Scalability and Optimization:
Horizontal Scaling would be the preferred scaling method, through partitioning we can enhance retrieval speed and minimize latency. Moreover we can store frequently accessed tweets using services like Redis.
Storage Structure:
Database : We'll use a NoSQL Database to enhance storage and retrieval accordingly with OLTP systems
In Memory Cache: Use hash table for quick data access using Tweet ID as keys to retrieve tweet informations
Using Indexing, we can use ElasticSearcj to optimize retrieval based on Keywords or Hashtags
Likes/Favorites Management
This component manages the functionality for users to like a tweet, it stores the relationship between the users and the tweet they have liked.
Scalability:
This feature is write heavy, hence we can use append-only logs in combination with btach writes to improove write perfomance while lowering transaction costs. Additionally, this component can be partitioned based on userID's and TweetID's to optimize write and ready transactions
Data Structures:
This specific use case is perfectly suited for a relational database, as it maps a many-to-many relationship between both entities consisting of User_id and liked_Tweet_id
In Memory Structure: Considering the nature of the relationship we could map it as either a set or tuple for quick retrieval
Batch Processing who be required in this instance to minimize cost, hence the best option would be to store recent write operation in a virtual queue to later process them as batch on periodical intervals
Follower/Followee Management:
This component maintains a relationship table that tracks which user follows which other users.
Choice of Database
NoSQL, while a SQL database would provide the structure required to make complex queries necessary for our analytical service. However the number of read request in our system would make the management of cost and complexity quite challenging. On the other hand, NoSQL databases are more suited to Online Transactional systems, better suited for horizontal scaling.
Caching Strategy
Using an in-memory cache can significantly boost performance and reduce latency, maintaning cache consistency however oppose some challenges especially when it comes to maintaning data integrity and consistency. In this case by using Redis our abiliy to horizontally scale the In memory cache storage increase significantly
Batch Processing For Write Transactions
Real-time updates allow immediate reflection of likes in the UI, but can lead to increased write loads on the database. Batch processing can delay updates but decreases write frequency.
By leveraging NoSQL databases, in-memory caching, and graph-based representations for dynamic user relationships, we focus on creating a responsive and reliable platform. However, each decision also comes with potential risks, whether that involves managing cache coherence or ensuring that the database schema remains adaptable.
In a system like this, the trade-offs effect usability for the end-users while also allowing for future growth and feature expansions. Continuous monitoring and iteration based on usage patterns would also be crucial to adjust as user engagement evolves.
Advertisement and Business Profiles:
Third-Party API Integration
Advanced Analytics and ML Recommendation:
Enhanced Security Protocols:
Server Failures
Security
Database Failures
Traffic Spikes