System Design
System Design
It is the process of design the elements of a system. Such as the architecture modules and components the different
interfaces of those components and the data goes through system.
Monolithic Architecture:
Frontend, backend and DB written and deployed at same place, all the components and functionalities are in
single codebase. It has less complexity and easy to understand, it is also known as centralized.
Can’t be scaled and if any error occur it destroy the whole system.
Distributed system:
Is a collection of multiple individual system connected through network that shares common resources.
Like we purchase DB in different machines and connect them, and each machines should have replica or
extra machine in which we can copy data which will act as backup in case of machine failure.
Latency:
In monolithic system only computational delay
Geographically distributed network of proxy servers and their objective is to serve content to users more
rapidly
Caching:
Caching is the process of storing information for a set period of time on a computer
Throughput:
Amount of data transmitted per unit of time, it is the process flow rate
Measured in bps, bits per second.
Availability:
We make replicas of each resource in distributed system, if any failure occur then
system will be available due to resources are distributed and it also includes replications.
consistency:
In monolithic more consistency bcz we don’t share our resources so no need sync with other
systems.
CAP Theorem:
C=consistency
A=availability
P=partition tolerance
Horizental scalabling:
We increase load on server we increase the configuration of that machine in which we are
running our server
Redendency:
It is duplication of nodes, if any node or component fail the other server will be available to
customer.
Active Redendency:
If all server are working at a time, req is managed with load balancer
passive Redendency:
one server will be in working state, it one fail then other will start
Replication:
Retendency+sync
Duplication in live time, when one data change in one server at same time it will change in
other server.
In active different machine working in same time managed with load balancer
In passive, master server works and change data in slave server, if master dies and slave
become master
Load balancer:
It is used in microservices/distributed_system
Round robins (1st request to 1st server, 2nd to 2nd and so on)
Waited rounded (one server have limit to handle when limit complete then move to
next)
IP hash algorithms (hash function deside to which ip to be redirected)
Source IP hash (source IP and the nearest location of server compare to redirect)
Caching:
Primary memory(ram) is used to store data temporary. It is used as a layer between DB and
server to reduce latency. When we load data 1st time from DB it stores in caches and we give
time cache to remove automatically after sometime. We use cache where reading is extensive
or web contain static content
Types of caches:
Distributed
CDN:
It is also type of cache, we store cache in cdn and served through cdn instead of DB
LRV: process to delete data which is not used since some time.
LFV: least used data will be deleted and most used data will remain
FIFO: 1st cached data will be deleted 1st after some time
Data stores in the form files (e.g. txt) but security and inconsistency problems occur.
RDBMS:
Non-SQL/ non-relational:
Key-value based like reddix for caching, document based like mongoDB, columnar db for
data analysis or machine learning, graph DB used for social networking DB like graphql.
Polyglot persistence:
Normalization in DB:
Denormalization:
putting data from multiple tables to single tables and merge it into one table.
It make faster data read operation, high data available, easy management.
Indexing:
For write intensive Indexing should not be used bcz time complexity increase
Synchronous communication/known as blocking call:
If one app sending req to other app then it will wait for res from other app, till that it will not
do any other work. It is sequential process in we have to complete each step in sequence.
Things not work in sequence. The step to which other task are not dependent can
be do in non-sequence manner.
P2P, agent send message it goes to agent (queue) then agent forward it to the
consumer.
Webserver:
Hardware, software or both that store component files of software and run software to
interchange data between users
Communication programme:
Push:
Client open the connection with server and keeps it always active and server give data
when ever new data come, no need to req again and again.
e.g. like feature in fb, it automativcally shows like increase without refreshing or
requesting of user
Pull/polling:
Long polling:
Socket:
Long lived connection, clent subscribe the server stream , server will send msg to
client on each event happen until client unsubscribe the server.
o Fast
o Light weighted
Use in agile
Selective scaling (mean most used api can be scale amongst the others api)
Microservices Architecture:
Highly scalable
Oauth:
Proxy:
Client send req, proxy forward to main server but the server don’t
know who is client
Like. We use vpn, our req go to vpn then vpn forward to blocked site,
blocked site send req to vpn and vpn forward to us