High-Level Design
- Popular tweets along with static content like. images and videos can be cached in a CDN and served directly to users
- Our API server will rate limit all requests sent to it and let the users know that they are being rate limit if they are making too many requests
- Tweet service and search service would be handled by two different servers which all would be horizontally scaled
- All requests will pass through a load balancer which can balance requests based on average response times of servers
- A cache ensures that popular tweets are stored there and reduce stress on our servers
- We can use a message queue like Kafka to decouple our server from our database. When a tweet is handled by a server, it is then added to a message queue and then written to the database from there
- We can do a similar thing for creating our reverse index as well, add the tweet to a message queue like Kafka and let the index be created by consuming messages from the queue
flowchart TD CL[client] --> CDN[CDN] CDN-->API[API Gateway] API --tweet(), follow(), search() --> TW[Tweet Service] TW --search()--> SE[Search Service] TW -->DB[Database] SE -->SI[Search Index] TW --push-->MQ[Message Queue] IDX[Indexer]--pull-->MQ IDX-->DB TW-->CC[Cache] SE-->CC IDX-->SI