System Design Concepts Flashcards

1
Q

What are the steps involved in a system design interview?

A
  1. Functional Requirements (APIs, use case)
  2. Non Functional Requirements (traits of the system)
  3. Basic Architecture
  4. Data Modeling/Data Diagram
  5. Scaling/Different Pieces
  6. Follow Up
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does it mean for a system to be scalable

A

A system is scalable if it results in increased performance in a manner proportional to resources added

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

What’s the difference between latency and throughput

A

Latency is the time to perform some action or to produce some result, throughput is the number of such actions or results per unit time.

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

What do you want to optimize with regards to latency and throughput

A

Maximum throughput, acceptable latency

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

Explain the CAP theorem

A
C = Consistency
A = Availability
P = Partition Tolerance 

A distributed system can only have any 2 of CAP at a given time.

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

Explain CP

A

Consistency and Partition Tolerance
Waiting for a response from the partitioned node might result in timeout error - this is good if your business needs atomic reads and writes

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

Explain AP

A

Availability and Partition Tolerance
Responses return the most readily available version of data on any node, which may not be the latest. This is good if you allow eventual consistency

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

Explain weak consistency and applications

A

After a write, reads may or may not see it. A best effort approach is taken. This is seen in systems such as memcached, or real time use cases such as video chat, or multiplayer games.

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

Explain eventual consistency

A

After a write, reads will eventually see it (typically within a couple ms) - data is replicated asynchronously. This is seen in e.g. email and DNS; this works well in highly available systems

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

Explain strong consistency

A

After a write, reads will see it. Data is replicated synchronously. This approach is seen in RDBMS (relational databases), and in systems which need transactions.

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

What are two database patterns to support high availability?

A

Fail over and replication

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

What is fail-over and two types?

A

Active-passive, active-active
Active-passive fail over is when the passive server stops receiving heartbeats and takes over as active server. (master-slave failover)

Active active fail over is when both servers are managing traffic and spreading the load between them - DNS would need to know about the public ips of both servers (or application logic if internal facing)

There is risk in that there is a potential loss of data if the active system fails before any newly written data is replicated to the passive.
Writes get replayed to read replicas, which increases latency of the reads
Replication lag occurs if you have more and more read slaves/followers

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

What is master slave replication? (or, leader/follower replication)

A

Master will serve reads and writes, replicating to one or more slaves, which only serve reads; if a master goes offline, the system can continue in read only mode until a slave instance becomes promoted to master

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

What is master master replication (or, leader/leader replication)

A

Both masters serve reads and writes and coordinate with each other on writes. If either master goes down, the system can continue to operate with both read and writes.

Disadvantages: 
You'll need a load balancer or make changes to application layer on where to write 
Loose consistency (violating ACID) or increased write latency due to synchronization 
Conflict resolution comes into play as more write nodes are added
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the letters in the ACID acronym

A
A = atomicity; each transaction is all or nothing 
C = consistency; any transaction will bring the database from one valid state to another 
I = isolation; whether executed sequentially or in parallel, results after said writes will be the same 
D = durability; once a transaction has been committed, it will remain as so
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are advantages and disadvantages of sharding

A

Advantages:

  • less read and write traffic
  • less replication
  • more cache hits
  • smaller index size
  • one shard going down means other shards are operational

Disadvantages:

  • can result in complex SQL queries
  • data distribution can be lopsided, depending on shard index (resulting in increased load)
  • joining data from shards is complex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is DNS and advantages/disadvantages

A

Domain Name Service
Translates a domain name to an IP address

DNS products (Cloudflare, Route53) can route traffic through various different methods

  • prevent traffic from hitting servers under maintenance
  • A/B testing
  • location based

DNS has some disadvantages in that

  • there is a slight delay, which could be mitigated by caching
  • usually managed by governments, lSPs and large companies
  • recently, DNS services have come under DDos attack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a CDN, advantages and disadvantages

A

Content Delivery Network
Proxy servers closer to the user, which help serve static files such as HTML/CSS/JS (DNS resolution determines which server to contact)

Advantages:

  • users receive content from data centers close to them
  • your servers do not have to serve requests that the CDN fills

Disadvantages:

  • CDN costs could be significant due to traffic
  • Content might be stale if it is updated before the TTL expires it
  • CDNs require changing URLs for static content pointed to the CDN
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the difference between a push CDN and a pull CDN

