System Design

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

System Design

Systems design is the process of defining the architecture,


components, modules, interfaces, and data for a system to
satisfy specified requirements.

• Before we start designing any system, we must discuss what


are the main features this system is going to support.
• Then find out all the modules, which will help you in
determining API’s and database schema.
• Now discuss about how available and consistent your
application would be?
• Design class diagrams.
Topics We must Know

• Client Vs Server • Scaling (Horizontal and Vertical)


• Request Vs Response • Sharding

• Protocols[HTTP, HTTPS, TCP, UDP, Web Socket • Consistent Hashing


etc.] • Availability Consistency(Strong Vs Eventual)
• Cloud Hosting and Virtual Machine • Replication
• Object Oriented Design • CAP Theorem
• Design Patterns • Load Balancer
• Web API vs Web service • CDNS
• Micro Services Vs Monolithic • Multi Threading, Concurrency, Locks,
Synchronization.
• Caching
• Disk Read Operation [Random Vs Sequential]
• RDBMS[ACID] Vs NoSQL [BASE]
• CPU, Memory, Hard drive, Network Bandwidth
Client and Server
• Server: refers to operations that are
performed by the server in a client–server
relationship in computer networking. Typically,
a server is a software program, such as a web
server, that runs on a remote server, reachable
from a user's local computer or workstation.
• Client: refers to operations that are performed
by the client in a client–server relationship in a
computer network. Typically, a client is a
computer application, such as a web browser,
that runs on a user's local computer or
workstation and connects to a server as
necessary.
Cloud Hosting and Virtual Machine

