0% completed
Designing Twitter
1. What is Twitter?
Twitter is an online social networking service where users post and read short messages called "tweets." Registered users can post and read tweets, but those who are not registered can only read them. Users access Twitter through their website interface, SMS, or mobile app.
Try it yourself
Before looking at the solution, try designing it:
2. Requirements and Goals of the System
We will be designing a simpler version of Twitter with the following requirements:
Functional Requirements
- Users should be able to post new tweets. 2
.....
.....
.....
julian_humecki
· 2 years ago
You correctly say that sharding based on tweet id fixes the hot user problem but then increases latency since you need to query all shards (in the case of a shard taking longer to respond, your latency increases). This is fine.
Your second suggestion is epoch time, and that doesn’t work cuz servers holding recent info with be much hotter than other serivera (due to range based partitioning)
What’s not fine is claiming that if you combine epoch time with a sequence number to be your tweet id that automatically all your problems are solved. You go back to using your hashing function and you still need to query all your db servers.
Do correct me, but I don’t see how that fixes the latency problem.
a7mad.3bass
· 3 years ago
the part at the end which starts with:
"We would need 31 bits to store this number. Since on average we are expecting 1150 new tweets per second, we can allocate 17 bits to store auto incremented sequence; this will make our TweetID 48 bits long. So, every second we can store (2^17 => 130K) new tweets. We can reset our auto incrementing sequence every second. For fault tolerance and better performance, we can have two database servers to generate auto-incrementing keys for us, one generating even numbered keys and the other generating odd numbered keys."
till the end of the solution.. belongs before section 9
Junaid Effendi
· 4 years ago
Trying to understand data sharding. If data is sharded by tweetid, we can fetch top 10 latest tweets globally, but how would we do for a user A lets say? Would not it still have to find first a pool of top tweets for that particular user which would require alot of more work?
ankushp89
· 3 years ago
How do we know it takes 31 bits for epoch seconds and 17 bits for auto incrementing sequence? Where did these numbers come from?
HelloWorld
· 4 years ago
Benefits of putting creation time in the PK are questionable, since timeline is created only from tweets by the users you follow you now need to read vast amounts of data to get any hit. Same with trying to read some other user's page.
Nishikant
· 4 years ago
"Let’s say each tweet has 140 characters and we need two bytes to store a character without compression" - Isn't the character always 1 Byte ?
sabirch
· 3 years ago
Posting Tweet is a single API with media []? Because uploading media is a separate process should we break this API down into two?
Junaid Effendi
· 4 years ago
To handle this, a more intelligent LB solution can be placed that periodically queries backend server about their load and adjusts traffic based on that.
Whats the ideal one here?
Krispy Donut
· 5 years ago
In Instagram or Twitter design, why does the user follow table use PK as both follower and followed? How can I use such a table to find all followers or all followed of a single user?
Surbhi Goel
· 4 years ago
How many total tweet-views will our system generate? shouldnt this be 200M DAU * ((2 *5) * 20 tweets) => 40B/day