Skip to content

Commit 0dd7c50

Browse files
committed
added Twitter design solution
1 parent a1ad62c commit 0dd7c50

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ The platform currently supports a total of 11 languages: C, C++, Java, Python, C
143143
# Design questions
144144
- package `design`
145145
- `ParkingLotDesign` - design of Parking Lot
146-
- `WhatsAppDesign` - design of messaging system like whatsApp / facebook messager /weChat
146+
- `WhatsAppDesign` - design of messaging system like whatsApp / facebook messenger /weChat
147+
- `TwitterDesign` - design of messaging system with ability to follow and have timeline
147148

148149
# Codility.com tasks
149150
Codility is a platform for hiring stronger programmers faster. Has requirements for time and space complexity.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package iurii.job.interview.design;
2+
3+
/**
4+
* Message service like tweeter:
5+
* https://www.youtube.com/watch?v=KmAyPUv9gOY
6+
*
7+
* Very broad question, design will cover next core features:
8+
* - Sending a tweet (tweeting)
9+
* - Having Timeline (User = Having own tweets, tweets you re-tweeted; Home = tweets from people, you follow
10+
* - Following
11+
*
12+
* Naive solution: Relational database - user and tweet table (one user to many tweets relationship)
13+
* Limitation: big sql query to give all tweets from the users I follow
14+
* - it is hard to do, cause tweet table will grow (indexing table and sharding can be help for a while)
15+
*
16+
* Better solution: characteristics - a lot of tweets, but not many writes. So heavy read system.
17+
* Care about speed but care more about availability and less about consistency.(Eventual consistency)
18+
*
19+
* PUT/POST http tweet - load balancing - geo location (close to your region) - put into in-memory database -
20+
* pre-compute in-memory other home time-lines to Redis cluster. And each timeline replicated 3 times.
21+
* Machines with Redis need to have a lot of RAM to be able to store time-lines.
22+
*
23+
* Optimization is to store time-lines only for users that were active last some days.
24+
* For inactive user computation will take a bit longer to compute it.
25+
*
26+
* Replicas eventually will be the same.
27+
* If a lot of followers (100) tweet will land 3 times more(300).
28+
* Performance problem / weakness - if there is someone famous - a lot of followers of celebrity.
29+
*
30+
* Mixed approach can be used: sql and nosql. If there is a celebrity pre-compute them on read.
31+
*
32+
* Trade offs : fast reads (availability), eventual consistency, space (mainly text - not an issue)
33+
*
34+
* Loadbalancer can find quickly machines where redis machins have needed timelines
35+
*
36+
* Additional:
37+
* - Search is independent system (notifications - push notification)
38+
* - Monetization - advertisement
39+
*
40+
*
41+
*/
42+
public interface TwitterDesign {
43+
}

0 commit comments

Comments
 (0)