LOADING

DNS and Load Balancers Explained: How the Web Handles Traffic at Scale

DNS and Load Balancers Explained: How the Web Handles Traffic at Scale

DNS and Load Balancers Explained: How the Web Handles Traffic at Scale

Software Development

13 min

2025-09-09

DNS and Load Balancers are at the heart of how the internet works. Every time you type a URL, watch a YouTube video, or order something online, these systems make sure your request goes to the right server fast, secure, and reliable. Understanding them is essential for developers, architects, and IT professionals.

How a URL Works in Your Browser

When you type https://google.com into your browser, a lot happens behind the scenes:

  1. URL Parsing: The browser splits the URL into parts (protocol, domain, path, query).
  2. DNS Resolution: The domain (google.com) is translated into an IP address using DNS servers.
  3. Connection: The browser opens a TCP connection (and TLS for HTTPS) with the server at that IP.
  4. HTTP Request: The browser sends a request with headers (e.g., "give me the homepage").
  5. Server Processing: The server prepares the response (HTML, JSON, images, etc.).
  6. HTTP Response: The server sends the data back with a status code (200, 404, etc.).
  7. Rendering: The browser renders the page and may make more requests for CSS, JS, or images.

This flow explains why DNS and load balancers are so important they determine which server answers your request.

What is DNS?

DNS (Domain Name System) works like the phonebook of the internet. It translates human friendly names like amazon.com into IP addresses like 192.168.1.1 that computers use to communicate.

Key DNS Concepts

  • Top Level Domain (TLD): The ending of a domain (.com, .org, .net, .bd).
  • SOA (Start of Authority): Holds important details about the domain, such as the primary DNS server and refresh timing.
  • RNS (Root Name Server): The highest level servers that guide queries down the chain to the correct DNS server.
  • DNS Records:
    • A record: Maps a domain to an IPv4 address.
    • AAAA record: Maps a domain to an IPv6 address.
    • CNAME: Alias pointing one domain to another.
    • MX: Defines mail servers for email routing.

How Clients Get a Response from the Server

When your browser queries DNS, the response flows like this:

Client >> Local Resolver >> Root Server >> TLD Server >> Authoritative DNS >> IP Address Response

Once the IP is known, the browser connects to the server and retrieves the content.

What is a Load Balancer?

A Load Balancer is like a traffic police officer for servers. It distributes incoming traffic across multiple servers so that no single server is overwhelmed.

Purposes of Load Balancers

  • Prevent Overload: Spread requests across servers.
  • High Availability: If one server fails, redirect to a healthy one.
  • Performance: Route to the least busy or closest server.
  • Scalability: Easily add/remove servers as demand changes.

Types of Load Balancers

  • Layer 4 (Transport Layer): Routes based on IP and port. Fast but basic.
  • Layer 7 (Application Layer): Routes based on content (e.g., send images to one server, API requests to another).

DNS Load Balancer

A DNS Load Balancer distributes requests at the DNS level instead of using a separate device. When a client asks DNS for a domain, it can return different IPs each time, spreading traffic across servers.

Round Robin Approach

The simplest DNS load balancing technique is Round Robin. Example:

myapp.com >> 192.168.1.10
myapp.com >> 192.168.1.11
myapp.com >> 192.168.1.12

The DNS server rotates through these IPs for each request, so traffic is shared evenly.

Pros

  • Very easy to set up.
  • No extra hardware required.

Cons

  • No awareness of server health (may send users to a failed server).
  • DNS caching can cause uneven distribution.
  • Not ideal for real time load balancing.

Firewall Basics

A Firewall acts as a security guard, controlling traffic in and out of a network.

Types of Firewalls

  • Packet Filtering Firewall: Filters based on IP, port, or protocol.
  • Stateful Inspection Firewall: Tracks active connections and makes smarter decisions.
  • Application Layer Firewall: Inspects application traffic (e.g., HTTP, FTP).
  • Next Gen Firewall (NGFW): Combines intrusion detection, malware scanning, and deep inspection.

How Firewalls Work with Ports

Every service runs on a port number. Examples:

  • HTTP >> 80
  • HTTPS >> 443
  • FTP >> 21
  • SSH >> 22

A firewall can block or allow traffic based on these ports.

Example: Putting it All Together

Imagine you visit shop.example.com:

  1. The browser parses the URL.
  2. DNS resolves shop.example.com to one of several server IPs (using round robin).
  3. A load balancer routes your request to the healthiest and least busy server.
  4. The firewall checks and allows the request on port 443 (HTTPS).
  5. The server processes your request and responds with the website content.

Conclusion

From typing a URL to receiving a webpage, DNS and load balancers play a crucial role in directing traffic and keeping the internet reliable. Firewalls then add a layer of security to ensure only safe traffic gets through.

Call to Action

Next time you visit your favorite website, think about the chain of systems making it possible. As a hands on exercise, try setting up a local DNS round robin or an open source load balancer like HAProxy or Nginx to see traffic distribution in action. This will solidify your understanding of networking in real world systems.

Tags :

dns

load balancer

networking

system design

firewall

distributed systems

Thanks For Reading...

0%