Design Twitter — Microservices Architecture of Twitter Service
Twitter is an online social networking service where users post and read short messages called “tweets”.
Most candidates try to design Twitter as a monolithic service in System Design Interview. If you check several existing online resources, they also try to design Twitter as a monolithic service. However, in our opinion, designing a gigantic service like Twitter as a monolithic service shows that the candidate lacks experience in designing distributed systems. Nowadays, it is a norm to design distributed systems in terms of microservices and even lamdas (or functions). No one is writing a new service as a monolithic service and companies are gradually converting their big monolithic services to a set of microservices. Hence, the candidates should discuss Twitter system design as a microservices architecture.
Let us discuss the functional and non-functional requirements now.
The following are the main functional requirements for the Twitter service.
1. The users can post new messages or tweets (this is a write operation).
2. The size of a tweet is 140 characters at most.
3. A user can delete his tweets but not update/edit his posted tweets (this is a write operation).
- Allowing updates to already posted tweets can affect the design significantly.
5. The users can mark favorite tweets (write operation).
6. A user can follow another user (write operation) — Following a user means that the user can see the other user’s tweets on his timeline.
7. Two types of timelines can be generated (read operation).
- A user timeline comprising of the last N number of his tweets (let us say N=1000)
- A home timeline that is generated from the popular tweets of the users he is following in the descending order of time
8. The users can search the tweets based on keywords (read operation).
9. The users need an account in the service to post or read tweets.
- We will be using an external identity provider for the time being