DNS and Essential Application Protocols
DNS: The Internet's Phonebook
The Domain Name System (DNS) translates human-readable names (e.g., google.com) into machine-readable IP addresses (e.g., 142.250.190.46).
The Hierarchical Resolution Process
- Local Cache: Browser check $\rightarrow$ OS check $\rightarrow$ Router check.
- Recursive Resolver (ISP): If not found, your ISP’s DNS server takes over.
- Root Nameservers (.): Provides the address of the Top-Level Domain (TLD) server (e.g., for
.com). - TLD Nameservers: Provides the address of the Authoritative Nameserver for the specific domain.
- Authoritative Nameserver: Provides the final IP address.
Common DNS Record Types
| Type | Function | Example |
|---|---|---|
| A | Hostname to IPv4 | example.com → 93.184.216.34 |
| AAAA | Hostname to IPv6 | example.com → 2606:2800:220:1:: |
| CNAME | Alias | www.example.com → example.com |
| MX | Mail Server | example.com → mail.google.com |
| TXT | Information | Verification codes, SPF records |
WebSocket: Full-Duplex Real-Time
Unlike HTTP, which is strictly request-response, WebSocket allows for a continuous, bidirectional flow of data.
- Handshake: Starts as a normal HTTP request with an
Upgrade: websocketheader. - Persistence: Once established, the TCP connection stays open.
- Overhead: Minimal. While HTTP headers can be hundreds of bytes, a WebSocket frame header is as small as 2 bytes.
Supporting Infrastructure Protocols
DHCP (Dynamic Host Configuration Protocol)
Automatically assigns network parameters (IP, Subnet, Gateway, DNS) to devices when they join a network.
- Process: Discover $\rightarrow$ Offer $\rightarrow$ Request $\rightarrow$ Acknowledgment (DORA).
SMTP / IMAP / POP3 (Email)
- SMTP: Used to send mail between servers.
- IMAP: Used to read mail. Keeps mail on the server, allowing sync across multiple devices.
- POP3: Used to download mail. Traditionally deletes mail from the server after download.
Engineering Insights
Why DNS uses UDP
Speed. A DNS query is a single packet, and the response is usually a single packet. Using TCP’s 3-way handshake would triple the latency for every website lookup. However, if a response is too large (>512 bytes), DNS automatically falls back to TCP to ensure data integrity.
DNS hijacking and DNS-over-HTTPS (DoH)
Traditional DNS is sent in plain text. This allows ISPs or attackers to see what websites you are visiting (and potentially redirect you to fake ones). DoH encrypts DNS queries within standard HTTPS traffic, hiding your browsing habits and preventing censorship/tampering at the network level.
The "Polling" Problem vs. WebSocket
Before WebSockets, real-time apps used "Long Polling"—the client would keep a request open until the server had data. This was incredibly resource-heavy for servers. WebSockets replaced this with a single persistent socket, drastically reducing server load and latency for things like stock tickers and chat apps.