System Design
Interview Questions
 
RECOMMENDED RESOURCES
Behaviorial Interview
Top resource to prepare for behaviorial and situational interview questions.

STAR Interview Example
System Design - Interview Questions

System Design - Basics

System design interview questions have become a standard part of software engineering interview process, especialy for senior level roles. Most candidates struggle with system design interview questions; either because they do not have the experience in designing large-scale systems, or because they have not prepared for the open-ended and unstructured nature of such questions. There are many ways to prepare for a system design interview. Below is one example of a step by step approach to solve system design interview questions.

Step 1 - Clarify Requirements

  • Who are users of the system?
    • People?
    • Systems?
    • Processes?
  • What features and functionality are in scope?
  • What actions are performed on the system?
    • Writes?
    • Gets?
    • Updates?
    • Deletes?
  • Does the system have a UI? Is UI design in scope for this interview?

Step 2 - Define the System Interface Definition
  • Services
  • API Endpoints for each service

Step 3 - Define data model
  • Define entities
  • Define interaction between entities
  • SQl, NoSQL or Both?

Step 4 - Define Scale of System
  • Estimate scale
    • Number of requests per second
    • Number of Read vs Write requests.
  • Estimate storage
    • Estimate size of write request
    • Estimated storage requirement per year
  • Estimate bandwidth
    • Payload size of read and write requests
    • Bandwidth requirement per second

Step 5 - Sketch High Level Design
Include following components if applicable
  • Client
  • DNS Server
  • UI/Web layer (react.js, angular.js, backbone.js, etc.)
  • Service/API Layer (app servers, micro services, etc.)
  • Data layer (database, image storage, file server, etc.)
  • Async/off-line processing (messaging queue, kafka, .etc)

Step 6 - Sketch High Level Design For Scale
Include following components if applicable
  • Load-balancers
  • Caching
  • Data partitioning
  • Data replication

Step 7 - Detail Design Deep dive into one or more of key components
  • Any specific algoriths to use
  • Address any bottlenecks

Following are some frequently asked questions in System Design - Basics


What are the key characteristics of distributed systems?

FAQkey Concept

Key characteristics of distributed systems are Scalability, Reliability, Availability, Efficiency, and Manageability.

Scalability - A system is scalable if its performance does not degrade with increasing load.

Reliability - A system is reliable if it operates correctly (functionally with desired performance levels) even with adversities (such as hardware or software faults, or user errors).

Availability - Availability is the percentage of time that a system remains functional under normal circumstances.

Efficiency

Manageability


What is the difference between Performance and Scalability?

FAQkey Concept

Performance - A system is said to have performance issue if it is slow even for a single user.

Scalability - A system is said to have scalability issue if it is fast for a single user but is slow under load.


What is the difference between Latency and Throughput?

FAQkey Concept

Latency - Latency is the time taken by a system to perform an action and return the result.

Throughput - Throughput is the number of such actions that a system can perform within a unit of time.

A system should be designed for maximum throughput with acceptable latency.


What do you understand by consistency? What are consistency patterns?

FAQkey Concept

A system is said to be consistent if it returns the most recent write, or error, for every read request.

There are three consistency patterns

Weak consistency - In weak consistency, reads may and may not see the latest writes.

Eventual consistency - In eventual consistency, reads will eventually see the latest writes.

Strong consistency - In strong consistency, reads will immediately see the latest writes.


What do you understand by availability? What are availability patterns?

FAQkey Concept

A system is said to be available if every request receives a response, without guarantee that it contains the most recent version of data.

There are two complementary patterns that support high-availability

Fail-over - Fail-over can be active-passive or active-active. In active-passive fail-over, only the active server serves requests. If the active server fails, the passive server starts serving the requests. In active-active fail-over, requests are served by both servers.

Replication - Replication is applicable at the database layer and can be master-slave or master-master. In master-slave replication - the master serves read and write requests and replicates to one or more slaves. The slaves serves only read requests. In master-master replication - the both masters serve read and write requests, and the write data is replicated.


What is the CAP theorem?

FAQkey Concept

CAP theorem states that it is not possible for a distributed software system to simultaneously support for more than two of the following three guarantees - Consistency, Availability, Partition Tolerance - (CAP).


Domain Name Systen (DNS)

Following are some frequently asked questions in Domain Name Systen (DNS)


What is Domain Name System (DNS)?

FAQkey Concept

Domain Name System (DNS) is a distributed system that maintains mapping of domain names to their IP addresses.

When a user enters a domain name on the browser URL the request is sent to a DNS server provided by the user's ISP. The DNS server checks if it has the IP address for the domain, else it sends a lookup request to other DNS servers.

The DNS server then returns the IP address back to the browser, which receives the web page by contacting the server by it IP address.


What are the different kinds of DNS servers?

key Concept

DNS servers can be classified into one of the following categories. These DNS servers collaborate to return a specific IP address for a specific domain to the web client.

