System Design

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/22

encourage image

There's no tags or description

Looks like no tags are added yet.

23 Terms

1
New cards

What is the tradeoff between TCP and UDP. When would you use one or the other.

TCP guarantees that packets arrive in order and that all packets arrive, whereas with UDP packets may or may not arrive, possibly mulitple times, or out of order. So the tradeoff is reliability vs latency
TCP: Chats, banking, file upload, API. Reliability Necessary
UDP: Gaming, video/audio streaming, DNS (benefits from low latency)

2
New cards

What is head-of-line blocking

Because TCP enforces ordering, if a packet is lost then the entire message must wait for it to be found. This is head-of-line blocking.

3
New cards

What are the 5 common communication patterns

Request - Response: Client sends a request when needed server sends a response. Connection must be initiated by client in order for the server to respond
Short Polling: Client makes requests on a fixed interval to get updates.
Long polling: Client sends requests, but server doesn’t respond until new data comes in.
SSE: Create a connection and hold it unidirectionally from client to server
Websocket: Create a connection and hold it bidirectionallly between client/server

4
New cards

When should you use standard HTTP request-response as your communicaton pattern.

When you don’t need continuous or automatic updates

5
New cards

When should you use short polling as your communication pattern. What are its major tradeoffs

When you want continuous updates, but can deal with delay. Can become expensive because of the amount of connections you’re stopping and starting

6
New cards

When should you use long polling as your communication pattern. What are its major tradeoffs

When you want continuous updates, and do not want much delay. Good when infrequent but require urgency. Prioritize SSE/Websockets over it. Having these long held requests consumes resources. timeouts add complexity to this approach.

7
New cards

When should you use Websockets for communication. What are its major tradeoffs

When you need frequent low-latency 2 way communication. Uses Websockets protocol so it’s complicated to manage, uses resources, must implement logic for message recovery.

8
New cards

When should you use SSE for communication. What are its major tradeoffs

When you have frequent 1 way communication from server to client.

9
New cards

why is SSE better than Long polling. Why is SSE better than WebSockets when communication is one way.

SSE is easier than Websockets because it has built in reconnection protocols, and it uses HTTP, whereas Websockets uses its own protocol.
SSE is better than long polling because it holds the same amount of resources, while not dealing with repeated HTTP request overhead.

10
New cards

How to approach an interview.

Get the Functional Requirements - Users/Clients should be able to do what?
Get the Non-Functional Requirements - These are qualitative things that you want the system to be able to do
Identify the Core Entities - The main nouns in your system needed for functional requirements. For example in Twitter this would be Users, Tweets, and Follows
Choose your API/system interface and define the endpoints

Create the High Level Design. Draw the components and the data flows between them. Do it at a basic level then optimize afte for scaling/fault tolerance.

11
New cards

Commonly encountered nonfunctional requirements

CSE LSD FC
CAP Theorem
Scalability
Environment Constraints
Latency
Security

Durability

Fault Tolerance
Compliance

12
New cards

What is an API Gateway, what are its 4 side benefits,and when is it useful.

An API Gateway is basically a router for requests. Every request goes through the gateway before being pathed to their actual service.

Side benefits are authentication, overall application rate limiting, logging requests, and TLS termination
This is useful when you have microservices as opposed to a monolith

13
New cards

What is TLS Termination

HTTPS is HTTP communicated with an extra security layer called TLS. TLS termination is when that layer is dropped, so we now just have readable HTTP.

14
New cards

What is Request Logging and what are its 4 benefits

Debugging - With all of these records it is easier to tell why things go wrong

Performance Monitoring - Can see the latency of all operations

Security - Do any specific IPs stand out

Traffic Analysis - which endpoints have lots of traffic and might need to be scaled.

15
New cards

What is CAP Theorem and what to ask nonfunctional requirements?

When you have a network partition (an event that causes replicated databases to lose communication between each other) you can only have 2 of the following 3.
Consistency - Data is always completely up to date
Availability - Data is always available to access
Partition Tolerance - If one server goes down, the system should still be functional. We always need this
To diagnose this we ask whether it is more important that data is always accurate, or that data is always accessible/server is operational.

16
New cards

What to ask/think about Scalability in nonfunctional requirements?

What is our expected peak requests per second? - Determine whether one server is sufficient or we need to scale horizontally
Is it a Write-Heavy or Read-Heavy workload? - If read heavy we use redis caching, create read replicas. If write-heavy we do batch writes or potentially shard the database.
How much data will we store and can we expect it to grow? - Estimate databse storage requirements

Do we expect traffic to spike and fall or be consistent/predictable? - Potentially implement autoscaling, scheduled scaling, or a queue to absorb spikes.

If we are in a realtime system, i.e. websockets - how many concurrent users should we be able to support? - See if we need to scale Websocket servers horizontally. We will need Redis Pub/Sub if so.

17
New cards

What to ask about latency for nonfunctional requirements?

Just ask plainly how strict are the latency requirements for each path. If they are strict then use caching, databse indexes, or asynchronous processes.

18
New cards

What to ask about security for nonfunctional requirements?

19
New cards

What is durability and what to ask nonfunctional requirements?

20
New cards

What is Fault Tolerance and what to ask nonfunctional requirements?

21
New cards

What is Compliance and what to ask nonfunctional requirements?

22
New cards

What are the two types of caches and what is more favorable. What technology is frequently used for caching

Query caching - keep track of the queries you have had and what they return. Makes it easier in future to return em back
Object caching -cache a User,Tweet, etc. Generally more favorable.
Redis is often used for caching.

23
New cards