Latency

graph LR;
User--t1-->Server
Server--t2-->User
Server--t3:Computation-->Server
subgraph Latency
A[t1+t2+t3]
B[network delay<br>+<br>computational delay]
end

Monolithic<<Distrubuted :Latency

Methods to reduce Latency

function getName(userId){
.........we are getting this after 1000 lines of code.....
}
function getName(userId="abc"){
if(userId==="abc"){
return [...results];
}
......... 1000 lines of code.....
}

Throughput

Causes of Low Throughput

Methods to increase Throughput

Availability

Causes of Low Availability

Methods to increase Availability

Consistency

graph TD;
subgraph Delhi
A[Ticket1<br>booked]
B[Ticket2]
C[Ticket3]
end
subgraph Pune
X[Ticket1<br>booked]
Y[Ticket2]
Z[Ticket3]
end
subgraph Status
T[Data should be updated<br> on change on any loaction's data]
end

Types of Consistency

Strong Consistency Eventual Consistency Weak Consistency
when the system doesn't allow
read operation until the data
is written to
all the replicas
when the system allows read
operation
even if the data is not written
to
all the replicas
Not need to update all
the replicas 
it depends upon the
business logics
Example: Ticket Booking Example: Social media post
Update

CAP Theorem

Lamport Logical Clock

graph LR;
a[Server 1<br>USA Washington DC<br> time:8:23 AM]
b[Server 2<br>India<br> time:6:53 PM]
c[Server 3<br>UK<br> time:1:23 PM]
a-->b-->c-->a
subgraph Events
A[How can we find which event is first occuring]
end

Scalability

graph
A[Scaling]-->B[Horizontal Scaling]
A-->C[Vertical Scaling]

Vertical Scaling

graph LR;
A[Server<br> 25 GB ]-->B[Server <br> 100 GB]

Pros

Cons

Horizontal Scaling

Pros

Cons

Redundancy and Replication

Redundancy

Types

Replication

Types

graph LR;
D-->A
A-->D[Server 2]
E[Server 3]-->D
D-->E
E-->A
A-->E
A[Server 1]-->B[Copy 1<br> I am awaking and <br> continuously Copying the data  from server <br> So i am Actively Redundance]
A-->C[Copy 2<br> I am sleeping and <br> not Copying the data  from server <br> So i am Passively Replication]
subgraph Redundancy
X[Active Redundancy]
Y[Passive Redundancy]
end
graph LR;
subgraph Active Replication
D-->A
A-->D[Server 2]
E[Server 3]-->D
D-->E
E-->A
A-->E
A[Server 1]-->a[DB 1 <br> Master Node<br> read write simultaneously]
A-->c[DB 2 <br> Master Node<br> read write simultaneously]
A-->d[DB 3 <br> Master Node<br> read write simultaneously]
A-->e[DB 4 <br> Master Node<br> read write simultaneously]
A-->f[DB 5 <br> Master Node<br> read write simultaneously]
a-->c
c-->a
c-->d
d-->c
d-->e
e-->d
e-->f
f-->e
f-->a
a-->f
end
subgraph Passive Replication
D1-->A1
A1-->D1[Server 2]
E1[Server 3]-->D1
D1-->E1
E1-->A1
A1-->E1
A1[Server 1]-->a1[DB 1 <br> Master Node<br> read write simultaneously]
A1-->c1[DB 2 <br> Slave Node<br> read write on permission <br> by Master Node]
A1-->d1[DB 3 <br> Slave Node<br> read write on permission <br> by Master Node]
A1-->e1[DB 4 <br> Slave Node<br> read write on permission <br> by Master Node]
A1-->f1[DB 5 <br> Slave Node<br> read write on permission <br> by Master Node]
a1-->c1
c1-->a1
c1-->d1
d1-->c1
d1-->e1
e1-->d1
e1-->f1
f1-->e1
f1-->a1
a1-->f1
end
subgraph Replication
X[Active Replication ]
Y[Passive Replication]
end

Load Balancer

NGINX

Diagram of Normal HTTP Connection

  graph LR
    A[Client] -- Normal HTTP Connection --> B[Server]

Diagram of HTTP Connection with VPN

  graph LR
    A[Client] -- Normal HTTP Connection --> B[Server]
    A <--> C[Forward Proxy Server]
    C <--> B
  graph LR
    A[Client 1] <--> B[Forward Proxy :VPN]
    C[Client 2]<--> B
    D[Client 3]<--> B
    E[Client 4]<-->B
    B<-->F[Server]   
  

Connection of NGINX

  graph LR
    A[Client] -- Normal HTTP Connection --> B[Reverse Proxy S:NGINX]
    B <--> C[Server 1]
    B <--> D[Server 2]
    B <--> E[Server 3]
    B <--> F[Server 4]
  
graph LR;
A[Client 1]<-->B[NGINX]
C[Client 2]<-->B
D[Client 3]<-->B
E[Client 4]<-->B
F[Client 5]<-->B
G[Client 6]<-->B
H[Client 7]<-->B
B--Request Sending On specific server after decision-->I[Decision Output]
I-->J[Server 1]
I-->K[Server 2]
I-->L[Server 3]
I-->M[Server 4]
I-->N[Server 5]
I-->O[Server 6]
I-->P[Server 7]
I-->Q[Server 8]

More Clearation

graph LR;
A[Client 1]<-->B[NGINX]
C[Client 2]<-->B
D[Client 3]<-->B
E[Client 4]<-->B
F[Client 5]<-->B
G[Client 6]<-->B
H[Client 7]<-->B
B--/admin-->J[Server 1]
B--/user-->K[Server 2]
B--/admin-->L[Server 3]
B--/settings-->M[Server 4]
B--/all-->N[Server 5]
B--/todo-->O[Server 6]
B--/example-->P[Server 7]
B--/ex-->Q[Server 8]

Contributions

When to use Load Balancer

Challenges

Solutions

Advantages

Load Balancing Algorithms