System Design Concepts Flashcards
What is Horizontal Scaling?
Scaling by adding more servers to your pool of resources
What is the advantage of Horizontal Scaling?
Horizontal scaling is easier to dramatically scale
What is Vertical Scaling?
Scaling by adding more power (CPU, RAM, Storage) to existing server
What is a Load Balancer?
Helps spread traffic across a cluster of services in order to reduce individual server load, and prevent any one server from becoming a single point of failure.
LBs are intended to improve overall application availability and responsiveness
What type of scaling does Load Balancing introduce?
Horizontal Scaling
Where can you add Load Balancers?
Lots of places! Between the user and the web server, between web servers and internal platform layer (ex: application servers, cache servers) and between internal platform layer and database
What are the benefits of using a Load Balancer?
- Users experience faster, uninterrupted service (not waiting on a single server)
- Less downtime and higher throughput (even full server failure won’t impact end user)
- Fewer failed or stressed components since no single device is performing a lot of work
How does the Load Balancer choose a backend server?
- Health Checks: LBs should only forward traffic to healthy hosts
- Predetermined Algorithm
What is Least Connected Method, and when is it useful?
A LB method that directs traffic to the server with the fewest active connections
This is useful when there a large number of persistent client connections which are unevenly distributed between the servers
What is Least Response Time Method?
A LB method that directs traffic to the server with the fewest active connections and the lowest average response time
What is Least Bandwidth Method?
A LB method that selects the server that is currently serving the least amount of traffic measured in megabits per second (MBPs)
What is Round Robin Method and when is it useful?
A LB method that cycles through a list of servers and sends each new request to the next server. When it reaches the end it starts from the beginning
This is most useful when the servers are of equal specification and there are not many persistent connections
What is Weighted Round Robin Method and when is it useful?
A LB method in which each server is assigned a weight that indicates the processing capacity. Servers with higher weights receive new connections before those with less weights (and get more connections)
This is useful in the case where you have servers with different processing capabilities, and there are not many persistent connections
What is IP Hash Method?
A LB method that uses the hash of the IP address of the client to redirect the request to a server
What are Redundant Load Balancers?
The Load Balancer itself can be a single point of failure. To overcome this, a second load balancer can be connected to the first to form a cluster
Each LB monitors the health of the other, and since both are capable of serving traffic and failure detection, the second LB can take over if the main LB fails
What is Cache and what principal does it take advantage of?
Short term memory.
It has a limited amount of space, but is typically faster than the original data source.
Cache takes advantage of the locality of reference principal: recently requested data is likely to be requested again
What is Application Server Cache?
This involves placing a cache directly on a request layer node, to enable the local storage of response data
The cache on one request layer could be located both in memory (very fast) and on the node’s local disk (still faster than going to network storage)
How do you handle cache with multiple server nodes?
It is possible to have each node host its own cache
However, if your LB randomly distributes requests across the nodes, the same request will go to different nodes, thus increasing cache misses
Two choices for overcoming:
- Global caches
- Distributed caches
What is CDN?
Content Distribution Network
CDNs are a kind of cache that comes into play for sites serving large amounts of static media
Typical set up:
- Request asks CDN for piece of static media (file, image)
- CDN serves if available
- If not available, CDN queries BE server for the file, caches and serves
What is Cache Invalidation and why is it important?
Cache must be kept coherent with the source of truth (the database). If the data is modified in the database, it should be invalidated in the cache (removed or updated) otherwise this can cause inconsistent application behavior
What is Write Through Cache and what are its pros and cons?
Data is written to the cache and the corresponding database at the same time
Pros:
- Allows for fast retrieval and complete data consistency between cache and storage
- Minimizes risk of data loss
Cons:
- Higher latency for write operations (since done twice)
What is Write Around Cache and what are its pros and cons?
Data is written directly to permanent storage, bypassing the cache
Pros:
- Can reduce the cache being flooded with write operations that will not be re-read
Cons:
- Read requests for recently written data will create “cache misses” and must be read from storage – causing higher latency
What is Write Back Cache
Data is written to cache alone and completion is immediately confirmed to the client. The write to permanent storage is done after specified intervals or under certain conditions
Pros:
- Low latency and high throughput for write intensive apps
Cons:
- Comes with risk of data loss because the only copy of written data is in cache