Layer 4 vs Layer 7 Proxying In Details Explained with Examples

Поділитися
Вставка
  • Опубліковано 15 вер 2024

КОМЕНТАРІ • 51

  • @hanifmoha4355
    @hanifmoha4355 3 роки тому +26

    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 UA-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 2 роки тому

    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!

  • @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.

  • @nashaeshire6534
    @nashaeshire6534 Рік тому

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

  • @pajotrus
    @pajotrus 4 роки тому +4

    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 👍

  • @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

  • @animeshnath1087
    @animeshnath1087 2 роки тому +2

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

  • @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 😊🙏

  • @user-fy2mc7ip3f
    @user-fy2mc7ip3f 9 місяців тому

    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.

  • @abdelrhmanahmed1378
    @abdelrhmanahmed1378 2 роки тому

    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 ?

  • @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

  • @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.

  • @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.

  • @sarahbrown1230
    @sarahbrown1230 4 роки тому +2

    very good Hussein

    • @hnasr
      @hnasr  4 роки тому

      Sarah Brown thanks Sarah 😊

  • @ashutoshmishra2328
    @ashutoshmishra2328 4 роки тому

    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  4 роки тому

      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 4 роки тому +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.

  • @venkateshkumar4216
    @venkateshkumar4216 3 роки тому

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

  • @davidlira8853
    @davidlira8853 3 роки тому

    i love the "boop boop"s

  • @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

  • @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

  • @elmeroranchero
    @elmeroranchero 3 роки тому

    And I thought that L4 proxying was the lightest approach.

  • @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.

  • @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 4 роки тому

      @@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.

  • @catallergiccat
    @catallergiccat 4 роки тому +1

    Getting high .. don’t know why