Layer 4 vs Layer 7 Proxying In Details Explained with Examples

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 พ.ค. 2024
  • In this video I will explain the difference between layer 4 and layer 7 proxying in details. HAProxy & NGinx support this and I want to go behind the scenes of what exactly is going on in layer 7 proxying and layer 4 proxying.
    Chapters
    0:00 Intro
    1:00 Layer 7 Proxying
    12:55 Layer 4 Proxying
    🏭 Software Architecture Videos
    • Software Architecture
    💾 Database Engineering Videos
    • Database Engineering
    🛰 Network Engineering Videos
    • Network Engineering
    🏰 Load Balancing and Proxies Videos
    • Proxies
    🐘 Postgres Videos
    • PostgresSQL
    🚢Docker
    • Docker
    🧮 Programming Pattern Videos
    • Programming Patterns
    🛡 Web Security Videos
    • Web Security
    🦠 HTTP Videos
    • HTTP
    🐍 Python Videos
    • Python by Example
    🔆 Javascript Videos
    • Javascript by Example
    👾Discord Server / discord
    Support me on PayPal
    bit.ly/33ENps4
    Become a Patreon
    / hnasr
    Stay Awesome,
    Hussein
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 51

  • @hanifmoha4355
    @hanifmoha4355 3 ปีที่แล้ว +25

    Thanks for the video but I think you could have explained the differences of L4 vs L7 Load Balancing a bit more:
    Differences Between Layer 4 and Layer 7 Load Balancing
    Layer 4 load balancing operates at the intermediate transport layer, which deals with delivery of messages with no regard to the content of the messages. Transmission Control Protocol (TCP) is the Layer 4 protocol for Hypertext Transfer Protocol (HTTP) traffic on the Internet. Layer 4 load balancers simply forward network packets to and from the upstream server without inspecting the content of the packets. They can make limited routing decisions by inspecting the first few packets in the TCP stream.
    Layer 7 load balancing operates at the high‑level application layer, which deals with the actual content of each message. HTTP is the predominant Layer 7 protocol for website traffic on the Internet. Layer 7 load balancers route network traffic in a much more sophisticated way than Layer 4 load balancers, particularly applicable to TCP‑based traffic such as HTTP. A Layer 7 load balancer terminates the network traffic and reads the message within. It can make a load‑balancing decision based on the content of the message (the URL or cookie, for example). It then makes a new TCP connection to the selected upstream server (or reuses an existing one, by means of HTTP keepalives) and writes the request to the server.

    • @im_parth
      @im_parth 3 ปีที่แล้ว +1

      Great input !

  • @simonedeluca104
    @simonedeluca104 4 ปีที่แล้ว +16

    I'm following and watching your videos every time and i don't know why but you're following precisely my school's program 😂 you're magic!!!

    • @hnasr
      @hnasr  4 ปีที่แล้ว +3

      Haha I am glad my videos line up with your school schedule. All the best 😊

  • @nosh3019
    @nosh3019 3 ปีที่แล้ว +5

    I'm really glad that I found your videos through TH-cam recommendation. This is by far the best recommendation for me, your videos are very useful for me as a software engineer. Thank you and keep up the great work!

  • @sirjansingh310
    @sirjansingh310 ปีที่แล้ว

    This one video clears so many concepts! As software engineers, we work with so much high level stuff, knowing what is happening behind the scenes is really important. Your channel is great!

  • @nashaeshire6534
    @nashaeshire6534 11 หลายเดือนก่อน

    Much appreciate. Great work! You deserve more tumbs up! Maybe a video on Reverse Proxy vs APIGateway ?

  • @NastyWicked
    @NastyWicked 4 ปีที่แล้ว +4

    Love your energy man, really enjoyed binge watching for the last days.
    On the topic of proxying, I recently deployed a MITM proxy using nginx (openresty for lua oidc connector) in front of a openshift 3.11 cluster, reason being limiting entry to the platform and deployed workloads only to users authenticated at the proxy level, while retaining access to programmatic clients (jenkins pipelines). Not proud about the result since it is so hacky, but it gets the job done

    • @aymanpatel5862
      @aymanpatel5862 3 ปีที่แล้ว +1

      @NasyWicked Is there a write-up on this? I am curious how to set up such a infrastructure.

  • @nafasm
    @nafasm 4 ปีที่แล้ว +1

    Thank You, I tries to watch all your videos

    • @hnasr
      @hnasr  4 ปีที่แล้ว +1

      Nafas Muhammad thank you !! I really appreciate it, you support the channel by watching

  • @FUTETrends
    @FUTETrends 4 ปีที่แล้ว +1

    Thanks fr this topic also. Wonderdul as always Hussain.
    I had also Made a Video ant Reserve proxies but this one is way better

    • @hnasr
      @hnasr  4 ปีที่แล้ว +2

      FUTE thanks FUTE! Please keep making videos, some people will prefer your style over mine. If you enjoy making tech videos keep at it 😊🙏

  • @sagartyagi2450
    @sagartyagi2450 3 ปีที่แล้ว

    Thanks a lot for this info. However, I've one silly doubt, how does a reverse proxy differs from a proxy? Not the theory way, so basically in proxy, somebody else acts like the "client" for me, I sent request to him, and he hits the actual SERVER, and gets the response back right?
    But isn't that s exactly what reverse proxy is doing for me? I hit a reverse proxy, as if it was a server, but then it hit the actualy SERVER for me, got the reeponse and returned in to me. This is exactly what my PROXY did for me.
    Got it, I think the fundamental remains the same, it's just about the capabilities that we've allowed for reverse proxy and proxy.

  • @animeshnath1087
    @animeshnath1087 2 ปีที่แล้ว +2

    where were you all these years 😂 I am thinking to buy your video series plan like netflix

  • @user-fy2mc7ip3f
    @user-fy2mc7ip3f 5 หลายเดือนก่อน

    How does the layer 7 reverse proxy know which client to respond to, when it receives the response from server? I believe in layer 4, it is done by maintaining a NAT, and it is the same TCP connection.

  • @pajotrus
    @pajotrus 4 ปีที่แล้ว +3

    the coolest thing for me is that Layer 4 proxy is breaking the first TLS message and then passes the "Client Hello" to server1 as if the proxy was the client. and then server1 responds with the "Server Hello" and Layer 4 proxy just passes it back to the actual client. but that means that all the servers behind the proxy have to share the same certificate? so that means you can have only the same app behind the proxy? not like in Layer 7 when one subdomain may be handled by app1 in server1 and second subdomain in app2 in server2 :thinking:

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      What a fantastic observation 👍 absolutely correct. However you can still serve different certificates based on the SNI TLS extension which is in the client hello 👍

  • @abdelrhmanahmed1378
    @abdelrhmanahmed1378 ปีที่แล้ว

    in layer 4 ,we have one connection between the client and the load balancer and the server ? how is that happening , what about the acks > and what happen if the packet is lost between one node and the other ?

  • @palaniappanrm6277
    @palaniappanrm6277 4 ปีที่แล้ว

    Will the above L4 proxying work if the requests get routed between S1 and S2 when we use TLS 1.3? No right? I understand it will work with TLS 1.2 if both S1 and S2 serves the same certificate during the symmetric key formation.

    • @hnasr
      @hnasr  4 ปีที่แล้ว +2

      Palaniappan RM it should work with either. If we are doing TLS Passthrough 👍 the S1 / S2 will serve the same certificate

    • @palaniappanrm6277
      @palaniappanrm6277 4 ปีที่แล้ว

      @@hnasr okay, let's say during our initial HTTPS call, we created a symmetric key with S1 via TLS 1.3. Our next call goes to S2 encrypted with the key we formed with S1. Now, S2 can't decrypt it right? Am I missing something?

    • @JamesSmith-cm7sg
      @JamesSmith-cm7sg 3 ปีที่แล้ว +2

      @@palaniappanrm6277
      Two options I know of:
      TLS termination = the load balancer takes care of TLS and forwards requests unencrypted inside your network. Risky.
      TLS bridging = same but the load balancer does TLS internally with your servers. Decrypting and encrypting. Slower but safe.
      Also sticky sessions can be achieved in the case of pass through.

  • @ashutoshmishra2328
    @ashutoshmishra2328 3 ปีที่แล้ว

    Hey Hussein, thank u for this video.
    1.) What is the point behind L4 proxy reading TLS packets. it doesn't need to read because it is sending them to server like it was sending simple HTTP request packets right.?
    2.) In L4 reverse proxy, there will be two TCP connection (client- proxy, proxy-server) but one TLS Handshake(client-server) in case of HTTPS.

    • @hnasr
      @hnasr  3 ปีที่แล้ว

      Hey Ashurosh, your second question answers the first one. Layer 4 proxy reads TLS packet in order to terminate TLS so it decrypts the traffic and either send the traffic to the backend unencrypted or reencrypt it to the backend
      The alternative is TLS Passthrough which forwards everything to the backend

    • @ashutoshmishra2328
      @ashutoshmishra2328 3 ปีที่แล้ว +2

      @@hnasr ok, got it. thanks for the quick reply. you are amazing man.

    • @Max-zf5ot
      @Max-zf5ot 2 ปีที่แล้ว

      @@hnasr But this is not what you have explained in the video right? Video talks about proxy not having a key to decrypt the packets sent by either client or server. Video explains a case of TLS passthrough then?

    • @jivanmainali1742
      @jivanmainali1742 ปีที่แล้ว

      as per your first question, layer 4 is sticky connection so it needs to read few packets so it could forward traffic to same upstream server based on source ip.

  • @palaniappanrm6277
    @palaniappanrm6277 4 ปีที่แล้ว +1

    Proxy servers can't look at the data but it can check the Layer 2 details like MAC address and Layer 4 details like ports and IP address if it wishes to right?

    • @hnasr
      @hnasr  4 ปีที่แล้ว +2

      Palaniappan RM correct! Except when its. Layer 7 TLS termination proxy. Where it is acts like a man in the middle

    • @palaniappanrm6277
      @palaniappanrm6277 4 ปีที่แล้ว

      @@hnasr yes. L7 proxy can decrypt and see whole stuffs. Thank you.

  • @adityasethi9794
    @adityasethi9794 2 ปีที่แล้ว

    For L4 proxy, how does it get to know which server it has to send its request to if it does not read the data? When L4 proxy forms its own pkts it needs destination IP right. how will it know that IP?

    • @jivanmainali1742
      @jivanmainali1742 ปีที่แล้ว

      first few packets has those info like source ,dest ip etc which is differnet than content encryption

  • @mithiridiprasanth1002
    @mithiridiprasanth1002 3 ปีที่แล้ว +1

    How is HTTP a stateless protocol while TCP is a stateful protocol. Can you please explain @Hussein Nasser ?

    • @Varun2799
      @Varun2799 2 ปีที่แล้ว +2

      While the packets are being sent, the client and server keep track of which packets have successfully reached etc, this is what the TCP state is. Http has nothing to do with how things get transported and so is stateless

  • @palaniappanrm6277
    @palaniappanrm6277 4 ปีที่แล้ว

    I thought about a different perspective now. Does LB must be a TLS termination always? Because if doesn't and we created a symmetric key with one of the servers (S1) then if LB routes us to another server during next request, S2 can't decrypt what we send right?

    • @hnasr
      @hnasr  4 ปีที่แล้ว +1

      Palaniappan RM good question! So answer is no LB can also be TLS Passthrough where it just passes the TLS to the backend server and if that happens you are right the LB must always forward to the same backend. The certificate in this case is passed by the backend server.

    • @palaniappanrm6277
      @palaniappanrm6277 4 ปีที่แล้ว +1

      @@hnasr cool but the complication on LB to forward to same backend server is very difficult right? It should remember the requesting server in some way. Does it do that sticky session thing here?

    • @hnasr
      @hnasr  4 ปีที่แล้ว +2

      Not really. A sticky session its more like a layer 4 load balancing

    • @palaniappanrm6277
      @palaniappanrm6277 4 ปีที่แล้ว

      @@hnasr yeah. Layer 7 LB will do TLS termination. Layer 4 won't do and also does sticky session. Right?

    • @palaniappanrm6277
      @palaniappanrm6277 3 ปีที่แล้ว

      @@hnasr Saw your Nginx video now. So, Nginx L4 LB might do NAT to forward the request from same client to the same server or it can use something else too.

  • @animeshnath1087
    @animeshnath1087 2 ปีที่แล้ว

    one query - there is a single TCP connection between the client and the server in layer 4 proxy unlike 7, where there are two different TCP connections, the proxy starts the new connection to the server. This is regarding the whatsapp connections video, you mentioned only one IP can make 65k connections to the server, so for layer 7 proxy as the server sees a connection from the proxy it will always limit the no. of connections to 65k, right. Then how does, whatsapp handle this. They claim till 300k. Do they use layer 4 proxying? I have this query on my mind. I asked someone else, they explained like, the LB just handles the connection to the server. So everytime, the client wants to start a websocket, the LB delegates and transfers the first request to the dedicated server, and where the connection is established from the actual server to the client. 😕 Please reply

    • @hnasr
      @hnasr  2 ปีที่แล้ว +1

      The connection pairing is source ip - source port - destination ip - destination port
      Only If destination ip and destination port is fixed and the source ip is fixed then you only have 65k source port to play with
      In whatsapp case, the client is your phone and destination is whatsapp server (assume just one server) the destination ip and the destination port is fixed so source port and source ip is variable (any client can connect with their ip so it will be different)
      This means that the theoretical limit options are 4 billion IP addresses (assuming ipv4) times 65k source ports which is .. alot of connections. whatsapp was able to handle 3 million connections on one server on one port on one ip address after which their machine just melts.

    • @animeshnath1087
      @animeshnath1087 2 ปีที่แล้ว

      Thanks for the reply. There was another query, regarding the connection forming between the layer7 proxy to the WhatsApp server. The server sees only one source IP(the proxy), as it terminates the prev connection and starts a new connection to the server. What happens in this case. There would be a cap of only 65k connections

  • @sarahbrown1230
    @sarahbrown1230 4 ปีที่แล้ว +2

    very good Hussein

    • @hnasr
      @hnasr  4 ปีที่แล้ว

      Sarah Brown thanks Sarah 😊

  • @venkateshkumar4216
    @venkateshkumar4216 3 ปีที่แล้ว

    If its a tech stuff, check out Hussein's content. period!

  • @davidlira8853
    @davidlira8853 2 ปีที่แล้ว

    i love the "boop boop"s

  • @elmeroranchero
    @elmeroranchero 3 ปีที่แล้ว

    And I thought that L4 proxying was the lightest approach.

  • @catallergiccat
    @catallergiccat 4 ปีที่แล้ว +1

    Getting high .. don’t know why