Load balancing in Layer 4 vs Layer 7 with HAPROXY Examples
Hussein Nasser
@hnasrAbout
Join me as we discuss various software engineering topics with examples and add fun elements to them. We always try to learn by example here in this educational Youtube channel which we believe is the right way to learn. I love Software engineering (especially the backend) and I strive to be a better software engineer every day. Join me on this journey and let us learn together. All opinions, suggestions, and tips I provide in all of this channel's content are my own. Information provided is for educational purposes only. Consider becoming a member to support the channel https://www.youtube.com/channel/UC_ML5xP23TOWKUcc-oAE_Eg/join Check out my courses https://courses.husseinnasser.com Stay awesome! Hussein Nasser, http://www.husseinnasser.com Feel free to shoot me an email [email protected] twitter: @hnasr
Latest Posts
Video Description
💻 More software engineering videos https://www.youtube.com/playlist?list=PLQnljOFTspQXOkIpdwjsMlVqkIffdqZ2K Load balancing is process of balancing incoming requests to multiple machines, processes or services. In this video we will explain two types of load balancers, layer 4 and layer 7. Chapters 0:00 Intro 6:00 L4 Load balancer 9:10 L4 Load Balancer Pros and Cons 16:18 Example L4 Load Balancer with HAPROXY 22:30 L7 Load Balancer 27:00 L7 Pros and Cons 31:00 Example L7 Load Balancer with HAPROXY 37:00 Summary Layer 4 (4/3) Take content forwards it based on basic rules, it knows ip and port and perhaps latency of the target service. Layer 4 - haproxy, NLB Pros - great for simple packet-level load balancing - Fast and efficient doesn’t look at the data - More secure as it cant really look at your packets. So if it was compromised no one can look - Uses NAT - One connection between client and server NATed Cons - Cant do smart load balancing based on the content, such as switch request based on requested media type - Cant do microservices with this type - Has to be sticky as it is a stateful protocol (all segments) Layer 7 (Nginx , haproxy) This type of proxy actually looks at the content and have more context, it knows you are visiting the /users resources so it may forward it to a different server. Essential and Great for microservices , it knows the content is video:image etc.. it can also cache.. we cant really do caching on layer 4 because we have no clue whats in the packets. But expensive because it has to decrypt and look and compute Layer 4 - haproxy, nlb - great for simple packet-level load balancing - fast and efficient doesn’t look at the data - More secure as it cant really look at your packets. So id it was compromised no one can look - Uses NAT - One connection between client and server NATed Layer 7 - examples nginx - Smart routing based on the url (microservices) flexible - Provide caching - Expensive need to decrypt - Secuirty, you have to share your certificate with the load balancers. Id compromised attacker has access to all your data. - Proxy creates multiple connection (client to proxy/proxy to server) Image thumbnails https://www.haproxy.com Support me on PayPal https://bit.ly/33ENps4 Become A Patron https://www.patreon.com/join/hnasr? Stay Awesome! Hussein
You May Also Like
Essential Flight Sim Tools
AI-recommended products based on this video

Logitech K400 Plus Wireless Touch TV Keyboard With Easy Media Control and Built-in Touchpad, HTPC Keyboard for PC-connected TV, Windows, Android, Chrome OS, Laptop, Tablet - Black

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

Razer DeathAdder Essential Gaming Mouse: 6400 DPI Optical Sensor - 5 Programmable Buttons - Mechanical Switches - Rubber Side Grips - Classic Black

Razer BlackShark V2 X Gaming Headset: 50mm Drivers - Cardioid Mic - Memory Foam Cushion - Lightweight- Comfortable, Noise Isolating Earcups - for PC, PS4, PS5, Switch - 3.5mm Audio Jack - Black ECOLOGO

230W Charger Compatible with Razer Blade 14” 15” 16" 17” (2025-2018) RZ09 RTX-3060/3070/3080/4060/4070 Gaming Laptop RC30-0530 RC30-0238 RC30-0248 Replacement Power Adapter

Logitech G435 Lightspeed and Bluetooth Wireless Gaming Headset - Lightweight Over-Ear Headphones, Built-in mics, 18h Battery, Compatible with Dolby Atmos, PC, Mobile - Black

Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

ASUS ROG Strix G16 Gaming Laptop, GeForce RTX 5070 Ti 12GB GDDR7, AMD Ryzen 9 8940HX, 64GB DDR5, 2TB SSD, Backlit Keyboard, Wi-Fi 6E, 16" WUXGA 165Hz Display, Win 11, Gray, 1TB Docking Station Set

ASUS ROG Strix G16 (2024) Gaming Laptop, 16” 16:10 FHD+ 165Hz, GeForce RTX 4060, Intel Core i7-13650HX, 16GB DDR5, 1TB PCIe SSD, Wi-Fi 6E, Windows 11, G614JV-AS71-CA

Asus ROG STRIX Z890-A GAMING WIFI Z890 LGA 1851 ATX motherboard, Intel® Core™ Ultra Series 2 Ready, Advanced AI PC-ready, 16+2+1+2 stages, DDR5, WiFi 7, 2.5G, 5x M.2, Thunderbolt™ 4, USB Type-C, AI OC

Asus ROG Strix B850-A Gaming WiFi AMD AM5 B850 ATX Motherboard 14+2+2 Power Stages, DDR5 AEMP, 2.5G LAN, WiFi 7 with Q-Antenna, 4X M.2, PCIe® 5.0, USB 20Gbps Type-C, AI Networking II, ASUS AI Advisor

Entry Door Knob with Lock and Keys for Bedroom/Bathroom, Interior/Exterior Door Handles, Indoor/Outdoor Privacy Door Knob, Main/Front Door Handle Lock, Home Security, Poignee Porte Interieur/Exterieur

2025 Deep Cat Extra Large High Sides, 21. 45 x 16. 14 x 10. 43 Inches Low Entry Cat Litter Tray Litter Open Splashing Pan Easy Clean for Small Medium (Green) (Yellow, 49x35. 5x13cm)

eufy Security 5-Piece Home Alarm Kit, Home Security System, Keypad, Motion Sensor, 2 Entry Sensors, Home Alarm System, Control from The App, Links with eufyCam

Birosnsy Digital Camera 4K 50MP with 32GB SD Card 2.88" IPS LCD Screen Auto Focus 16xDigital 9 Shooting Modes Zoom Entry Beginner 0.23LB HD Portable Mini Camera(Black, Batteries X2, Charging Head X1)




















