BMS Prep For The Tech PM Interview

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Prep Sheet for PM Technical Interviews

Solid Websites / Resources


- Gaurav Sen (Best Resource)
- PMQuestions.com
- TryExponent.com
- Internet-Class
- Link

How does Google Docs work?


What is MapReduce?
How does Chromecasting work?
How does the internet work (for computers)
How does the internet work on phones?
What is the difference between between a modem and a router
What is Recursion:
What is an Array
What is an Caching
What is Sharding
What is the different between a SQL and a NoSQL database
How does Rate Limiting work and how does it relate to the Thundering Herd Problem
(video)
How would you think about scaling scaling data systems (video)
Describe Extensibility
High Level vs Low Level Design
Calculate the qps (queries per second) of Google

You have a ladder of N steps (rungs). You can go up the ladder by taking either 1 step or two
steps at a time, in any combination. How many different routes are there (combinations of 1
steps or 2 steps) to make it up the ladder?

Areas to focus on:



● CS fundamentals
Time Complexity (ie Linear time vs Constant time.
● How do computers work? Bits/Bytes? Computer Software?

Time complexity is a way to express the relationship between the number of operations an algorithm
will perform and the size of the input to the algorithm.

If an algorithm performs 1 operation (or any fixed number of operations) for an input size N, this is
constant time, because the number of operations does not change depending on the size of the
input.
If an algorithm performs a fixed number of operations for every input, this is linear. Increasing the
input size by 1 increases the number of operations by some fixed number of operations; in other
words the number of operations depends on the size of the input.

- Constant Time: O(1)


- Code that will perform the function in the same time regardless of the size
- Analogy. You have a deck of cards and are asked to grab one at random. No
matter how many cards you add it will take the same amount of time.
- Linear Time: O(n)
- Code whose time to execute that grows linearly as the data set grows. Rule of
thumb is your code should always be at least this fast, though ideally faster
- Analogy: You have a deck of ten cards. I ask you to find the Ace of Spades. Yes
it could be the first card, but it could also be the last, so if you did the came many
times it would average higher. Now say I ask you to find the one Ace of Spades
in a deck of cards with 1k cards. That would take much longer. Linear time.
- Logarithmic Time: O(log (n))
- This Code where it can use what it knows about how the information is done to
split the issue or look up into smaller tasks, thus being faster than Linear time.
- Analogy: You are asked to find the 3 of hearts in a 52 card deck. But before you
start you know that the cards have already been organized by suit and within
those suits ordered by number lowest to highest. You save a bunch of time by
jumping straight to the pile of hearts. And once you are there you know 3 is in the
lower part of the deck so you start from the bottom.
- Quadratic Time
- Exponential Time

-
Technology
● How do computers work? Bits/Bytes? Computer Software?
● How does the internet work? What is HTTP and TCP/IP? How do you make it faster?
● How do servers work?
● What are the various search algorithms? Sorting? Graph search?
● What is Big O notations and various algorithm run times?
○ Big O Cheat Sheet
○ Time + Space Complexity / Complexity Analysis

● How does search voting work?

● How does Google search work?


○ Crawling​:
■ The search process begins with Google sending “spiders” to crawl over
the internet to find all of the available, public websites.
○ Indexing​:
■ As the spiders start with a set of webpages and then follow all the links to
those pages, and on those pages find all the links to those pages,etc. As
the spiders find new webpages they are added to Google’s index of all the
websites into the database.
■ This process is constantly happening. In 2019 that required 100m
gigabytes to just index
■ Google only indexes about 10% (ie Google doesn’t index grandma’s
sweet memories with no traffic, deep web, + dark web)
○ Querying → PageRank
■ When you type in a word or phrase Google then tries to match you to the
correct website.
■ In the early days of Search this was done by “Keyword Density” which
was the equivalent of like a Super Control F across all the pages. This
quickly became gamed / less relevant.
■ Fixing this was Google’s first major search innovation, and it’s called
“PageRank” named after Larry Page.
■ The idea was that Google could take many more factors than Keyword
destiny to better predict what the right answer to queries would be.
■ A core factor was something like a “popularity/respect source” wherein
Google would measure the number of respected sites (ie the WSJ,
whitehouse.gov, etc) that linked to that site, as a proxy for how legitimate
+ relevant it is. Think of it as like social proof but on the internet.
■ Now there’s a bunch more factors considered such as:
● Your location​ (ie “Football” in US yields something different than in
UK)
● Your search history​: If you last search was pony’s and your next
search is mustang it might yield a different result than if your
previous search was Ford
● Your sites associations​: Is the site associated with other spammy
sites
● The bounce rate of the sites:​ This is a data point that says this
was the wrong answer.
● The Speed to load​: (ie AMP change for mobile sites in 2018)
● Increasingly the source of the data. (ie Russian sites writing about
elections in missouri might be deprioritized against articles
originating in missouri.

● How does Google Docs work?


○ Video
○ What does “work” mean?
■ Real time collaboration
■ Storage
■ Permissions
○ Real time collaboration
■ Two clients are making calls to a server. The Server acts as the single
source of truth.
■ Change requests come in via a que to the server. (ie Delete G, or more
specifically Delete item in space 3 if the word was DOG)
■ When two requests come in at the exact same time (very rare) if they are
the same thing one will invalidate the other. (ie if my computer (Client 1)
sent a request to Server to delete G, your computer (Client 2) made a
request to delete G it would come in via a que and by the time the request
from Client 2 asked to Delete G the server would know that the item there
had already been completed so it would invalidate the request to delete G
and both parties would see DO.
○ Permissions
■ Google stores in the DB what users have access to a specific doc. When
a user gets invited to join the doc they are added as a valid user of the
doc, and then when accessing the doc a call is made which is “does this
user have access to this doc” the application looks at the column of
“permissioned users” and if the name is present access is granted, if not
access denied.
● What is MapReduce?
○ Easy version: It’s how really big tasks get split across multiple servers /
machines. (how do we divide and conquer to conquer faster)
○ Was very popular in the early days of Google.
○ MapReduce forces a programmer to break up the job into 3 pieces.
■ Map
■ Shuffle
■ Reduce
○ Famous Example​: Count the number of times a 2 words (ie DOG and CAT)
shows up across a 100 documents with 4 computers
○ MAP:
■ Assign a certain number of documents (ie Tasks) to a specific
computer/server, ie Computer 1 takes 1-25, C2 takes 26-50, etc.
■ Assigned computers perform the task (ie Count the times DOG or CAT)
shows up in their assigned documents
■ Note: at Map Stage, there is no communication across computers.
○ SHUFFLE:
■ Shuffle and assort stage
■ Could be the same computer or in a different computer, but it effectively
routes the answers to the computer that will be doing the computation (ie
all answers for CAT go to one computer and all answers for DOG go to
another.
○ REDUCE:
■ Combine all the answers together to get final couts.
○ Map split up the work, Shuffle directs it, Reduce is what pulls it back together.
○ MapReduce isn’t as commonly used as it once was.

● What is NoSQL?
● What is a Hash Table?
○ Its a Key Value look up
● What is a Hash Map?
○ Has
● What is a Key-Value Store?
○ Ke
● What is Mark down as it relates to Storage?
○ Markdown is a text-to-html conversion tool for web writers
○ Used for when there’s a very simple
○ HTML can be really hard to understand
○ Markdown is very simple and not a replacement for HTML
○ Video
● What is the difference between a normalized and denormalized
Database?
○ The objective of DB normalization is to isolate and eliminate redundancies.
○ Denormalized DB remove the connections between tables
○ The reason you would denormalize a db is because you want to flatten the data
(ie create redundant but paired data to increase efficiency by reducing the
necessity of leveraging joins, or queries across multiple DBs.)
○ Good analogy:
■ Say you wanted to go grocery shopping for lunch and dinner.
● In a normalized DB, you go to each section (meat, veggies, etc) 2x
because you first shop for breakfast then need to go back and get
everything separately for dinner
● In a denormalized DB you can shop for both.
○ The downside of a denormalized DB is that it has a lot of redundant data and can
become difficult to stay organized.

● What is a LAN?
○ Local Area Network (think LAN parties with Command and Conquer)

● What is Fuchsia?
○ Possible successor to Android.

● What is a protocol?
○ Video
○ The rules for how computers can communicate with each other. They need very
rigid rules.
○ Especially important for packet based communication.
○ Two things protocols need to do
■ 1. Define the structure for the packets being shared
■ 2. Set the rules of how the computers will able to communicate moving
forward (ie Unidirectionally, bidirectionally, open communication, etc)
○ Examples of Protocols:
■ TCP/IP- Used for transporting data often via Communication (WhatsApp)
■ Http/https - Used for web access (ie Google, Ebay)
● Note HTTP is fine for when you are just browsing the web (ie
Gif.com) but anyone can theoretically see what you are doing.
With HTTPS the data that is entered (ie SSN, CC info, etc) is
encrypted.
○ HTTPS uses SSL (Secure Socket Layer)
■ RTP - Used for Video Calls +Streaming (ie NetFlix, Zoom)
● What is an API?
○ An API is something that lets apps / software work with eachother. It prevents
redundancies (ie every website needing to build it’s own payment service) by
allowing different apps/services to use eachother’s software/hardware.
○ 3 types of API
■ Feature API ​- Example: Uber has an API to Braintree to outsource
payment collection.
■ Data API​ - How Google might connect with ESPN to get Sports Scores
■ Hardware API​ - How instagram tells your phone to connect it to the
phone’s camera.

● How does Chromecasting work?
○ Video
■ To cast there are two core pieces; a Sender application and a Receiver
application
● The Sender application just sends messages to and from the
device to the service (ie Netflix) It’s not actually streaming the
media. This is built into the app (ie Netflix) and controlled on the
phone / tablet/ computer.
● The Receiver application is what’s actually streaming the media
and is the software in the ChromeCast. The request is made via
the phone and it returns with the specific media to the Chromecast
as the display.
■ The ChromeCast is essentially a lightweight ChromeBrowser. It has its
own IP address, load HTML, CSS, and JS from the internet and can
communicate with the various sites.
■ The phone sends a URL request via the WiFi to a service that includes a
return address, which is the ChromeCast.

● Technical Article​.

Why did ChromeCast go with WiFi over says LTE or Bluetooth?


- Main drivers are:
- Bandwidth capacity
- Range
- Data requirements
CS Concepts
● What are the various data structures? (Arrays, Hashes, Stacks, Queues)
○ Arrays
○ Hashes
○ Stacks
○ Queues
○ Stacks vs Queues ​video
■ Stacks are LIFO, imagine a stack of plates.
● You can only grab the last item added
● Use case would be the UNDO button on Docs


■ Queues are FIFO, imagine a line of people waiting to get into a movie
theatre
● Used things like accessing a website (ie if 5 people access you
want the first person who asked to get it first) and print jobs.
■ Both queues and stacks don’t have indexes so they can’t do insertions
into the middle and can only pull from the top or bottom (or back)

● When people talk about a tech Stack, what is that? (​blonde dictionary​)
○ It’s all of the technology (programming, languages, tools) needed to run your
software / service.
○ Examples would be:
■ Server (ie Apache, Nginx)
■ Database (ie MongoDB, MySQL, Postgres)
■ Back End (PHP, Java, Python, Ruby)
■ Front End (HTML, CSS, JavaScript) ← these 3 are often used together.

● How does a LinkedList work? What about a trees and graphs?

● What is concurrency vs parallelism (video)


○ Concurrency is when there is a large list of things to do and the system can
switch back and forth to do them all but can only do 1 thing after another
■ Think humans people multitasking
■ Single core processor is just switching very fast, so fast that we think our
computer is actually running Docs and our video game at the same time.
○ Parallelism is when 2 or more things can be done at the same time.
■ QuadCore CPUs are an example. Think of it as more brains / arms on the
same person.
● Rendering (Server + Client) / MVC

How do computers work:


- All computers have 4 main functions
- Input
- Storage
- Processing
- Output
- Input​: can come in a bunch of ways (ie mouse clicks, keyboard, etc). What those are
inputs and transmissions of commands through circuits / electric pulses to a computer’s
“brain” or CPU, Central Processing Unit.
- Storage and Processing​: The CPU is made up of circuits that can run commands
based on knowledge that was stored to memory. For example if you hit B on your
keyboard, the CPU receives that input, looks up what is and what it should look like from
the computer memory, either via the short term memory (RAM) or via the persistent or
long term memory, the Disk. Once the CPU has communicated the input / calculation
request to the Memory and received the right information for how to process it, it then
passes that configuration of binary (Os and 1s) to next stage which is“output”.
- Output​: Output is what happens once the calculations have been run and the
information is ready to be returned. For example if the input was a B on the keyboard,
the CPU will process and return as output how to display a B via the exact combination
of activated pixels. In this case a B is passed back to the monitor to be shown as a B.
- This is happening billions of times as your computer is constantly doing thousands of
calculations (ie remember that B should be in black cause we are using black font, and
the B should be 12 font cause that’s what we are running right now) It’s also running
concurrent with other items, ie the CPU may also be running music or something else.

How do computers work


● Transistors are the key to building computers. When you turn a computer on, electricity
flows through the transistors. They are super small - iPhone has 32 billion. Chip is a solid
state fingernail sized piece of silicon that can have billions of transistors. Moore’s law
says transistors get smaller every 18/24 months and we can fit 2x per chip - making
computers cheaper and more powerful.
● A computer has CPU, RAM and Disk/Flash.
○ CPU (Central Processing Unit) is the brains of the computer and can perform
billions of simple operations per second. Code runs on the CPU.
■ Gigahertz is speed - 1 billion cycles per second and it shows how fast the
CPU can process actions.
○ RAM (Random Access Memory) is temporary storage that is not persistent when
power is removed. With code like newSimpleImage(“flowers.jpg”) bytes of image
are loaded in RAM.
○ Disk - This is persistent storage and has a file system to organize things. "File" -
a name, a handle to a block of bytes. e.g. "flowers.jpg" refers to 48KB of image
data bytes
● Motherboard brings all of these pieces together - CPU, RAM, Disk Drive. Microcontroller
- has CPU, RAM and Disk on one chip and can be used in small thing like thermostats,
etc.

Bits/Bytes
● A bit is like an atom, it’s the smallest unit of storage and can be a 0 or a 1. It’s too small
to use. A byte is 8 bits and can store a letter like an “x”. There are 256 different patterns
of 1s and 0s in a byte. For example, 01101100 = 9 = “o”.
● KB is 1000 bytes. Email is about 2KB.
● MB is 1 Million Bytes. MPG audio is 1MB per minute.
● GB is one billion bytes. A flash drive may hold 16GB. A hard drive might hold 750GB.
● Terabyte is one trillion bytes.
● Email: 2KB, Image: 200KB to 1.5MB, Song: 5MB, Video: 20MB for 90 seconds
● Numbers: ​13 is 1101
● Text: Each letter gets a number. For example HELLO is 72,69,76,76 and 79. Each
number then has a corresponding binary count. Unicode is the process of giving
characters a number
● Colors: Red, Green, Blue makeup all colors. To get binary version of color you say how
much red, green and blue is in it on a scale of 1 to 255. Magenta is
111111110000000011111111 (255 for red and blue, 0 for green)
● Image: A table of pixels. Each pixel is located at [X,Y] and has a RGB color value.
Data Sizes

1Byte (8 bits) Example object

KB 1k Bytes Plain Text Word Doc =20kb

MB 1m Bytes Photo = 5mb

GB 1b Bytes HD movie = 4GB

TB 1t Bytes

PB (Petabyte) 1​quadrillion​ Bytes

EB (Exabyte) 1 ​quintillion​ Bytes Total 2013 Internet traf. = 5eb

All internet traffic in 2013 was 5EB

How do data sizes relate?


1 KB = 1 MB = 1 GB= 1 TB =
KB 1 1,000 1,000,000 1,000,000,000
MB 0.001 1 1,000 1,000,000
GB 0.000001 0.001 1 1,000
TB 0.000000001 0.000001 0.001 1
How much does Gmail cost Google per user per year?

● Cost Drivers are:


○ Infra: Storage / bandwidth / servers
○ People: Engineers + staff
○ Marketing
● Example of how to answer. (​link​)
● Ballpark should be around $6.25 cents per user per year
● If you want to go deep:
○ Split into user segments of usage (ie Free users vs Paying vs Corporate)
○ Consider portions of the overall users
○ Consider the different storage / costs of each group
How does Netflix (and YouTube) handle video uploading

● It’s important to know that when the video is upload there are two things to immediately
consider:
○ Different formats​ the video may need to be stored in:
■ ie the Codex / compression size based on viewers with Higher or lower
bandwidths.
○ Different resolutions
■ Where if someone is going to watch it on their TV they will likely want
1080p or 4k whereas someone watching it on their phone is likely fine
with 720
○ So the total number of videos that Netflix would want to save it (FxR) or the # of
formats x the number of Resolution sizes.

● Doing all of this at the time of upload would be pretty time consuming if it was done by
one computer / server so what Netflix does is it breaks the problem into much smaller
chunks and distributes it across a bunch of servers. For example on Server might
process the first scene of the video in 1080p in a Low compression format, whereas
another Server processes the scene of the video in 720b in a high compression format.
All of these chunks are processed concurrently.
○ Note: They don’t use raw time (ie 5 min chunks cause it’d be annoying if at the
climax at of a great scene buffering was required.

● What is Buffering?
○ Buffering is preloading a portion of the content so that the video can run
smoothly.
○ Think of it as a head start. If the computer knows that it needs X time to get 30
seconds of video, it was start your video at when it has y*30second clips so that
the computer can continue to fetch the movie data while you watch (and you
don’t need to wait for the whole movie to be transferred.
○ The little buffering icon appears when there’s a break or decrease in your
bandwidth and the video that you are viewing catches up to the amount of video
that has been retrieved.
○ The data retrieved from the buffering process stores the video/music you want to
watch in your RAM. having more RAM means your computer can store more
video in the buffer.
○ F

● 5 GHz vs 2.4 GHz


Scrum vs Kanban
○ Video
○ Both are versions of Agile Software development.
○ Scrum
■ Typically work in “sprints” usually 2 weeks
■ During the Sprint the PM pulls “next up features” based on the feedback
from the customer & the product roadmap and prioritizes what should be
considered during the next sprint (aka put in the next Sprint backlog)
■ Any items not included in the sprint, then need to wait until the next sprint
unless there’s a big emergency.
■ Typically a board is used to track where everything is during the sprint.


■ Typically scrums have a daily standup to discuss where everyone is /
highlight any blockers
■ Sprints typically end with a Sprint Review and a Sprint Retrospective.
■ Then the cycle repeats.
○ Kanban
■ Kanban is continuous process, so there is no Sprint backlog
■ A board is used but it’s based off of the team’s eng capacity.
■ When an items is completed another is just pulled from the build column
(ie below) and something from the product backlog is pulled into the build
column

How computer software works


● Software is code that runs on a computer. CPU takes code, expands it to machine code
and then runs the code line by line. pixel.setRed(10) may expand to 10 lines of machine
code. A program is a series of machine code instructions which are stored in RAM but
executed by CPU. For example, when you open FireFox, its a file with lots of instructions
stored on the disk. It copies those instructions to RAM and the CPU starts running them
one by one.
● An OS is an administrative program that manages the opening/closing of programs.
Each program has its own RAM so you can use them at the same time and if one
crashes they don’t all crash. When you turn on a computer it looks for a tiny get stated
program. That program looks at the disk for an OS to run and start the computer.
● Low Level: Machine (1s and 0s), Assembly (Hard to read and needs assembler to
translate to machine code)
● Highlevel (eg. Java, C++): Easy to understand and portable.
● Compiler takes source code like C++ and translates it into machine code. When you
want to make changes, change the source code and recompile. Can’t go backward from
machine code to source code.
● Interpreter languages like Java or Python have an interpreter which looks at each line,
looks at what it says to do, takes action and the proceeds to next line. It takes longer but
as more features.
● Comparison

What is a VPN?
● Good Analogy: Its like a PO box.
○ Say you wanted to get “XYZ monthly” but you didn’t want the people @ YXZ or
the Post man to know it’s for you. You’d get a PO box to keep your privacy cause
your address is associated with you.
○ The VPN obfuscates your IP address. When the data request gets to the server
it will not have your IP address but rather the IP address over the VPN server.
Once the server returns the requested data to the VPN, the VPN will then pass it
back to you.
● Why do people use a VPN?
○ Privacy
■ IP addresses are usually assigned in blocks so the server you are
reaching out to knows where you are, often down to the city or portion of
the city level.
○ Security
■ If you get on the “free internet” at Starbucks some might be able to spoof
a wifi connection and collect information you are accessing (ie bank
passwords, usernames, etc.)
○ Gaining access to blocked
■ For example, if you are traveling to India and want to access your netflix
but Netflix says we don’t service india and we can tell your IP address is
coming from India you are blocked unless you use a VPN.

How much bandwidth is needed for various tasks?


- Link
How does the internet work (for computers)

- A person types in a website (ie Facebook.com) in a computer which is a “client” that can
connect to an ISP via a router.
- The request goes from the person’s IP address to the ISP (via router) which accesses
the DNS (Domain Name System) to determine the correct IP address of the domain
facebook.com. (This is only the case if you’ve never been to facebook.com. If you have it
will be stored in your cache memory.)
- It is then sent via a series of routers to another router that will bring it close to the server
where facebook.com is being stored, each time it travels over a router, that router
attaches its IP address so that when the information is sent back it knows where it needs
to go.
- The request is sent via a series of 1s and 0s that are split up into “packets” the
contain the sequence number (for reassembly) and the IP addresses that it
needs to flow through to bring the information back to the correct IP address.

- That request is routed from the user computer through optical cables (via pulses of light)
to a data center where the information for Facebook.com is being stored on a SSD (solid
state drive.)
- That request for information triggers a response from the Facebook Servers to serve the
correct data back to the requesting IP address.
- That information is sent back to your home via fiber optic cables till it gets to your router
where it converts the light signals into electrical signals that are then passed back to
your computer to display the data you requested.

How does the internet work on phones?


- Similar to the above except the requests are initially made and served back via
electromagnetic waves to a cell phone.

ICANN manages IP address assignment, domain name registration, etc.

Protocols set the rules for data packet conversion and destination addresses for each packet.
- Example of protocols are: TCP / IP, Http /Https, RTP.

What is the difference between between a modem and a router


- The Modem
- Serves to establish a steady connection between a computer and an ISP and to
convert the computers signals which are digital to the ISPs signals which are
often analogue.
- Modem stands for modulator / demodulator which is what the modem does when
it converts the analog to digital and vice versa.

- The Router
- Comes after the Modem if you want to have more than one device to access the
internet or have a wireless connection.
- Routes your internet connection to your various devices
- Increasingly folks are selling modem / router combined machines.

Cable or Fiber connections mostly come from cable companies (ie Comcast)
DSL connections mostly come from phone companies. (ie AT&T)

What is Recursion:
- Analogy: Russian doll
- It’s a function that calls itself and is useful when a problem is can be solved faster by
breaking it into smaller problems that use the same algorithm
- It must have an end condition to say when its achieved its goal (ie when you get to the
front of the movie theatres rows and there is no row in front of you come back)
- Uses:
- Sorting algorithms
- Working with files in a directory structure
- Parsing XML/html

What is Recursion
- Recursion is code that references itself to arrive at the answer
- Analogy: Say you are in a movie theatre and you want to know what row you are in but
it’s dark. So to find out you ask the person to what row am I in? They don’t know so they
ask the person in front of them, and it continues until the person gets to person whose in
the 1st (#1) row. They then say, I’m in the first row, so the person ahead knows they are
in the second row, and it comes back to where you are and you learn you are in the x
row.

What is an Array
- An array is a list of data (ie bubbles)
- Code is int [ ]
- Arrays always start at zero.
- This of an array as a series of X slots.

What is an Caching
- Caching is when a computer stores the results of an operation so that future requests
return faster.
- Helpful ​video

What is ​Sharding
- Analogy: A really big pizza that’s a lot to eat by itself so you cut it into slices and share it
across folks that can “eat” it
- Useful for when you have A LOT of data that you need to pull from, so you “partition” the
pizza across multiple Database servers with a key (ie every transaction from March with
a user whose name was A-M, is on server A156, every transaction from March with a
user whose name is N-z is one server A157)
- Examples of ways you can shard the data
- Location
- User ID
- Age of users
- etc
- Sharding is a component of horizontal partitioning.
- Partitioning can be either horizontal or vertical.
- Problems with Sharding
- Sometimes data can cut across to shards (ie joins)
- There are a fixed number of partitions set at the start and thus shards can get too
big (when that happens you need to break it into a “mini slice”)
- Big shards can get slow (in this case establish an index on the shard)
- Helpful ​video

What is the difference between ​a SQL​ and a ​NoSQL database


- In SQL the database is made of component tables of information and structured
horizationally. For example, ID number, address, age, role, etc (similar to what you’d see
in an array) It uses foreign keys. SQL requires schema and is less flexible as a result.
-
- In NoSQL db all the data is vertical and all attached to the ID and doesn’t require foreign
keys because the data is attached. NoSQL attaches all the data at the same insertion so
schema doesn’t apply (hence it’s more flexible)
- WATCH THIS VIDEO

What is a foreign key​: (​video​)


- A foreign key is a column or set of columns in one table that identifies rows in another
table.
- Possible and common for a table to have multiple foreign keys.
- Example: Imagine you wanted to know the grades of a specific student in various
classes. You have 3 DBs, Student ID, Courses, Grades
-

What is SQL?
- Structured Query Language
- Example: SELECT id, name, price FROM products
- Uses a relational databases and tables
- Example.You have Users, Products and Orders tables. When a User picks their
products, they’ve made an order which connects the Users with the Product they
ordered.
- Fields are the columns. Records are the rows
- All data must conform to the Schema (ie the rules of the table)
- Joins are special commands that pull data from various tables (ie Users and Order Dates
for example)
- Downsides:
- There is a limit to how much you can scale SQL dbs because they require
Vertical scaling. (Not sure if this is true)
- SQL doesnt’ do large data set analysis well. (Largely cause fo the # of data
tables it needs to cut across.)

What is NoSQL?
- MongoDB is an example a NoSQL database
- The NoSQL Structure is”
- Database
- Collections
- Documents
- People like NoSQL DBs because
- Don’t have a schema requirement
- More Flexible to future Changes
- Faster
- Downsides
- Can be less reliable because the lack of schema means it can become less
reliable in terms of querying the data.
- If you are trying to make a retroactive change (ie BBall becomes Basketball)
there’s a bunch of places that that needs to be changed and its not as organized
as it would be in a SQL db

There is now one that’s better than the other. Most big companies use a combination of both.

What is MySQL?
- The most popular SQL database

What is MongoDB
- The most popular NoSQL

The Power of Logs

Estimating Capacity

Rate Limiting
System Design

Logarithmic vs linear scale

Logarithmic scale

How does Rate Limiting work and how does it relate to the Thundering
Herd Problem (​video​)
- The Thundering Herd problem (ie too many folks suddenly hit the servers) can lead to
the “Cascading Failure” issue if other servers were already maxed out. It can become a
race against time.
- When this happens you have a few options:
- 1) [A bad solution] You can NOT load balance out the requests to the other
servers and just have the experience be down for just the % of users that were
being served by the server. (better one goes down that all via a cascade of
failures.)
- 2) [Usually the right solution]
- Once first server falls set up a que of requests from the fallen server
- Have the system take into account the capacity of all the other servers
and pass over capacity to server with the most free capacity.
- Have que fill that capacity to the limit but not above. Once it hits limits,
have the system respond with a failure notification.
- Send over requests to fall over server to the pick up where possible.
- Once exhausted then only show failures to those not-servable requests
(ie a much smaller portion than would have been seeing failures if you
just cut it off.
- Future-proofing
- If you have a “predictable surge” coming (ie black Friday) you can and should
“rent” additional server capacity.
- Setup Auto-scaling for the future (can get very expensive very quickly)
- Use Job Scheduling (ie if you are going to send a happy new year email to 1M
users, you don’t want to do it all at 12:01am. You want to schedule it out over a
period the system can handle.)

Antipatterns
- These are practices or structures that should be avoided.
- Example would be using your database to communicate with your various servers.
Reason is that a setup like that requires that the Servers pull from the database (ie
frequent polling) which impacts the servers and it takes requires the DB to do a good
amount of read functions which eatup the the DB load.
Sorting
- Fastest way to sort is nLogn
How would you think about scaling scaling data systems (​video​)
- Imagine you have a service (ie a website) on a server. Your site has become so popular
that the demands on that server are greater than it can handle. What do you do?
- You need SCALABILITY. To achieve Scalability you can go with either vertical or
horizontal scaling
- Vertical Scaling ​- Buy a bigger machine (think of it as adding a server on top)
- Horizontal Scaling​ - Buying more machines (think of it as setting up bunch of
distributed but equally sized servers.)

Horizontal Vertical

Distributing Load Requires a load balancer Doesn’t need load balancing

Failures Resilience Single point of failure


If one system fails, you can
fall requests over to other
servers in the network.

Performance Slower​ because it requires Faster​ because it uses ​inter


RPC ​ or Remote Procedure process communication.
Calls

Consistency Susceptible to less More consistency ​because


consistency ​or more all the changes / updates are
specifically more effort to served on the same server. It
maintain consistency also has a consistent cache.
because of the distributed
servers (ie data changed in
Server 6 needs to be
distributed to all other
servers)

HW Scalability HW is more scalable HW is less scalable


because it’s using a because the server can’t just
distributed network of servers get bigger and bigger and
that can grow. bigger. There is a limit.

The CAP theorem suggests data structures must always balance tradeoffs of one the three
following items:
1) Consistency​ - ie Keeping Data consistent on 50 servers is a lot harder than doing it one
1 massive server.
2) Availability​ -
3) Partition Tolerance​ - If you have everything on
People often use the ATM Example. (​video​) This highlights the trade offs of Consistent vs
Available design. If the link (Partition is broken) between 2 ATMs and someone goes to
withdrawal money does it:
A) Say here your money: ie ​Available Design
B) Say we can’t give you money cause we can’t talk to other ATMs right now: ​Consistent
Design.
C) What ends up happening in the real world is people make trade offs between
Available Design and Consistent Design
For example, if you are coming to make a deposit and the network is down, it will accept it (ie
Available), but if you are trying to withdrawal it will reject it (ie Consistency)

