Fundamentals of Backend Communications and Protocols
Fundamentals of Backend Communications and Protocols
Fundamentals of Backend
Communications and
Protocols
Understand what’s behind the backend
husseinnasser
Introduction
husseinnasser
Introduction
● Welcome
● Who this course is for?
● Course Outline
husseinnasser
Backend Communication
Design Patterns
There are handful of ways backends communicate
husseinnasser
Request - Response
Classic, Simple and Everywhere
Request Response Model
GET / HTTP/1.1
Headers
<CRLF>
BODY
Building an upload image service with request response
● Notification service
● Chatting application
● Very Long requests
● What if client disconnects?
● We will talk about alternatives
Request/Response
t0
Request
t2
Request
processing
time
t30
Response
t32
husseinnasser
Demo Curl
–trace
husseinnasser
Synchronous vs
Asynchronous
Can I do work while waiting?
Synchronous I/O
Executes
code
locally….
Synchronous vs Asynchronous in real life
Demo NodeJS
Blocking call (loop) and fetch
husseinnasser
Push
I want it as soon as possible
Request/response isn’t always ideal
*Backend gets
message*
ge 1
New messa
ge 2
New messa
Push Pros and Cons
● Pros
○ Real time
● Cons
○ Clients must be online
○ Clients might not be able to handle
○ Requires a bidirectional protocol
○ Polling is preferred for light clients
husseinnasser
Demo WebSockets
Push notification (users login)
husseinnasser
Short Polling
Request is taking a while, I’ll check with you later
Where request/response isn’t ideal
Request
RequestID X
Is X ready?
No
Is X ready?
No
Is X ready?
Response
Short Polling Pros and Cons
● Pros
○ Simple
○ Good for long running requests
○ Client can disconnect
● Cons
○ Too chatty
○ Network bandwidth
○ Wasted Backend resources
husseinnasser
Long Polling
Request is taking long, I’ll check with you later
But talk to me only when it's ready
Where request/response & polling isn’t ideal
Request
RequestID X
Is X ready?
Response
Long Polling Pros and Cons
● Pros
○ Less chatty and backend friendly
○ Client can still disconnect
● Cons
○ Not real time
husseinnasser
Request
*Backend gets
message*
event1
event2
Server Sent Events Pros and Cons
● Pros
○ Real time
○ Compatible with Request/response
● Cons
○ Clients must be online
○ Clients might not be able to handle
○ Polling is preferred for light clients
○ HTTP/1.1 problem (6 connections)
husseinnasser
Publish Subscribe
One publisher many readers
Request Response
GET /
content..
Web Server
Where it breaks
Copyright
Service
Request/Response pros and cons
Pros Cons
1080p video
Uploaded! Upload
Service
4k video
Format
Service
Message Queue
topics/channels Notification
Service
Pub/Sub pros and cons
Pros Cons
RabbitMQ Demo
Publish a job and have worker pick them up
husseinnasser
Multiplexing vs
Demultiplexing
HTTP/2, QUIC,
Connection Pool, MPTCP
Multiplexing vs Demultiplexing
Multiplexing example HTTP/2
3 HTTP/1.1 Connections
HTTP request 1 HTTP/1.1 server
HTTP request 2
HTTP request 3
HTTP request 2
HTTP request 3
Multiplexing HTTP/2 on the Backend
Proxy
3 HTTP/1.1 Connections (e.g. ENVOY)
1 HTTP/2 Connection
h1 frontend h2
backend HTTP/2 server
More throughput
High backend resources (CPU for h2)
Demultiplexing HTTP/1.1 on the Backend
Proxy
(e.g. ENVOY) 3 HTTP/1.1 Connections
1 HTTP/2 Connection
h2 frontend h1 HTTP/1.1 server
backend
less throughput
low backend resources (simple h1)
Connection Pooling
Backend Server Database Server
4 Database Connections
Browser demultiplexing in HTTP/1.1
6 HTTP/1.1 Connections
HTTP/1.1 server
HTTP request 1
HTTP request 2
HTTP request 3
Stateless vs Stateful
Is state stored in the backend?
Stateful vs Stateless backend
● Stateful
○ Stores state about clients in its memory
○ Depends on the information being there
● Stateless
○ Client is responsible to “transfer the
state” with every request
○ May store but can safely lose it
Stateless Backends
S1
/profile
cookie=S1 Check if S1 is in
memory to
authenticate
and return.
Stateful backend where it breaks
/profile
Cookie =S1
/login
Backend
restarted
Sessions are
empty
Stateless backend
Generate
session S1,
return to user
&pass
and store in DB verify user
/
/login user&pass
S1
Store
S1
S1?
/profile
cookie=S1 Check if S1 is in
the DB
Sidecar Pattern
Thick clients, Thicker backends
Every protocol requires a library
HTTP/1.1 Server
HTTP/1.1 Client
HTTP/1.1 HTTP/1.1
Library Library
HTTP/2 Server
HTTP/2 Client
HTTP/2 HTTP/2
+ +
HTTP/1.1 HTTP/1.1
Library Library
Every protocol requires a library
TLS Server
TLS Client
TLS
TLS
Library
Library
(openSSL)
(rustSSL)
gRPC Server
gRPC Client
gRPC gRPC
Library Library
Changing the library is hard
HTTP/2
HTTP/2
+TLS
+TLS
Library
Library
Sidecar Design Pattern - Upgrade to HTTP/3!
http/1.1 Server
HTTP/1.1 client
HTTP/3 + Secure
HTTP/3
HTTP/3
+QUIC
+QUIC
Library
No change in both Library
client and server
code, just the
proxies
But introduces an
extra hop
Sidecar Examples
Cons
● Complexity
● Latency
husseinnasser
Protocols
How the client and backend communicate
husseinnasser
Protocol Properties
What to take into account when designing a protocol?
What is a protocol?
OSI Model
Open Systems Interconnection model
husseinnasser
Client Server
Application Application
Presentation Presentation
Session Session
Physical Physical
Client Server
Client Server
Application Application
Presentation Presentation
Session Session
TCP/IP Model
● Much simpler than OSI just 4 layers
● Application (Layer 5, 6 and 7)
● Transport (Layer 4)
● Internet (Layer 3)
● Data link (Layer 2)
● Physical layer is not officially covered in the model
husseinnasser
UDP
User Datagram Protocol
husseinnasser
UDP
● Stands for User Datagram Protocol
● Message Based Layer 4 protocol
● Ability to address processes in a host using ports
● Simple protocol to send and receive messages
● Prior communication not required (double edge sword)
● Stateless no knowledge is stored on the host
● 8 byte header Datagram
husseinnasser
A B
husseinnasser
10.0.0.1 10.0.0.2
husseinnasser
UDP Pros
● Simple protocol
● Header size is small so datagrams are small
● Uses less bandwidth
● Stateless
● Consumes less memory (no state stored in the server/client)
● Low latency - no handshake , order, retransmission or guaranteed delivery
husseinnasser
UDP Cons
● No acknowledgement
● No guarantee delivery
● Connection-less - anyone can send data without prior knowledge
● No flow control
● No congestion control
● No ordered packets
● Security - can be easily spoofed
husseinnasser
Summary
● UDP is a simple message based layer 4 protocol
● Uses ports to address processes
● Stateless
● Pros & Cons
husseinnasser
TCP
Transmission Control Protocol
husseinnasser
TCP
● Stands for Transmission Control Protocol
● Stream based Layer 4 protocol
● Ability to address processes in a host using ports
● “Controls” the transmission unlike UDP which is a firehose
● Connection
● Requires handshake
● 20 bytes headers Segment (can go to 60)
● Stateful
husseinnasser
A B
husseinnasser
TCP Connection
● Connection is a Layer 5 (session)
● Connection is an agreement between client and server
● Must create a connection to send data
● Connection is identified by 4 properties
○ SourceIP-SourcePort
○ DestinationIP-DestinationPort
husseinnasser
TCP Connection
● Can’t send data outside of a connection
● Sometimes called socket or file descriptor
● Requires a 3-way TCP handshake
● Segments are sequenced and ordered
● Segments are acknowledged
● Lost segments are retransmitted
husseinnasser
App1-port 5555
AppX-port 53
App2-port 7712
AppY-port 68
App3-port 2222
AppZ-port 6978
10.0.0.1
10.0.0.2
husseinnasser
Connection Establishment
● App1 on 10.0.0.1 want to send data to AppX on 10.0.0.2
● App1 sends SYN to AppX to synchronous sequence numbers
● AppX sends SYN/ACK to synchronous its sequence number
● App1 ACKs AppX SYN.
● Three way handshake
Sending data
● App1 sends data to AppX
● App1 encapsulate the data in a segment and send it
● AppX acknowledges the segment
● Hint: Can App1 send new segment before ack of old segment arrives?
Acknowledgment
● App1 sends segment 1,2 and 3 to AppX
● AppX acknowledge all of them with a single ACK 3
File descriptor
File descriptor
10.0.0.2 22 ACK3 5555 10.0.0.1
husseinnasser
Lost data
● App1 sends segment 1,2 and 3 to AppX
● Seg 3 is lost, AppX acknowledge 3
● App1 resend Seq 3
Closing Connection
● App1 wants to close the connection
● App1 sends FIN, AppX ACK
● AppX sends FIN, App1 ACK
● Four way handshake
10.0.0.1 5555 FIN 22 10.0.0.2
AppX-port 22
App1-port 5555 AppY-port 443
App2-port 7712 AppZ-port 80
App3-port 2222 10.0.0.2 22 ACK 5555 10.0.0.1
TCP Pros
● Guarantee delivery
● No one can send data without prior knowledge
● Flow Control and Congestion Control
● Ordered Packets no corruption or app level work
● Secure and can’t be easily spoofed
husseinnasser
TCP Cons
● Large header overhead compared to UDP
● More bandwidth
● Stateful - consumes memory on server and client
● Considered high latency for certain workloads (Slow start/ congestion/ acks)
● Does too much at a low level (hence QUIC)
○ Single connection to send multiple streams of data (HTTP requests)
○ Stream 1 has nothing to do with Stream 2
○ Both Stream 1 and Stream 2 packets must arrive
● TCP Meltdown
○ Not a good candidate for VPN
husseinnasser
Summary
● Stands for Transmission Control Protocol
● Layer 4 protocol
● “Controls” the transmission unlike UDP which is a firehose
● Introduces Connection concept
● Retransmission, acknowledgement, guaranteed delivery
● Stateful, connection has a state
● Pros & Cons
husseinnasser
TLS
Transport Layer Security
TLS
● Vanilla HTTP
● HTTPS
● TLS 1.2 Handshake
● Diffie Hellman
● TLS 1.3 Improvements
HTTP
open 80
GET /
+
e a ders l
H .htm
d e x
in
h t m l>...
<
close ….
HTTPS open
443
Handshake
GET /
+
e a ders l
H
n d e x.htm
i
l>...
<htm
….
close
Why TLS
Change cip
her, fin
GET /
s+
Header l
tm
index.h
..
close <html>.
….
Diffie Hellman
Private x
+
Public g,n
= Symmetric key
+
Private y
Diffie Hellman
Public/
Unbreakable +
/can be shared
g^x % n
Public/
Unbreakable +
/can be shared
g^y % n
her/ fin
server hello/ change cip
GET /
s+
Header l
tm
index.h
..
<html>.
….
● Vanilla HTTP
● HTTPS
● TLS 1.2 Handshake (two round trips)
● Diffie Hellman
● TLS 1.3 Improvements (one round trip can be zero)
husseinnasser
HTTP/1.1
Simple web protocol lasts decades
Client / Server
Headers
Body
HTTP Request
HTTP Response
Protocol Code Code Text
Headers
Body
HTTP Response
HTTP
open 80
GET /
+
e a ders l
H .htm
d e x
in
h t m l>...
<
close ….
HTTPS open
443
Handshake
GET /
+
e a ders l
H
n d e x.htm
i
l>...
<htm
….
close
HTTP 1.0
open 80
GET /index
.html
close
GET /img1
.jpg
GET /img2
.jpg
….
HTTP 1.0
GET /index
.html
GET /img1
.jpg
GET /img2
.jpg
close
….
HTTP 1.1
Pipelining
open 80
GET /index
.html
GET /img1
.jpg
GET /img2
.jpg
close
….
HTTP 1.1
● SPDY
● Compression
● Multiplexing
● Server Push
● Secure by default
● Protocol Negotiation during TLS (NPN/ALPN)
HTTP over QUIC (HTTP/3)
● HTTP Anatomy
● HTTP/1.0 over TCP
● HTTP/1.1 over TCP
● HTTP/2 over TCP
● HTTP over QUIC (HTTP/3)
husseinnasser
WebSockets
Bidirectional communications on the web
Agenda
● HTTP
● WebSockets
● WebSockets Handshake
● WebSockets use cases
● WebSockets Example
● WebSockets Pros and Cons
HTTP 1.0
open 80
GET /index
.html
close
GET /img1
.jpg
GET /img2
.jpg
….
HTTP 1.1
open 80
GET /index
.html
GET /img1
.jpg
GET /img2
.jpg
close
….
WebSockets
open 80
Websocket handshake
close ….
WebSockets Handshake ws:// or wss://
open 80
GET 1.1 U
PGRADE
101 - Switching
Protocols
close
….
WebSocket Handshake
Client
Server
WebSockets use cases
● Chatting
● Live Feed
● Multiplayer gaming
● Showing client progress/logging
WebSockets Pros and Cons
Pros Cons
● No
● Rule of thumb - do you absolutely need bidirectional
communication?
● Long polling
● Server Sent Events
Summary
● HTTP
● WebSockets
● WebSockets Handshake
● WebSockets use cases
● WebSockets Example
● WebSockets Pros and Cons
husseinnasser
HTTP/2
Improving HTTP/1.1
Agenda
200 okGET
Html/index.html
document
….
HTTP 1.1
/index.html ✅
/main.js
/main.css
/img1.jpg
….
HTTP 1.1
ContentGET
type/main.css
css, main.js
/index.html ✅
/main.js ✅
/main.css
/img1.jpg
….
HTTP 1.1 (Browsers use 6 connections)
GET /main.js
GET /main.css
GET /img1.jpg
HTTP/2
GET /main.js (stream1)
GET /main.css (stream3)
GET /img1.jpg (stream5)
GET /img2.jpg (stream7)
HTTP/2 with Push
GET /index.html
Index.html
Main.css
Main.js
img.jpg
….
HTTP/2 Pros
HTTP/3
HTTP over QUIC
Multiplexed streams
Agenda
200 okGET
Html/index.html
document
….
HTTP 1.1
/index.html ✅
/main.js
/main.css
/img1.jpg
….
HTTP 1.1
ContentGET
type/main.css
css, main.js
/index.html ✅
/main.js ✅
/main.css
/img1.jpg
….
HTTP 1.1 (Browsers use 6 connections)
GET /main.js
GET /main.css
GET /img1.jpg
HTTP/2
GET /main.js (stream1)
GET /main.css (stream3)
GET /img1.jpg (stream5)
GET /img2.jpg (stream7)
TCP head of line blocking
2 1
GET /main.js (stream1)
4 3
8 7
2 1
GET /main.js (stream1)
4
8 7
2 1
GET /main.js (stream1)
4
8 7
gRPC
Taking HTTP/2 to the next level
Agenda
● Motivation ● Coding!
○ Client/Server Communication ● gRPC Pros & Cons
○ Problem with Client Libraries ● I’m tired of new protocols
○ Why gRPC was invented? ● Summary
● gRPC
○ Unary gRPC
○ Server Streaming
○ Client Streaming
○ Bidirectional
Client Server Communication
● Unary RPC
● Server streaming RPC
● Client streaming RPC
● Bidirectional streaming RPC
gRPC modes
● Unary RPC
● Server streaming RPC
● Client streaming RPC
● Bidirectional streaming RPC
gRPC modes
● Unary RPC
● Server streaming RPC
● Client streaming RPC
● Bidirectional streaming RPC
gRPC modes
● Unary RPC
● Server streaming RPC
● Client streaming RPC
● Bidirectional streaming RPC
Coding time!
WebRTC
Realtime communication on the web
Agenda
● WebRTC Overview
● WebRTC Demystified
○ NAT, STUN, TURN, ICE, SDP, Signaling the SDP
● Demo
● WebRTC Pros & Cons
● More WebRTC content beyond this content
WebRTC Overview
● A wants to connect to B
● A finds out all possible ways the public can connect to it
● B finds out all possible ways the public can connect to it
● A and B signal this session information via other means
○ WhatsApp, QR, Tweet, WebSockets, HTTP Fetch..
● A connects to B via the most optimal path
● A & B also exchanges their supported media and security
WebRTC Overview
How can people reach me?
How can people reach me?
B1, B2, B3 are candidates
(A1, A2, A3) are candidates
Security Parameters
Security Parameters
Media options
Media options
A1 B1
A2 B2
A B
A3 B3
WebRTC Overview
Looks like B2 is the available Looks like A1 is the available
and optimal path and optimal path
A1 B1
A2 B2
A B
A3 B3
WebRTC Demystified
● NAT
● STUN, TURN
● ICE
● SDP
● Signaling the SDP
Network Address Translation
10.0.0.1 5.5.5.5
10.0.0.2
8992 10.0.0.2 GET/ 4.4.4.4 80
4.4.4.4:80
8992 10.0.0.2 GET/ 4.4.4.4 80
3333 5.5.5.5 GET/ 4.4.4.4 80
3333 5.5.5.5 GET/ 4.4.4.4 80
10.0.0.1 5.5.5.5
10.0.0.2 200
80 4.4.4.4 5.5.5.5 3333
OK
80 4.4.4.4
200
10.0.0.2 8992 4.4.4.4:80
OK
200
80 4.4.4.4 10.0.0.2 8992
OK
200
80 4.4.4.4 5.5.5.5 3333
OK
200
22 3.3.3.3 5.5.5.5 3333
OK
200
8080 3.3.3.3 5.5.5.5 3333
10.0.0.1 5.5.5.5 OK
10.0.0.2 200
23 9.8.1.2 5.5.5.5 3333
OK
200
22 3.3.3.3 5.5.5.5 3333
OK
200
8080 3.3.3.3 5.5.5.5 3333
10.0.0.1 5.5.5.5 OK
10.0.0.2 200
23 9.8.1.2 5.5.5.5 3333
OK
200
22 3.3.3.3 5.5.5.5 3333
OK
200
8080 3.3.3.3 5.5.5.5 3333
10.0.0.1 5.5.5.5 OK
10.0.0.2 200
23 9.8.1.2 5.5.5.5 3333
OK
200
22 3.3.3.3 5.5.5.5 3333
OK
200
8080 3.3.3.3 5.5.5.5 3333
10.0.0.1 5.5.5.5 OK
10.0.0.2 200
23 9.8.1.2 5.5.5.5 3333
OK
10.0.0.1 5.5.5.5
10.0.0.1 5.5.5.5
9.9.9.9:3478
3478 9.9.9.9 RSP 5.5.5.5 3333 (STUN Sever)
10.0.0.2 You are
3478 9.9.9.9 RSP 10.0.0.2 8992
5.5.5.5:3333
3478 9.9.9.9 RSP 10.0.0.2 8992
5.5.5.5:3333
You
333 a re 7
5.5.5:3 .7.7
ar e 5. .7:4
444
You
192.168.1.2
10.0.0.2 Sure! 5.5.5.5:3333!
Behind full cone
Behind full cone
NAT
NAT
You
333 a re 7
5.5.5:3 .7.7
ar e 5. .7:4
444
You
192.168.1.2
10.0.0.2 NOPE!
Behind
Behind full cone
symmetric NAT
NAT
TURN
192.168.1.2
10.0.0.2
(7.7.7.7:4444)
(5.5.5.5:3333)
Behind
Behind
symmetric NAT
symmetric NAT
ICE
● Interactive Connectivity Establishment
● ICE collects all available candidates (local IP addresses,
reflexive addresses – STUN ones and relayed addresses
– TURN ones)
● Called ice candidates
● All the collected addresses are then sent to the remote
peer via SDP
SDP
● Session Description Protocol
● A format that describes ice candidates, networking
options, media options, security options and other stuff
● Not really a protocol its a format
● Most important concept in WebRTC
● The goal is to take the SDP generated by a user and send
it “somehow” to the other party
SDP Example
v=0
o=- 9148204791819634656 3 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video data
a=msid-semantic: WMS kyaiqbOs7S2h3EoSHabQ3JlBqZ67cFqZmWFN
m=audio 50853 RTP/SAVPF 111 103 104 0 8 107 106 105 13 126
c=IN IP4 192.168.1.64
a=rtcp:50853 IN IP4 192.168.1.64
a=candidate:3460887983 1 udp 2113937151 192.168.1.64 50853 typ host generation 0
a=candidate:3460887983 2 udp 2113937151 192.168.1.64 50853 typ host generation 0
...
Signaling
● SDP Signaling
● Send the SDP that we just generated somehow to the
other party we wish to communicate with
● Signaling can be done via a tweet, QR code, Whatsapp,
WebSockets, HTTP request DOESN’T MATTER! Just get
that large string to the other party
WebRTC Demystified
1. A wants to connect to B
2. A creates an “offer”, it finds all ICE candidates, security options,
audio/video options and generates SDP, the offer is basically the
SDP
3. A signals the offer somehow to B (whatsapp)
4. B creates the “answer” after setting A’s offer
5. B signals the “answer” to A
6. Connection is created
7.
WebRTC Demo
const iceConfiguration = {
iceServers: [{
urls: 'turn:turnserver.company.com:3478',
username: 'optional-username',
credentials: 'auth-token'},
{ urls: "stun:stun.services.mozilla.com",
username: "[email protected]",
credential: "webrtcdemo"}
]
}
const pc = new RTCPeerConnection(configuration);
Create your own STUN & TURN server
● stun1.l.google.com:19302
● stun2.l.google.com:19302
● stun3.l.google.com:19302
● stun4.l.google.com:19302
● stun.stunprotocol.org:3478
husseinnasser
● Establish Connection
● Establish Encryption
● Send Data
● Close Connection (when absolutely done)
HTTPs communications
Process vs Thread
What is the difference?
What is a Process?
PID
● A set of instructions
● Has an isolated memory
● Has a PID
● Scheduled in the CPU
What is a Thread?
PID
● A set of instructions
● Shares memory with parent process
● Has a ID
● Scheduled in the CPU
Single Threaded Process
PID
● Examples NGINX/Postgres
● Take advantage of multi-cores
● More memory but isolated
● Redis backup routine (COW)
Multi-Threaded
PID
ACK
Connection Establishment
SYN/ACK
ACK
Accept Queue
accept()
copy
PID
Problems with accepting connections
ACK
read()
Copy
PID
Send buffers
data
Send buffer
ACK
send()
Copy
PID
Problems with reading and sending
Single Listener/Multiple
Worker threads
husseinnasser
Idempotency
Resending the Request without affecting backend
What is idempotency?
● API /postcomment
● Takes comment and appends it to table
● What if the user/proxy retries it?
● You will have duplicate comments
● Very bad for financial systems
What is idempotency?
● GET is idempotent
● POST isn’t, but we can make it
● Browsers and proxies treat GET as idempotent
● Make sure your GETs are
husseinnasser
● Layer 4 vs Layer 7
● Load Balancer
● Layer 4 Load Balancer (pros and cons)
● Layer 7 Load Balancer (pros and cons)
Layer 7 Application Application
Backend server 1
Load Balancer
Backend server 2
Layer 4 Load Balancer
e ction
o nn
C
TCP N
SY CK
/A
Backend server 1
N
SY CK 44.1.1.3
A
TC
PC
onn
44.1.1.1 e ctio
S n
SY YN
N/A
L4 Load Balancer AC CK
K
44.1.1.2
Backend server 2
44.1.1.4
Layer 4 Load Balancer
Backend server 1
44.1.1.3
TCP Connection
SYN
SYN/ACK
44.1.1.1 ACK
L4 Load Balancer
44.1.1.2
44.1.1.1
L4 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 4 Load Balancer
2
.1.1.
44
S
RE
3
.1.1.
44
Backend server 1
44.1.1.2 RES 44.1.1.1 44.1.1.3
44.1.1.1
L4 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 4 Load Balancer
3
2
1
Backend server 1
44.1.1.3
HTTP GET /1
1 2 3
44.1.1.1
L4 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 4 Load Balancer
7
6
5
Backend server 1
44.1.1.3
HTTP GET /2
5 6 7
44.1.1.1
L4 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 4 Load Balancer
Backend server 1
44.1.1.3
1
44.1.1.1 2
1 2 3 3
L4 Load Balancer
(New connection) 44.1.1.2
HTTP GET /3
Backend server 2
44.1.1.4
Layer 4 Load Balancer (Pros and Cons)
Pros Cons
e ction
o nn
C
TCP N
SY CK
/A
Backend server 1
N
SY CK 44.1.1.3
A
TC
PC
onn
44.1.1.1 e ctio
S n
SY YN
N/A
L7 Load Balancer AC CK
K
44.1.1.2
Backend server 2
44.1.1.4
Layer 7 Load Balancer
Backend server 1
44.1.1.3
TCP Connection
SYN
SYN/ACK
44.1.1.1 ACK
L7 Load Balancer
44.1.1.2
44.1.1.1
L7 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 7 Load Balancer
2
.1.1.
44
S
RE
3
.1.1.
44
Backend server 1
44.1.1.2 RES 44.1.1.1 44.1.1.3
44.1.1.1
L7 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 7 Load Balancer
LB parsers and
understand the
3
segments
2
1
1 2 3
Backend server 1
44.1.1.3
HTTP GET /1
1 2 3
44.1.1.1
L7 Load Balancer
44.1.1.2
Backend server 2
44.1.1.4
Layer 7 Load Balancer
Backend server 1
44.1.1.3
HTTP GET /2
5 6 7
44.1.1.1 5
L7 Load Balancer 7
44.1.1.2
Backend server 2
44.1.1.4
Layer 7 Load Balancer
Backend server 1
44.1.1.3
44.1.1.1
1 2 3
L7 Load Balancer
(New connection) 44.1.1.2
HTTP GET /3
Backend server 2
44.1.1.4
Layer 7 Load Balancer (Pros and Cons)
Pros Cons
● Layer 4 vs Layer 7
● Load Balancer
● Layer 4 Load Balancer (pros and cons)
● Layer 7 Load Balancer (pros and cons)