Recursive resolvers

Root nameservers

TLD nameservers

Authoritative nameservers


What is a DNS record? What are some common types of DNS records

key Concept

DNS records, also known as zone files, provide information about a specific domain - such as the domains IP address, and how to handle requests for that domain. DNS records live in authoritative nameservers and have an associated TTL (Time To Live).

Some common DNS records are - A record, CNAME record, MX record, TXT record, NS record, and SRV record


Content Delivery Network (CDN)

Following are some frequently asked questions in Content Delivery Network (CDN)


What is Content Delivery Network (CDN)?

key Concept

Content Delivery Network (CDN) is a globally distributed network of servers that serve content from locations closest to the users.

Traditionally CDNs served static content files and pre-generated files such as HTML, CSS, JS, image and images. CDNs have evolved since to now serve dynamic content as well, including rich media.

Content served from CDN significantly improves the performance by reducing latency, since the content is served from servers closest to the users. In addition the load on the servers is also reduced since they do not have to serve content that is served from CDN.


How does a Content Delivery Network (CDN) work?

key Concept

Content Delivery Network (CDN) stores cached version of content in multiple geographical locations, known as Points of Presence (PoP). Each PoP contains a cluster of cache servers that deliver content to users closest to that geographical region. If the traffic at a particular PoP is high then you can setup more cache servers for that PoP, and if the traffic is low at another PoP then you can setup just one cache server for that PoP.

example, let's consider that a user from London accesses a website hosted in US. Without CDN, the website will take more time to load for the user because of high latency, i.e the request and response has to travel more distance over the network, very likely making multiple hops.

Whereas, with CDN, the same website will take less time to load for the user because of low latency, i.e the request and response has to travel less distance over the network, since the content will be served from a local PoP cache server.


What are the two kinds of CDNs based on how the content is cached and refreshed?

key Concept

There are two kinds of CDNs based on how the content is cached and refreshed - Push CDNs and Pull CDNs

Push CDNs - In Push CDN model, content is pushed to the CDN cache servers whenever content is modified, or new content is added, on the origin server. Origin server is responsible for pushing the content to the CDN cache servers

Pull CDNs - In Pull CDN model, content is pulled by the CDN from the origin server when that content is first requested by a client. This content is then stored in the cache servers for a certain period of time, usually 1-30 days based on the TTL, so that subsequent requests for that content is served from the CDN cache server.


Load Balancing

Following are some frequently asked questions in Load Balancing


What is a load balancer?

Key Concept

A load balancer distributes network traffic across a cluster of servers. This ensures that no single server is over-loaded; hence improving the responsiveness of an application, and also improving the availability of the application.

In a distributed application multiple load balancers are commonly put between different layers -
Between the client and web servers
Between the web servers and application servers
Between the application servers and database servers.


What are the key benefits of load balancer?

Key Concept

Following are the key benefits of a load balancer

Application Responsiveness - A load balancer distributes network traffic across a cluster of servers. This ensures that no single server is over-loaded; hence improving the responsiveness of an application.

Application Availability - A load balancer checks the health of a server before routing requests to that server, hence improving the availability of the application.

SSL Termination - A load balancer can decrypt SSL (Secure Sockets Layer) traffic before passing the request on to the web server, which reduces processing times and CPU cycles on the web server. This is called SSL Termination.

Prevention from DDoS attacks - Load balancer can defend against denial-of-service (DDoS) attacks by off-loading the attack traffic from the servers to cloud provider.

Predictive Analytics - A load balancer can provide predictive analytics such as traffic insights and bottlenecks before they happen.


How does a load balancer choose which server to route a request to?

Key Concept

A load balancer considers two factors to determine which server to route a request to.

Server health check - A load balancer pings the servers at regular intervals to determine the health of the servers. If a server fails a health check then that server is removed from the healthy server pool and requests are not routed to that server, until it responds to the health check again

Load balancing Algorithms - A load balancer determines which server to send a request to, out of the pool of healthy servers, by using on the many load balancing algorithms.


What are the different load balancing algorithms?

Key Concept

Following are some of the common load balancing algorithms

Least Connection Method - Routes request to the server having the least number of active connections.

Least Response Time Method - Routes request to the server having the least number of active connections and lowest average response time.

Round Robin Method - Routes request to the first available server and then moves it to the end of the queue.

Weighted Round Robin Method - Routes request to the first available server having the highest weight. Each server is assigned a weight, an integer number, based on its processing capacity.

IP Hash Method - The hash of the IP address of a server determines which server receives the request.


What is the difference between Layer 4 and Layer 7 load balancers?

Key Concept

Layer 4 - A layer 4 load balancer uses the information defined at the networking transport layer (Layer 4) as the basis for deciding how to route traffic across a cluster of servers. For web traffic, layer 4 information includes source and destination IP addresses and ports.