Great analogy​: Restaurant scales as a restaurant grows and you have a lot more traffic you
have a few choices.
1) Get the same chef to work more hours (​ie vertical scaling.)
a) To do that you’d need the chef to do more prep / chopping in off peak
hours (optimizing)
b) DOWNSIDE is a lack of ​resiliency​ because what if the Chef gets sick. No
one else can make the food. (ie single point of failure)
i) Mitigation is have a back up. (ie trained chef that knows the
recipes and come in when primary chef gets sick). This is similar
to backing up the data on the server to another server.
2) Hire more chefs ​(ie horizontal scaling.)
a) DOWNSIDE is that some chefs might not use the right recipe if you
update it, so you risk a lack of ​consistency.​ Also, it’s possible that some
chef’s might be better at soups while others are better at desserts.
i) Mitigation is a microservice. When orders come in, you have some
chefs just get the soup orders and some chefs just get the dessert
orders. This is great because A) when you need to change the
soup recipe you don’t need to do it with all chefs and B) the chefs
that are great at making soup, just make soup instead of
struggling with making dessert.

3) If the demand for food gets REALLY big you might need to buy another
restaurant so that if the first one goes down the 2nd one can pick up the orders
(distributed system)
4) If say we had A LOT of pizza shops and we wanted to make sure that when a
customer called for a pizza delivery they got the pizza as fast as possible, instead
of them calling each shop to find out the delivery times, you’d probably just want
all customers to call a center call center that knows the delivery shops to that
location for each pizza shop ​(load balancer)
5) (​link​)
Describe Extensibility
- It’s essentially flexibility that comes from making the solution core it it’s role and not the
specifics of that role.
- Good analogy: If you were to build a delivery robot, you don't want to build it so it can
just deliver pizza. It’s possible that in the future you want to deliver hamburgers so create
the robot with extensibility (ie flexibility to adapt to future needs)

