Layer 4 V.S Layer 7 load balancing

Layer 4 V.S Layer 7 load balancing

What is Load Balancing ?

load balancing is a mechanism or strategy applied when you have an API or back end service that heavily used in the system so you can run multiple instances form that component and on top of them there is another service that distribute request among of them.

Load Balancing Algorithms

Most popular two load balancing algorithms are IP Hashing and Round Robin :

IP Hashing

Here the load balancer hashes the request and match the hash with one of services , whenever this request came again it will stick with same service

No alt text provided for this image


Round Robin

Here the requests distributed among service equally as image below

No alt text provided for this image


So, What is Layer 4 and Layer 7 ?

regarding to OSI (open system interconnection) Model the network model has 7 layers described as below image :

No alt text provided for this image

So Layer 4 and Layer 7 we are talking about is transport layer and application layer in OSI model , let's talk about each one .

Layer 7 : Application Layer

Here your load balancing service will receive the whole request from the client and decide which service should receive this request and forward the request to it , This means that the load balancing service has full awareness of what is received and what is sent , Therefore as benefit from this you can enable caching for responses , Whenever got this request before it's not needed to forwarded the request to service just pull up the response from the cache and return it to client , also you can define here some URLs you don't want some users to access them so load balancer can act as security layer to prevent this access ,But it also has a security wise if load balancer service hacked , Hacker can now know a lot of data about your system

Layer 4 : Transport Layer

Here as OSI model describers the data packet is surrounded by source and destination addresses (IP address and port) as below image

No alt text provided for this image

So when you enable layer 4 load balancing , Your load balancer service will not wait until gather all packets and recognize the request , It will directly open a connection with one of your back end services and send the packets to it , Therefore the load balancer has no awareness of what happen here it just act as transporter only , So you can not get benefit of caching or prevent some URLs from being processed in load balancing layer , but it also enhance the security of load balancer service as it's now don't have any information about your system and also it faster in packets transporting


No alt text provided for this image

for better explanation you can watch this video


要查看或添加评论,请登录

Sameh Muhammed的更多文章

  • The Idea Behind Quarkus

    The Idea Behind Quarkus

    Introduction If you are a Java developer and using a Spring Boot framework, you can see that a lot of videos and…

    2 条评论
  • Legacy Code: I can't get this class into test suite

    Legacy Code: I can't get this class into test suite

    ??????? ?? ?????? ???? ??? ??????? ?? ???????? ?????? ???? ???? ???????? ????? ????? feature ????? ?? ?????? ?????? ???…

  • Legacy Code: How do I add a feature

    Legacy Code: How do I add a feature

    ??????? ?? ?????? ?????? ??????? ?? ????? ??? ????????? ??? ????? ????? ??? ???????? ???? ??????? ?? ??? ???? ????? ???…

  • Legacy Code: I don't have much time and I need the change quickly

    Legacy Code: I don't have much time and I need the change quickly

    ??????? ??????? ?? ?????? ???? ??? ?? ?? Seam ??? ??? ???? ?? ?? ??????? ?? ?? legacy code ?? ?? unit tests. ?????? ???…

    4 条评论
  • Legacy Code: The Seam & Feedback Loop

    Legacy Code: The Seam & Feedback Loop

    ??????? ?? ??????? ??????? ??????? ?? ????? ??????? ?? ?????? ??? ?????? ????????? ???? ???? ???? ??? ?????? ??? ??????…

  • Legacy Code: Mechanics of change

    Legacy Code: Mechanics of change

    ??????? ?? ???? ??? ????? ????? ????? ????? ?? ??? ???????? ???? ??????? ?? ???? ????? ???? ????? ?? ?????? ??? ?? ????…

    1 条评论
  • Service Design Best Practices - Part II

    Service Design Best Practices - Part II

    Introduction By now most softwares separating the server side logic from user interface logic by developing a back end…

  • Service Design Best Practices - Part I

    Service Design Best Practices - Part I

    Introduction By now most softwares separating the server side logic from user interface logic by developing a back end…

  • ????? ????? : ????? ??????? ?????? ????

    ????? ????? : ????? ??????? ?????? ????

    ??????? ?? ????? ???? ??? ??? ??????? ??? ????? ??????? ????????? ?? ????? ??? ??? ?? ??????? ???? ?? ???? ???? ???…

  • Object-Oriented Programming : comprehensive guide

    Object-Oriented Programming : comprehensive guide

    Motivation It's very common to be asked about OOP concepts while you are still fresh graduate or junior developer, but…

社区洞察

其他会员也浏览了