Problem clarify
- No one expects you to design a real twitter in 50 minutes.
- You need to focus on several core features first then dive deep.
- Interviewer will guide you to specific field to get some property of you.
Core features
- Tweeting
- Timeline
- User
- Home
- Following
Naive solution (Synchronous DB queries)
Two Tables - User Table
ID | Name | ….. |
---|---|---|
ID1 | Name1 | ….. |
ID2 | Name2 | ….. |
ID3 | Name3 | ….. |
Two Tables - Tweets Table
ID | Content | User |
---|---|---|
ID1 | Content1 | User1 |
ID2 | Content2 | User2 |
ID3 | Content3 | User3 |
User ID is the primary key of the User Table.
A primary key is a special relational database table column (or combination of columns) designated to uniquely identify all table records.
A primary key’s main features are:
- It must contain a unique value for each row of data.
- It cannot contain null values.
Limitation of architecture (point out the bottlenecks)
It is impossible to retrieve the tweets in the one giant tweets table with millions of TPS.
Characteristics (What is optimize for?)
Focus more on availability than the data consistency. (eventual consistency)
Optimized solution (Give high level overview)
Mixed solution (In memory Database + Synchronous DB queries)
We could mix the IMDB-Redis with Synchronous DB look-up of followers shows as above.
Trade off (Time VS Space)
Always could be negotiable between time and space.