Neetcode System Design Concepts Flashcards

1
Q

How can we vertically scale a single server?

A

Give it more RAM or CPU (memory or raw computing power)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is vertically scaling a server limited?

A

You’ll run out of computing power fast. Won’t be able to keep up with compute demands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is vertically scaling a single server risky?

A

It creates a single point of failure if anything happens to that server. All our eggs are in one basket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the advantage of horizontal scaling vs. vertical scaling?

A

Horizontal scaling allows us to create replicas of a single server which eliminates our single point of failure problem and allows us to get a lot of computing done with average servers. Don’t need really high power servers to make this effective

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False: Horizontal scaling can scale infinitely in theory

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Does a horizontally scaled system have better availability than a vertically scaled one? Why or why not?

A

Yes - a horizontally scaled system allows us to eliminate the single point of failure issue and allows us to route traffic to different servers depending on the health of a server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a disadvantage to horizontally scaling servers?

A

It’s much more complicated than vertically scaling. You have to make sure one server doesn’t get overloaded or many servers don’t sit idle. You also have to use load balancers to balance out the load, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is another name for a load balancer?

A

Reverse-proxy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does a load balancer work from a high-level?

A

It takes in incoming requests and redirects them to the correct server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are two methods for redirecting traffic in a load balancer?

A

Round robin & hashing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Let’s say we have a global infrastructure, how can we use load balancers to our advantage from a geographic standpoint?

A

We can use load balancers to route traffic to the nearest location or region

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If we have a global system, how can we deliver static content like images, HTML, CSS?

A

We can use content delivery networks (CDN). This allows us to configure how we deliver static content across our network

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a content delivery network?

A

It’s a network of servers that are located all around the world. These servers can delivery static content like images, videos, HTML/CSS/JS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do CDN’s take files from our server and put them onto the CDN?

A

It takes the file from our origin server and copies them onto CDN servers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False: CDN’s can copy data on both a push or pull basis

A

True - this can be done push or pull

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a general definition of caching?

A

Creating copies of data so that it can be refetched faster in the future

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the advantage of caching on a machine?

A

Things like network requests can be expensive time-wise (take a long time) so we can cache this data to disk to reduce that time burden

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Is reading disk expensive?

A

Yes, we can copy to memory but that can be expensive too, so usually our operating systems will copy this into a subset of our CPU (L1, L2, L3 CPU cache)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is an IP address?

A

Every computer is assigned an IP address, which is a unique identifier for any machine. You can think of this as the telephone number for any machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does the Internet Protocol Suite include?

A

IP/TCP & UDP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of TCP?

A

Sending data over a network has to have a set of rules, TCP enforces these rules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

True or False: TCP can fail because it doesn’t resend a request that fails

A

False - TCP will automatically re-send any requests that fails

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

When you type in a URL, how does the computer know which IP address it belongs to?

A

DNS (domain name system) solves this. You create an “a” record that points a URL to an IP address of the server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Does the operating system have to make a request for the IP address of the server using DNS every time?

A

No this request is usually cached by the operating system so that it can be referenced later without making the request every time

25
Q

What is HTTP in relation to TCP?

A

It’s built on top of TCP - TCP is too low-level to be useful for network requests so HTTP was built to handle these

26
Q

What is a general definition of HTTP?

A

HTTP provides an application-layer protocol which follows the client-server model instead of just using packets like TCP

27
Q

What is the general structure of an HTTP request from the client?

A

Client will initialize the request with a request header (where it’s going, who it’s from) and a request body (payload or the actual content)

28
Q

What is a REST API?

A

It’s a standardized HTTP API that makes these requests stateless and consistent

29
Q

What is a 200, 400, and 500 error code in REST API?

A

200 = successful, 400 = unsucessful request, 500 = internal server error

30
Q

What advantages does GraphQL have over REST API?

A

You can make a request for specific fields so that you don’t overfetch data or make duplicate requests

31
Q

What is gRPC?

A

Released by Google in 2016, gRPC is a client to server interaction that creates a performance boost from protocol buffers

32
Q

What is a protocol buffer in a gRPC system?

A

Improved version of JSON using serialized binaries to send data which is much faster than JSON. Down-side is that it’s not as human readable as JSON

33
Q

True or False: WebSockets are built on top of TCP

A

True

34
Q

What is the main advantage of WebSockets?

A

You can get the change instantly from device to device. Once a message is received, it is immediately sent to the next device

35
Q

If we tried to replicate WebSockets using HTTP, how could be do it?

A

We’d have to use polling to do this using HTTP which works but is sub-optimal because you have to continually check for changes using polling

36
Q

What is SQL mostly used for on a high-level?

A

Storing data

37
Q

What are the most common SQL tools?

A

MySQL, Postgres

38
Q

If we can just store data in a text file on disk, why do we need to use a database?

A

Databases can more efficiently store data using data structures like B-trees

Databases also have fast retrieval of data using SQL queries

SQL queries allow you to access data that are stored as rows in tables

39
Q

True or False: One issue with SQL is that it is not ACID compliant

A

False - SQL is ACID compliant

40
Q

What does the acronym ACID stand for?

A

Atomicity, Consistency, Isolation, Durability

41
Q

What does atomicity mean in the ACID acronym?

A

Every transaction is all or nothing

42
Q

What does consistency mean in the ACID acronym?

A

Foreign keys and other constraints will always be enforced

43
Q

What does isolation mean in the ACID acryonym?

A

Different concurrent transactions won’t interfere with each other (think a queue)

44
Q

What does durability mean in the ACID acronym?

A

Data is stored on disk, so if a machine is restarted data will still be there

45
Q

What is the main advantage of using NoSQL databases?

A

Consistency (using foreign keys) makes databases harder to scale, so NoSQL databases remove this relation constraint

46
Q

What are 3 different types of NoSQL databases?

A

Key-value stores (DynamoDB), Document stores (MongoDB), Graph DB (neo4j)

47
Q

If we’re separating the database using sharding, how do we decide which portion of the data to put on which machine?

A

We can use a shard key

47
Q

What is the definition of sharding in relation to databases?

A

Since we no longer have foreign key constraints, we can break up our database and scale horizontally, this is called sharding

48
Q

What is ranged-based sharding?

A

Ranged-based sharding is using the id of a person in a table as the key

49
Q

What is the advantage to replication over sharding?

A

Replication is a simpler approach to sharding

50
Q

What is leader-follower replication?

A

If we want to scale our DB reads, we can make read only copies of our DB - this is leader-follower replication

51
Q

What is the process for leader-follower replication?

A

Every write gets sent to the leader, who then sends to the followers
Every read could go to a leader or a follower

52
Q

True or False: Leader-leader replication is possible

A

True - every replica can be read or write but this can lead to inconsistent data

53
Q

What does the acryonym CAP mean in CAP theorem?

A

Consistency, Availability, Partition (Network)

54
Q

What is the advantage of CAP theorem? What problem does it solve?

A

It can be complex to keep replicas in sync, so CAP theorem was created to weigh trade-offs with replicated design

55
Q

What is the technical definition of CAP theorem?

A

Given a network partition in a database, you have to choose between data consistency or data availability

56
Q

How are message queues similar to databases?

A

They are similar to databases in that they have durable storage, can be replicated for redundancy, or sharded for scalability

57
Q

If we’re overwhelmed with more data than we can process, how can message queues help us solve this problem?

A

Message queues are perfect for this because we can handle these requests one at a time in a consistent manner. Data can be persisted (held in queue) before it can be processed

58
Q

True or False: Different parts of our app can be decoupled by using message queues

A

True