Sign in

READMF

Requirements

Functional

  1. User searches a video based on titles
  2. User should be able to comment/like/share

Non functional

Estimation

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

Storage:

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!

API

Upload POST https://www.googleapis.com/upload/youtube/v3/videos

{

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…


READ MF

Requirements

Functional

  • See places ranked higher
  • Add or see reviews (I’m assuming some trusted users and avoiding abuse scenario)
  • Do we need a map to take to the restaurant like

Non functional

  • latency 200ms
  • Read heavy

Estimation

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


READ MF!

Requirements

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

Design

tweets -> tweets analyzer -> tweets filter -> velocity service

tweets analyzer: tf x idf

velocity service: df/tweet delta time

lat long

{

tweet

rank

trend

lat

lng

}


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…


Programming Paradigm

  • Procedural
  • Object oriented
  • Functional
  • Reactive

Reactive Manifesto

  • Responsive- reply within a time limit. If you need to send a report, go async and say we will reply in email.
  • Resilient- errors are first class system. Better handle them.
  • Message driven. whatsapp vs phone call.

Async vs Sync

  • Main program loop not blocked.
  • Without RxJava, you need a callback. Callback hell!

Push vs Pull

  • Most programming model is Request — Response model which is pull.
  • RxJava is push based. We can use callbacks for push too.

Observer design pattern

  • when an something changes subject updates all other observers
  • Subject…

READ MF

Requirements

Estimation

Fixed Window

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

Sliding window

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…


READ MF!

Requirements

API

/crawl

/search

Estimation

Storage

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

Database

Design

  • Web archiving
  • Web mining
  • Web monitoring

DFS vs BFS for Crawling

  • We can crawl sub URL’s by DFS (depth first search) or BFS (breadth first search) starting from root page and traverse inside. BFS with queue is recommended here so that we can keep adding the URL’s to the queue as FIFO (First in First Out).

Seed URL


Requirements

Functional

User shortens a URL

User is redirected when shortened url is sent

Non functional

Estimation

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

API

POST http://api.gitly.com/v1/urls

Response: 201 Created with the short link

GET http://gitly.com/{slug}

Response 301 redirect (permanent redirect)/ 302 redirect (temporary redirect) or 404 Not found or 400 if slug more than 7 characters

Design

If we allow c different characters in a n-character slug, we can have c^n combinations.

Let’s…


READ MF!

Requirements

Functional

  • User selects a movie and sees all theaters and showtimes
  • User selects a particular show and books tickets from the seating arrangement and availability.
  • User gets 5 minutes to make a payment

OR

  • waits for 30 mins max for seats to become available.
  • Waiting customers should be serviced in first come first serve manner.

Non-functional

Availability

99.99

Latency

100ms

Estimation

Storage

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…


Braze

Build dynamic segmentation

A/B testing tools

Personalization

PN Channels

  • In-App an In-browser Push
  • Content Cards — image cards, banner cards
  • Email
  • SMS

Android vs iOS

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.

Cghzqzd

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store