High Level vs Low Level Design


- High level design is the macro components like the system architecture.
- Low level design is the code of the systems

How does Spotify make recommendations to you that are so good?


1) Collaborative filtering ​- They look at what you like and compare it to everyone else and
see who you are most similar to and what they like that you haven’t experience yet
2) Taste Profiles ​- They look at the music you like and recognize genres, beats, etc. They
then match it
3) Why do they do this?
a) Its a selling point.
b) It creates a moat. The more data they have the better their recommendations, the
better their recommendations, the more data they have cause you use the
product more. That loop feeds itself and makes it very difficult for new music
services to compete.

Calculate the qps (queries per second) of Google


- Full Answer
- Approach / Equation:
- Calculate total number of Google users
- Calculate queries per day
- Multiply Users * Queries per Day, then Divide down to per second
- Calculate Google users using a top down approach
- There are 7.8B people in the world.
- Google is not allowed in China so MINUS 1.4B (6.4B)
- Only 50% of people have internet access so 6.4B/2 (3.2B)
- Google has competitors (Bing, Baidu, etc) so Google’s market share is ~75% so
3.2B*.75 (2.4B)
- Google overall users = 2.4B
- Calculate Google queries per day by segmenting users
- 3 buckets of people (Passive, Active, HyperActive)

Passive Active/Average Hyperactive