• Cloud server: is a logical server that is built, • DNS: The Domain Name Systems (DNS) is the
phonebook of the Internet. Humans access
hosted and delivered through a cloud
information online through domain names,
computing platform over the Internet. Cloud
like pepcoding.com or google.com. Web
servers possess and exhibit similar
browsers interact through Internet Protocol
capabilities and functionality to a
(IP) addresses. DNS translates domain names
typical server but are accessed remotely from
to IP addresses so browsers can load Internet
a cloud service provider.
resources.
• Virtual Machine: A virtual machine is a
computer file, typically called an image, which
behaves like an actual computer. In other
words, creating a computer within a
computer.
Common Protocols
• HTTP: It allows you to download data from the
internet as well as provides you the privilege to
browse web pages on the internet. 
• HTTPS: It makes use of Secure Socket Layer (SSL) • Web Socket: It provides full-duplex
to add an extra feature of security to the network.  communication channels over a single TCP
• TCP/IP: is a suite of communication connection. The WebSocket protocol enables
protocols used to interconnect network devices on communication with lower overhead than
the internet. It can also be used as a half-duplex alternatives such as HTTP polling,
communications protocol in a private network (an facilitating real-time data transfer from and to
intranet or an extranet the server. 
• UDP:  (User Datagram Protocol) is an alternative
communications protocol to Transmission Control
Protocol (TCP) used primarily for establishing low-
latency and loss-tolerating connections between
applications on the internet.
Object Oriented Design

• Encapsulation- The implementation and state


of each object are privately held inside a
defined boundary, or class. Other objects do
not have access to this class or the authority
to make changes but are only able to call a list
of public functions, or methods. This • Inheritance- Relationships and subclasses
characteristic of data hiding provides greater between objects can be assigned, allowing
program security and avoids unintended data developers to reuse a common logic while still
corruption. maintaining a unique hierarchy. This property
of OOP forces a more thorough data analysis,
• Abstraction- Objects only reveal internal reduces development time and ensures a
mechanisms that are relevant for the use of higher level of accuracy.
other objects, hiding any unnecessary
implementation code. This concept helps • Polymorphism- Objects are allowed to take
developers make changes and additions over on more than one form depending on the
time more easily. context.
Design Patterns

• Design patterns can speed up the development


process by providing tested, proven development
paradigms.
• Effective software design requires considering issues
that may not become visible until later in the
implementation.
• Reusing design patterns helps to prevent subtle

issues that can cause major problems.
• Improves code readability for coders and architects
familiar with the patterns.
• Often, people only understand how to apply certain software
design techniques to certain problems. These techniques are
difficult to apply to a broader range of problems. Design
patterns provide general solutions, documented in a format
that doesn't require specifics tied to a particular problem.
Web API vs Web service
• An API exactly defines the methods for
one software program to interact with the
other.
• When this action involves sending data over a • 1. All Web services are APIs, but all APIs are not
network, Web services come into the picture. Web services.
An API generally involves calling functions
from within a software program. • 2. Web services might not perform all the
operations that an API would perform.
• In case of Web applications, the API used is
web based. • 3. A Web service uses only three styles of use:
SOAP, REST and XML-RPC for
• Desktop applications such as spreadsheets
and word documents use VBA and COM-based • communication whereas API may use any
APIs  style for communication.
• 4. A Web service always needs a network for its
operation whereas an API doesn’t need
Micro Services Vs Monolithic 
• Monolithic Architecture: A monolithic
application has single code base with multiple
modules. Modules are divided as either for
business features or technical features. It has
single build system which build entire
application. It also has single executable or
deployable binary.
• Microservice Architecture: A microservices
architecture consists of a collection of small,
autonomous services. Each service is self-
contained and should implement a single
business capability.
Cache

• Cache:
A cache is a memory buffer used to
temporarily store frequently accessed data.
It improves performance since data does not
have to be retrieved again from the original
source. 
• Distributed cache:
• When the system gets to certain scale, we
need to distribute the cache to multiple
machines. The general strategy is to keep a • Eviction Policy: Eviction policy tries to predict
hash table that maps each resource to the which entries are most likely to be used again
corresponding machine. Therefore, when in near future, thereby maximizing the hit
requesting resource A, from this hash table we ratio. The Least Recently Used (LRU) policy is
know that machine M is responsible for cache perhaps the most popular due to its simplicity,
A and direct the request to M. good runtime performance
RDBMS[ACID] Vs NoSql [BASE]
• The key ACID guarantee is that it provides a
safe environment in which to operate on your
data. The ACID acronym stands for:
Atomic: All operations in a transaction • For many domains and use cases, ACID
succeed or every operation is rolled back. transactions are far more pessimistic (i.e.,
they’re more worried about data safety) than the
Consistent: On the completion of a domain requires.
transaction, the database is structurally
sound. Basic Availability: The database appears to
Isolated: Transactions do not contend with work most of the time.
one another. Contentious access to data is • Soft-state: Stores don’t have to be write-
moderated by the database so that consistent, nor do different replicas have to be
transactions appear to run sequentially. mutually consistent all the time.
Durable: The results of applying a transaction • Eventual consistency: Stores exhibit consistency
are permanent, even in the presence of at some later point (e.g., lazily at read time).
failures.
Vertical scaling and Horizontal scaling
• Requires Load Balancer • N/A
• Resilient • Single Point Of failure
• Network Calls (RPC) • IPC
• Data Inconsistency • Consistent
• Scales well as per requirement • Hardware Limit
Sharding
• Sharding is a type of
database partitioning that separates very
large databases the into smaller, faster, more
easily managed parts called data shards. The
word shard means a small part of a whole.
• Range Based Sharding
• Key Based Sharding(Hash based sharding)
• Directory Based Sharding
Consistent Hashing

• Consistent hashing allows you to


scale up and down easier and makes
ensuring availability easier. Easier
ways to replicate data allows for
better availability and fault-tolerance.
Easier ways to reshuffle data when
nodes come and go means simpler
ways to scale up and down.
Consistency 
• Eventual Consistency: Whenever we use
multiple replicas of a database to store data and
let’s say a write request comes to one of the
replicas. In such a situation, Databases had to
discover a strategy to make this write request at
one replica reach other replicas so that they all
could also write data of the request and become
consistent.
• Strong Consistency: It says data will get passed
on to all the replicas as soon as a write request
comes to one of the replicas of the database.
But during the time these replicas are being
updated with new data, response to any
subsequent read/write requests by any of the
replicas will get delayed as all replicas are busy in
keeping each other consistent.
CAP Theorem
• CAP theorem, is also named Brewer's theorem
after computer scientist Eric Brewer, states that it
is impossible for a distributed data store to
simultaneously provide more than two out of the • CAP is frequently misunderstood as if one
following three guarantees. always has to choose to abandon one of the
Consistency: every read receives the most recent three guarantees. In fact, the choice is really
write or an error between consistency and availability only when
Availability: Every request receives a (non-error) a network partition or failure happens; at all
response – without the guarantee that it contains the other times, no trade-off has to be made
most recent write
Partition Tolerance: The system continues to operate
• Database systems designed with
despite an arbitrary number of messages being
traditional ACID guarantees in mind such
dropped (or delayed) by the network between nodes. as RDBMS choose consistency over availability,
No distributed system is safe from network failures;
whereas systems designed around
thus network partitioning generally has to be tolerated. In the BASE philosophy, common in
the presence of a partition, one is then left with two the NoSQL movement for example, choose
options: consistency or availability. availability over consistency.
Load Balancer
• Load balancing refers to efficiently
distributing incoming network traffic across a
group of backend servers, also known as
a server farm or server pool.
Round Robin – Requests are distributed
across the group of servers sequentially.
Least Connections – A new request is sent to
the server with the fewest current
connections to clients.
IP Hash – The IP address of the client is used
to determine which server receives the
request.
• Design a service like Tiny URL[ Tushar Rai]:
https://www.youtube.com/watch?v=fMZMm_0ZhK4
• Autocomplete or Typeahead Suggestions for Google search: Tushar
Rai https://www.youtube.com/watch?v=us0qySiUsGU
• Architecture for auto suggestions [ Narendra L]:
• https://www.youtube.com/watch?v=xrYTjaK5QVM&list=PLkQkbY7JNJ
uBoTemzQfjym0sqbOHt5fnV&index=9&t=0s
Practice • Messaging/chat service like FB or WhatsApp [ Tushar Rai]:
Designs Videos https://www.youtube.com/watch?v=zKPNUMkwOJE
• Twitter system design [Narendra L]:
https://www.youtube.com/watch?v=wYk0xPP_P_8&list=PLkQkbY7JNJ
uBoTemzQfjym0sqbOHt5fnV&index=4&t=0s
• Uber System design [Narendra L]:
https://www.youtube.com/watch?v=umWABit-wbk&list=PLkQkbY7JN
JuBoTemzQfjym0sqbOHt5fnV&index=7&t=54s
• System Design Shopify eCommerce:
https://www.youtube.com/watch?v=lEL4F_0J3l8&list=PLA8lYuzFlBqAy6dk
ZHj5VxUAaqr4vwrka&index=9&t=0s
• https://www.interviewbit.com/problems/sharding-a-
database/
• https://www.interviewbit.com/problems/design-cach
e/
• https://www.interviewbit.com/problems/highly-consi
stent-database/
Good reads
• https://leetcode.com/discuss/interview-question/syst
From GFG and em-design/200342/Bloomberg%3A-Implement-a-sys
tem-to-track-runners-in-a-marathon
Interview bit
• https://www.geeksforgeeks.org/design-scalable-syst
em-like-foursquare/
• https://www.geeksforgeeks.org/design-video-sharin
g-system-like-youtube/
• https://www.geeksforgeeks.org/design-movie-ticket-
booking-system-like-bookmyshow/
• https://www.geeksforgeeks.org/design-online-hotel-
booking-system-like-oyo-rooms/

You might also like