A

Push CDNs receive new content whenever changes occur on the server. You take full responsibility for providing content, uploading directly to the CDN, and rewriting URLs pointed to the CDN. You can configure when content expires and when it’s updated.
Works well with sites which don’t have a lot of traffic or content that isn’t updated often.

Pull CDNs grab content from your server when the first user requests the content (so first request is not sped up). You leave the content on your server and rewrite URLs to point to the CDN. This results in a slower request until the content is cached on the CDN.
A time-to-live TTL determines how long content is cached. Pull CDNs minimize storage space on the CDN, but can create redundant traffic if files expire and are pulled before they are changed.
Sites with heavy traffic work well with pull CDNs as traffic is spread out more evenly with only recently-requested content remaining on CDN

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

What is a reverse proxy

A

A reverse proxy is a web server that centralizes internal services and provides unified interfaces to the public.

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

What are advantages and disadvantages of a reverse proxy

A

Advantages

  • hides information about backend servers, block list IPs, limit number of connections per client
  • clients can only see reverse proxy’s IP, allowing you to scale server and change configuration
  • SSL termination to encrypt and decrypt requests and encrypt responses
  • compress server responses
  • return cached request responses and server static content directly

Disadvantages

  • increases complexity
  • single point of failure unless multiple reverse proxies are able to be configured
22
Q

What is the difference between a reverse proxy and a load balancer

A

Deploying a load balancer is useful when you have multiple servers; load balancers route traffic to a set of servers serving the same function
Reverse proxies can be useful even with just one web server or application server; opening up benefits

23
Q

What are pros and cons of SQL

A
Pros: 
Guaranteed data consistency 
Vertically scalable 
Need for Joins 
Lookup by index is quite fast 
Strict Schema 

Cons:
Complex to scale up

24
Q

What are pros and cons of NoSQL

A

Pros:
Easy to scale up
Basically available (BA in BASE)
Non relational data

Cons:
Eventual consistency might not be suitable for use case (availability chosen over consistency)

25
Q

What are different types/”flavors” of NoSQL databases

A

Key Value Store
Document Store
Wide Column Databases
Graph Databases

26
Q

When do you use a KV store NoSQL database

A

Used for simple data models or rapidly changing data, such as an in-memory cache layer.

Complexity is shifted to application layer if additional operations are needed

27
Q

When do you use a document store NoSQL database

A

Documents are organized by collections, tags, metadata, and directories. They may have fields in each one different from one another.

Documents are good for working with occasionally changing data.

28
Q

When do you use a Wide Column store NoSQL database

A

Basic unit data is a column (name/value) pair. A column can be grouped into column families. Super column families can further group column families. You can access data with a row key.

Bigtable, HBase, Cassandra maintain keys in lexicographic order.

Used for large data sets.

29
Q

What is denormalization, advantages and disadvantages

A

Denormalization attempts to improve read performance at the expense of some write performance. Redundant copies of the data are written in multiple tables to avoid expensive joins.

Disadvantages:

  • data is duplicated, leading to greater disk space
  • constraints can help redundant copies of information need to stay in sync, which increases complexity of the database design
  • denormalized database under heavy write load might perform worse than normalized counterpart
30
Q

What is denormalization, advantages and disadvantages !!

A

Denormalization attempts to improve read performance at the expense of some write performance. Redundant copies of the data are written in multiple tables to avoid expensive joins.

Disadvantages:

  • data is duplicated
  • constraints can help redundant copies of information stay in sync, which increases complexity of the database design
  • denormalized database under heavy write load might perform worse than normalized counterpart
31
Q

What is denormalization, advantages and disadvantages !!

A

Denormalization attempts to improve read performance at the expense of some write performance. Redundant copies of the data are written in multiple tables to avoid expensive joins.

Disadvantages:

  • data is duplicated
  • constraints can help redundant copies of information stay in sync, which increases complexity of the database design
  • denormalized database under heavy write load might perform worse than normalized counterpart
32
Q

What happens if you have a hot spot in a database (e.g. data is accessed regularly)

A

Break up the table by putting hot spots in a separate table to help keep it in memory.

33
Q