(older folks, kids, (The Torso of the (Heavy Google users, students,
non-techies) population, avg age, knowledge workers, etc)
users, use cases)

Queries Per Day 1 4 8

Percent of 25% 50% 25%


Population

Weighted .25 2 2
Contribution

​Total Queries Per Day = 4.25

- Multiply Users * Queries per Day, then Divide down to per secondl
- 2.4B users * 4.25B queries per day = 10.2B queries per day
- Dominator for Days to Seconds = 1day = 60 secs *60 mins * 24 hrs = 86,400
- 10.2B/86,400 = 118,055 queries per second

- ANSWER IS: 118,055 queries per second

How would you build Tinder?


- Tinder has 4 main features
- Store Profile
- Recommend Matches
- Note Matches
- Direct Messaging
- (there are other but these are the main 4)
- Store profiles:
- For Storing profiles the biggest issue will be storing the images.
- There are going to be 5 images x Millions of users so there's a lot to store
- You can store images either as a File or a Blob (Binary large Object)
- In this case, you want it to be saved as a file cause you aren’t going to be
doing a lot of searching for or mutating of the photos.
- To store the file you’d what to have a:
- A Profile ID → Image ID + Image URL so the DB can fetch the
appropriate images for the appropriate profiles.
- Use a (distributed) file system