Layer 7 - A layer 7 load balancer uses the information defined at the networking application layer (Layer 7) as the basis for deciding how to route traffic across a cluster of servers. For web traffic, layer 7 information includes HTTP header and content message such as destination URL, content type (text, video, image), cookie information etc.


Caching

Following are some frequently asked questions in Caching


What is Caching?

key Concept

Caching is the mechanism of storing data in a temporary storage location, either in memory or on disc, so that request to the data can be served faster.

Caching improves performance by decreasing page load times, and reduces the load on servers and databases.

In a typical caching model, when a new client request for a resource comes in, a lookup is done on the temporary storage to see if a similar request came in earlier. If a similar request is found then the previous result is returned with out hitting the server or database. If a similar request is not found, then the client request is send to the server or database to fetch the result, the result is updated in the temporary storage, and the result is returned back to the client.


What are the different layers in a distributed system, where cache can be implemented?

key Concept

Caching can be implemented in the following layers.

Client caching - Caching on the client side (browser)

CDN caching - A Content Delivery Network (CDN) which is a globally distributed network of proxy servers, typically serving static content, is considered a type of cache.

Web server caching - Caching on the web server or proxy server side, which enables returning client response without contacting the application servers or databases.

Application server caching - Caching on the application server side, which enables returning client response without contacting the database.

Database caching - Caching on the database side, which enables returning client response without executing the queries.


What is cache invalidation? What are the three main methods of cache invalidation

key Concept

When data is updated in the database, then that data has to be refreshed in the cache as well. This is called cache invalidation.

There are three main methods of cache invalidation

Write-through cache - Data is written to the cache and database at the same time.

Write-around cache - Data is written to the database writing to cache. Data is written to cache when a request results in a 'cache miss', at which point data in retrieved from database, written to cache, and send back to client.

Write-back (Write-behind) cache - Data is written to the cache without writing to database. Data is written to database asynchronously.


What is cache invalidation? What are the three main methods of cache invalidation

key Concept

When data is updated in the database, then that data has to be refreshed in the cache as well. This is called cache invalidation.

There are three main methods of cache invalidation

Write-through cache - Data is written to the cache and database at the same time.

Write-around cache - Data is written to the database writing to cache. Data is written to cache when a request results in a 'cache miss', at which point data in retrieved from database, written to cache, and send back to client.

Write-back (Write-behind) cache - Data is written to the cache without writing to database. Data is written to database asynchronously.


What are cache eviction algorithms?

key Concept

Following are some common cache eviction algorithms

First In First Out (FIFO)

Last In First Out (LIFO)

Least Recently Used (RLU)

Most Recently Used (MRO)

Least Frequently Used

Least Frequent Recently Used (LFRU)

Random Replacement (RR)


Data Replication

Following are some frequently asked questions in Data Replication


What is Data Replication?

key Concept

Data replication is the technique of storing copies of same data in multiple databases. Data replication improves the availability of applications.


What are different kinds of Data Replication?

key Concept

There are two kinds of data replication.

Master-slave replication - In this kind of replication the master serves both read and write requests, and replicates the writes to one or more slaves. The slaves serve read requests only. If the master goes down, the system will continue to serve in read-only mode until the system promotes a slave to a master, or until a new master is provisioned.

Master-master replication - In this kind of replication multiple masters serve read and write requests. The writes are replicates to all master servers. The masters are fronted with a load balancer, and even if a master goes down the system will continue to serve read and write requests from the other masters.


Data Partitioning

Following are some frequently asked questions in Data Partitioning


What is data partitioning?

key Concept

Data partitioning is a technique to split a large database into multiple smaller, distinct, and independent parts; across multiple machines; to improve manageability, availability and performance.


What are the key benefits of data partitioning?

key Concept

Following are the key benefits of data partitioning.

1. Improve Scalability - Scalability improves since you can scale up by adding new machines.

2. Improve Performance - Performance improves since you will query from a smaller subset of data.

3. Improve Availability - Availability improves since having multiple machines avoids a single pount of failure.

4. Improve Security - Security improves since you can separate secure data from un-secure data.


What are the different strategies of data partitioning?

key Concept

Following are the key strategies of data partitioning.

1. Horizontal partitioning (Sharding) - In this strategy data is split into partitions, called shards. Each shard contains a subset of the data, based on a shard key. Example - a system can store orders for each state in a different partition.

2. Vertical partitioning - In this strategy data is split into partiotions based on the pattern of use. Example - an application can store frequently ordered items in one partition, and less frequently ordered items in another partiton.

3. Functional partitioning (Federation) - In this strategy data is split into partitions based on its functional use. For example an application can store inventory data in partition and order data in another partition.


What are the different partitioning criteria?

key Concept

Following are the key strategies of data partitioning.

1. Range partitioning

2. List partitioning

3. Round-robin partitioning

4. Hash partitioning

5. Composite partitioning


-->
 
Subscribe to our Newsletter