What happens if you have a hot spot in a database (e.g. data is accessed regularly)

A

Break up the table by putting hot spots in a separate table to help keep it in memory.

34
Q

When do you use graph databases

A

Graph databases are optimized to represent complex relationships with many foreign keys or many-to-many relationships.

They are used to represent relationships, such as a social network.

35
Q

When do you use graph databases

A

Graph databases are optimized to represent complex relationships with many foreign keys or many-to-many relationships.

They are used to represent relationships, such as a social network.

36
Q

What are the different types of caching?

A

Client side caching - e.g. browser, CDNs
Web Server Caching - reverse proxies and caches such as Varnish can serve static and dynamic content directly without contacting application servers
Database Caching - caching to prevent having to query and retrieve data from disk
Application Caching - in-memory caches such as Memcached or Redis are key-value stores between application and data storage.. Data is held in RAM so it’s much faster than typical databases store in disk, but need cache invalidation over time.

37
Q

What is a write through cache, pros and cons

A

A write through cache has the application use the cache as main data store, reading and writing data to it, while cache is responsible for reading and writing to db.

This is a slow overall operation due to the write operation, but subsequent reads of data just written are fast.

38
Q

What is a write behind cache

A

Application adds/updates entry in cache, then writes entry to the data store asynchronously, resulting in improved write performance.

However, there could be data loss if the cache goes down prior to its contents hitting data store, and it’s more complex to implement write-behind than cache aside or write through.

39
Q

What is a refresh ahead cache

A

Cache will automatically refresh any recently accessed cache entry prior to its expiration. This can reduce latency vs read-through if the cache can accurately predict which items are likely to be needed in the future.

However, you will need to accurately predict which items are needed in the future.

40
Q

What is a write aside/cache aside cache configuration

A

The application is responsible for reading and writing data from storage. The application will look for an entry in cache, if cache misses, it’ll load the entry from database, add entry to cache, then return entry.

Drawbacks in that cache miss results in 3 trips, and data can become stale; empty node will wipe existing data out.

41
Q

Explain the difference between performance vs scalability

A

If you have a performance problem, your system is slow for a single user.
If you have a scalability problem, your system is fast for a single user for slow under heavy load.

42
Q

What are some issues with consistent hashing and how do we solve it?

A

Consistent hashing suffers from potential uneven distribution with the addition and removal of nodes (assuming hash spaces are constant)

We can solve this by having the hash space have many virtual nodes

43
Q

Generally, we want systems to have the following non functional requirements (characteristics)

A

scalable (thousands of requests per second), performant (fast latency/response time), available (no single point of failure, survives hardware/network failures)

44
Q

Generally, what dictates the choice between SQL and NoSQL

A

Consistency (SQL) and ACID acronym vs Availability (NoSQL); Read Heavy (SQL) vs Read AND Write Heavy (NoSQL)

45
Q

What increases availability of databases

A

Sharding (based on the shard index) and replication (based on leader/follower, leader/leader arrangements)

Make sure too that database clusters live in different datacenters

46
Q

In general, how do we design the data model for a relational database

A

Noun with fields bundled into individual tables, joined by foreign keys

47
Q

What’s the difference between TCP load balancing and HTTP load balancing

A

TCP load balancing forwards networking packets without inspecting contents of packets (enabling them to be faster)
HTTP load balancing looks inside message to figure out what to do based on message contents (headers, cookies, etc.)

48
Q

What are the 4 golden signals of monitoring

A

latency, traffic, errors, and saturation

49
Q

What is the difference between a strong audit system and weak audit system

A

Strong audit system calculates views and does a full “runthrough” comparing results at the end
Weak audit systems may include end to end integration tests which make sure that the baseline functionality is correct

50
Q

For message consumer services, what can we utilize to maintain the number of active threads

A

Semaphore - determine how many read threads; can be adjusted dynamically

51
Q

What are some considerations for timeline based applications?

A

We need to figure out if we want a push fan out (fan out on write) or a pull fan out (fan out on load)

Push fan out immediately pushes a post to all followers. It has an advantage that it reduces read operations so you don’t need to go through your friends to get their posts. But, it has disadvantage that a hot user will push to a significant number of users.

Pull fan out pulls posts from followers based on user interaction. The main problem is that new data might not be shown to users until they issue a new request.