- You will also need to have a Profile service to allow for account set up.
- Later on the profile service will need to pass tokens to authenticate that
the person signing in is the right person / they should have access.

- Making Recommendations:
- The biggest problem with recommendations will be understanding / predicting
which users will be interesting to a user.
- You can start with the constraints and comparing those against information on
other users you’ve stored and indexed (ie age, location, height, etc)
- This will need to pull information from the Profile service described above.
- Note you may think you can store all of this in DB but you are going to want it
sorted and indexed and something can’t be sorted/indexed by two things (ie you
can't have sorted by age and city at the same time.)
- Your choices would either be 3 sorted DBs or a NoSQL Db.
- You will need to create a recommendation service.

- Noting Recommendations/Connections:
- Matching should be handled by a matcher service which is just a place that will
know if person A is actually connected to B. This will matcher service will also
need to pass that information to the sessions service below as messaging
sessions can only happen between matched users.

- Direct Messaging:
- Since each mobile phone is a client and there is a server, you don’t want the
client to constantly be pinging the service saying “hey is there a new message for
me” cause that’s super inefficient. As a result you want to a protocol that allows
the server to push messages so you use a Peer 2 Peer protocol like a XMPP
protocol
- NOTE: this is different from the HTTP protocol where it’s a Client-Server
protocol. See below.
- You will also need to build a sessions service which will handle the messaging.

- can’t have the You can’t

● How does a TCP handshake work


○ A TCP (or Transmission Control Protocol) is a connection protocol that facilitates
messaging across computers in a network. The most common protocol in
networks use a use an TCP/IP connection.
○ Related: What is a websocket
○ Link

● HTTP vs Websockets
○ HTTP is strictly unidirectional. Client makes a request, the server responds with
requested info.
○ Websockets allow us to build real time applications that allow for things like
messaging. In a websocket request, a “handshake” is made that is effectively an
open agreement to send messages back and forth for an extended period / until
either side decides the connection should be closed.

● What is a blockchain (​Good video​)


○ Good analogy: It’s a distributed ledger, that secure because to tamper
with/change one thing you need to effectively hack and change 51% of the other
ledgers which is really hard.
○ Its used for bitcoin
○ Fun fact: It was originally created to do digital timestamping for notaries.
○ Blockchain is like a ledger in that it carries with it not just the change, but also the
entire history of changes to that unit of information.

● What is a Master Slave architecture
○ A slave is just a copy of the master so that if the Master goes down the Slave
comes up. If the Slave goes down it doesn’t really matter you cause the master is
still up.
○ It’s very rare that both would go down at the same time.

You might also like