Assumptions
With the above assumptions, we can say the below
Total number of tweets per day: 200M * 5 = 1 billion tweets/day
Tweets with media = 10 million tweets/day
Number of write requests per second: 1 billion / (24 * 3600) = 12k requests/sec
Storage Estimations
Text Tweets : 1 billion * 500 bytes = 500 GB / day => ~ 950 TB for 5 years
Media Tweets : 10 million * 500 KB = 5 TB / day => ~ 1 Petabyte for 5 years
During a big news break or celebrity interaction we would have huge traffic on the platform, let's try to calculate the Peak traffic in an hour.
Assumptions:
Calculation:
Concurrent Users= 30 billion searches / 10 seconds = 3 billion concurrent users
Now, that we already know we have 200M active users, let's make the below assumptions.
Assumption:
Total Search Requests per Day = 200M * 30 = 6 billion
Number of Servers for Search Requests = 6 Billion / 100K * 1440 sec = ~416 servers
1. User Authentication API:
2. Tweet Creation API:
3. Tweet Retrieval API:
4. Real-time Updates API:
5. Personalized Content API:
6. Trending Topics API:
7. Tweet Interaction API:
For the database design we will create the following tables
To see how these tables are linked together have a look at the class diagram.
Each database type is chosen based on its strengths in handling specific types of data within the Twitter Search System, providing a balanced and efficient solution
In summary, employing hash-based partitioning, range or composite sharding, multi-datacenter replication, and global load balancing with dynamic routing will contribute to the scalability, availability, and performance of the Twitter Search System, aligning with the characteristics of the data and user interactions on the platform.
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...
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...
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?