|
| 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