System Design Flashcards
Can you describe a simple app request flow?
- Users access websites through domain names, such as api.mysite.com. Usually, the Domain Name System (DNS) is a paid service provided by 3rd parties and not hosted by
our servers. - Internet Protocol (IP) address is returned to the browser or mobile app. In the example, IP address 15.125.23.214 is returned.
- Once the IP address is obtained, Hypertext Transfer Protocol (HTTP) requests are sent directly to your web server.
- The web server returns HTML pages or JSON response for rendering.
What is load balancer?
( We send request to Load Balancer before actual server).
A load balancer evenly distributes incoming traffic among web servers that are defined in a load-balanced set.
• If server 1 goes offline, all the traffic will be routed to server 2. This prevents the website from going offline. We will also add a new healthy web server to the server pool to balance the load.
• If the website traffic grows rapidly, and two servers are not enough to handle the traffic, the load balancer can handle this problem gracefully. You only need to add more servers
to the web server pool, and the load balancer automatically starts to send requests to them.
What do you need to consider when you’re using cache?
- Consider using cache when data is read frequently but modified infrequently.
- Expiration policy. It is a good practice to implement an expiration policy. Once cached data is expired, it is removed from the cache.
- Consistency ( data in cache and DB should be the same )
- Mitigating failures: A single cache server represents a potential single point of failure (SPOF).
- Eviction Policy: Once the cache is full, any requests to add items to the cache might cause existing items to be removed.
What is single point of failure (SPOF)?
“A single point of failure (SPOF) is a part of a system that, if it fails, will stop the entire system from working”
What is Eviction Policy cache?
Once the cache is full, any requests to add items to the cache might
cause existing items to be removed. This is called cache eviction.
What is Content delivery network (CDN)?
A CDN is a network of geographically dispersed servers used to deliver static content. CDN servers cache static content like images, videos, CSS, JavaScript files, etc.
Can you describe the whole CDN client -> server flow?
- User A tries to get image.png by using an image URL. The URL’s domain is provided by the CDN provider. The following two image URLs are samples used to demonstrate what image URLs look like on Amazon and Akamai CDNs:
• https://mysite.cloudfront.net/logo.jpg
• https://mysite.akamai.com/image-manager/img/logo.jpg - If the CDN server does not have image.png in the cache, the CDN server requests the file from the origin, which can be a web server or online storage like Amazon S3.
- The origin returns image.png to the CDN server, which includes optional HTTP header
Time-to-Live (TTL) which describes how long the image is cached. - The CDN caches the image and returns it to User A. The image remains cached in the CDN until the TTL expires.
- User B sends a request to get the same image.
- The image is returned from the cache as long as the TTL has not expired.
What are the difference between stateful and stateless architecture?
stateful - should contain information about the user on the server ( in the server memory, if the server down we lose data and we can’t scale horizontally) and depends on the previous requests
stateless - send information from the client ( session) and doesn’t save it to the server ( save to the database )
What is database sharding? What problem can appear?
Sharding separates large databases into smaller, more easily managed parts called shards. Each shard shares the same schema, though the actual data on each shard is unique to the shard.
- Resharding data: Resharding data is needed when 1) a single shard could no longer hold more data due to rapid growth. 2) Certain shards might experience shard exhaustion faster than others due to uneven data distribution.
- Celebrity problem: This is also called a hotspot key problem. Excessive access to a specific shard could cause server overload.
- Join and de-normalization: Once a database has been sharded across multiple servers, it is hard to perform join operations across database shards.
What is rate limiter?
In a network system, a rate limiter is used to control the rate of traffic sent by a client or a service. In the HTTP world, a rate limiter limits the number of client requests allowed to be sent over a specified period. If the API request count exceeds the threshold defined by the rate limiter, all the excess calls are blocked. Here are a few examples:
• A user can write no more than 2 posts per second.
• You can create a maximum of 10 accounts per day from the same IP address.
• You can claim rewards no more than 5 times per week from the same device.
What is API gateway?
Cloud microservices have become widely popular and rate limiting is usually
implemented within a component called API gateway. API gateway is a fully managed service that supports rate limiting, SSL termination, authentication, IP whitelisting, servicing static content, etc.