1B users and 500M are active users. Let’s say each user views 5 videos per day
Read QPS: 500M * 5/100K = 25K videos/secs
Write QPS: Let’s say upload:view ratio is 1:200. So 25k/200 =200 videos/sec
Let’s say 200 videos/sec are uploaded and each video is 10 mins and each min is 50MB. 6k videos/min * 10 min* 50Mb =3500 GB/min!
userDetails, videoDetails (title desc,loc,tags,thumbnail,fileDetails))
HTTP 202 (request accepted)
Search GET https://api.google.com/youtube/v1/search
Query Params: q, location…
Let’s assume 500M places. Each place will have a businessId (8bytes) + Name (256 bytes) + lat(8) + long(8) + desc(512)+category(1 byte) = 1KB.
1KB for each place * 500M = 500GB
We also need to store reviews, photos and ratings of a place. …
User sees the relevant trending topics related to his geolocation
User can click on a trending topic and get all the tweets by time
Non Functional Requirements
Availability 9.99999 downtime is 1min/per year
Latency is 200ms
tweets -> tweets analyzer -> tweets filter -> velocity service
tweets analyzer: tf x idf
velocity service: df/tweet delta time
A: Just use a timestamp
Q: what is I have 2 different computers and 2 requests come in at the same time?
A: Just add a computer id + timestamp. Cool?
Q: What if I send 2 requests at the same microsecond from the same computer?
A: Add a counter! computer id + timestamp + counter.
Q: Wait a minute. I can set computer time to old timestamp what then?
A: Ok fine! Just use the computer id + counter.
Q: What if I run out of counter? Or my computer restarts and so does my counter?
A: Write our…
Async vs Sync
Push vs Pull
Observer design pattern
UserId takes 8 bytes and counter takes 4 bytes, Let’s assume we are limiting 500 or more requests per hour per user.
(8 + 2) =10 Bytes for each user
For 1 Million users, we need 10MB
UserId takes 8 bytes and epoch time takes 4 bytes. Let’s assume we are limiting 500 requests per hour.
8 + (4 * 500) = 3K + 2K sorted set and hashtable overhead = 5K/user
For 1 Million users, we need 5GB
Sliding Window Algorithm takes a lot of memory compared to the Fixed Window; this would be a scalability issue…
Assume 1 billion web pages are downloaded every month. Each page is 500KB. So 1 Billion * 500K = 500TB/month. So 1 year is 500 * 12 = 6PB/year and 30PB/5 years.
1B /30 days/90000 secs = 400pages/sec
DFS vs BFS for Crawling
User shortens a URL
User is redirected when shortened url is sent
Write QPS 2k
Read QPS 2 x 3 = 6k
One year, 2000/sec * 80,000 sec/day * 400 days = 64_ 000_000_000 = 64B links. For 5 years we need 1Trillion roughly.
62^n = 1Trillion log62(1Trillion) roughly 7 characters
Response: 201 Created with the short link
Response 301 redirect (permanent redirect)/ 302 redirect (temporary redirect) or 404 Not found or 400 if slug more than 7 characters
If we allow c different characters in a n-character slug, we can have c^n combinations.
Let’s assume we have 500 cities and each city has 10 theaters. Each theater has 2k seats and has 10 shows per day.
Let’s assume each booking needs 50 bytes…
Build dynamic segmentation
A/B testing tools
Android has default opt-in. iOS has default opt-out.
Age of the notification: iOS PN shows up on lock screen but vanishes when user unlocks later. Android displays notifications. Android provides user snooze option.
Rich content like images and stories in PN now in both Android and iOS.