- DNS (Domain Name System) turns names like
i.instagram.cominto IP addresses. It is a globally distributed, hierarchical, heavily cached database. - A recursive resolver (your ISP's, or 8.8.8.8 / 1.1.1.1) walks the hierarchy — root → TLD (.com) → authoritative name servers — and caches every answer for its TTL.
- Know the record types: A (IPv4), AAAA (IPv6), CNAME (alias), NS (delegation), MX (mail), TXT (verification/policy), SOA (zone metadata).
- DNS is also a traffic-steering tool: GeoDNS/latency routing sends users to nearby PoPs, weighted routing shifts traffic gradually, health-checked failover removes dead regions. Anycast makes DNS servers fast and DDoS-resistant.
- TTL is a trade-off: short TTL = fast failover but more queries; long TTL = resilience and speed but slow changes.
- DNS is a classic single point of failure: the 2016 Dyn DDoS took down major sites, and in October 2021 a BGP withdrawal made Meta's DNS servers unreachable, taking Facebook, Instagram and WhatsApp offline for about six hours.
1. The problem: why do we need DNS?
Computers route packets using IP addresses like 157.240.22.174 or 2a03:2880:f12f:83:face:b00c:0:25de. Humans and apps use names like instagram.com. Something has to translate — and it has to do so for billions of devices, millions of times per second, in a few milliseconds, without one central server that could fail or be overwhelmed.
Names also give system designers a crucial layer of indirection. If the Instagram app had a hard-coded IP address baked into it:
- Instagram could never move servers, add data centers or change cloud providers without breaking every installed app.
- Every user worldwide would hit the same IP, no matter whether they were in Mumbai or Montreal — no way to send them to a nearby edge.
- If that IP's data center failed, there'd be no way to send users somewhere else.
With DNS, the app asks "where is i.instagram.com right now, for me?" and Instagram's name servers can answer differently depending on the user's location, server health and load. DNS is therefore the very first hop in Instagram's architecture diagram and the first lever for global traffic management.
2. The DNS hierarchy
2.1 Anatomy of a name
Read a domain name right to left. The fully qualified name i.instagram.com. has an invisible trailing dot representing the root:
i . instagram . com . (root)
│ │ │ └── root zone: managed by IANA, served by root servers
│ │ └─────────── top-level domain (TLD): .com, run by Verisign
│ └─────────────────────────── second-level domain: instagram.com, owned by Meta
└──────────────────────────────────── subdomain / hostname inside Meta's zone
Each level is responsible only for delegating to the next. The root doesn't know Instagram's IP; it only knows who runs .com. The .com servers don't know it either; they know which name servers are authoritative for instagram.com. A zone is the slice of the namespace one organisation administers, and NS records are the signposts that delegate a sub-zone to other servers.
2.2 The three kinds of servers in the hierarchy
🌳 Root servers
13 logical root server names (a.root-servers.net … m.root-servers.net), run by 12 independent organisations, but replicated via anycast to well over 1,000 physical sites worldwide. They only answer "who runs this TLD?".
🏷️ TLD servers
Serve one top-level domain: generic (.com, .org, .app) or country-code (.in, .uk). They hold NS records for every registered domain under them — hundreds of millions for .com.
📖 Authoritative servers
Hold the actual records for a zone (A, AAAA, CNAME, MX…). Run by the domain owner or a managed DNS provider. For big platforms, they also run the routing logic (GeoDNS, health checks).
You don't talk to these servers directly from your phone. That's the job of a resolver.
3. Resolvers and the full resolution walkthrough
3.1 Stub resolvers vs recursive resolvers
- The stub resolver is the tiny DNS client in your phone's OS. It doesn't walk the hierarchy; it sends one question ("A record for
i.instagram.com?") to a configured recursive resolver and waits for the final answer. This is a recursive query: "please do all the work for me". - The recursive resolver (also called a caching or full-service resolver) does the walking. It's typically run by your ISP or mobile carrier, or a public service such as Google Public DNS (8.8.8.8), Cloudflare (1.1.1.1) or Quad9 (9.9.9.9), or by your company. It sends iterative queries to root, TLD and authoritative servers — each of which answers with either the final answer or a referral ("I don't know, ask these servers") — and caches everything it learns.
3.2 Full resolution, step by step (cold caches)
Phone app/OS Recursive resolver Root server .com TLD server instagram.com auth NS
(stub resolver) (ISP / 8.8.8.8)
| | | | |
(1) | A? i.instagram.com | | | |
|--------------------> | cache miss | | |
| | (2) A? i.instagram.com| | |
| |---------------------> | | |
| | (3) referral: ".com is served by a.gtld-servers.net …" (NS + glue IPs)|
| | <-------------------- | | |
| | (4) A? i.instagram.com | |
| |------------------------------------------>| |
| | (5) referral: "instagram.com NS = Meta's name servers" (+ glue) |
| | <------------------------------------------| |
| | (6) A? i.instagram.com |
| |----------------------------------------------------------------->|
| | (7) answer: i.instagram.com A 157.240.x.x TTL 60 |
| | (chosen for THIS resolver's location / client subnet) |
| | <-----------------------------------------------------------------|
| | (8) cache: root/TLD referrals for days, the A record for 60 s |
(9) | <-- 157.240.x.x ---- | |
| OS + app cache it; now open a connection (TCP/TLS or QUIC) to 157.240.x.x |
- The app calls the OS resolver (e.g.
getaddrinfo), usually asking for both A (IPv4) and AAAA (IPv6) records. The OS checks its own cache first. - On a miss, the stub sends a UDP packet (port 53) — or an encrypted DoH/DoT query — to the recursive resolver.
- The resolver checks its cache. It almost always already knows the root and
.comservers (their NS records have TTLs of days), so steps 2–5 are usually skipped. It starts at the closest ancestor it knows. - The root answers with a referral: NS records for
.com, plus glue records (the IPs of those name servers, needed to avoid a chicken-and-egg lookup). - The
.comTLD server answers with another referral: the NS records forinstagram.com(Meta's own name servers) and their glue. - Meta's authoritative server answers with the final record. This is where the intelligence lives: the IP returned depends on where the query appears to come from and which PoPs/regions are healthy.
- The resolver caches the answer for its TTL and returns it to the phone; the OS and the app may cache it too.
- Only now can the app start the TCP/TLS or QUIC handshake (see Networking basics).
Timing: a fully cold lookup needs up to four network round trips from the resolver (root, TLD, authoritative, plus the phone ⇄ resolver hop) — easily 100–300 ms if any of those servers is far away. A warm lookup answered from the resolver's cache costs one phone ⇄ resolver round trip (5–50 ms; more on a 3G radio), and an OS/app cache hit costs ~0 ms. Because root and TLD answers are cached for days and popular names like i.instagram.com are queried constantly, most lookups at big ISPs are cache hits.
DNS mostly uses UDP because a query and answer each fit in a single packet — no handshake needed, which keeps lookups to one round trip. Responses that are too large (e.g. big DNSSEC answers) fall back to TCP; EDNS(0) extensions allow larger UDP payloads and extra options such as Client Subnet.
4. Caching layers and TTLs
DNS works at planetary scale only because of caching. Every answer carries a TTL (time to live) in seconds, set by the zone owner: "you may reuse this answer for this long without asking again". Caches exist at several layers:
| Layer | Who | Notes |
|---|---|---|
| App / browser cache | Chrome's host cache, the app's HTTP library (OkHttp, Cronet) | Often caps TTLs at about a minute; some apps pre-resolve hostnames at launch |
| OS cache | iOS/Android/Windows/macOS resolver, systemd-resolved | Shared by all apps on the device |
| Home router / CPE | Small forwarding cache in your Wi-Fi router | Optional; sometimes buggy (ignores TTLs) |
| Recursive resolver | ISP, carrier, Google/Cloudflare/Quad9, corporate | The big one — shared by millions of users, so popular names are almost always hot |
| Negative cache | Resolvers | "This name does NOT exist" (NXDOMAIN) is cached too, for a duration derived from the zone's SOA record |
Each cache counts the TTL down from when it received the answer. If the authoritative TTL is 300 s and the resolver got the answer 200 s ago, it hands your phone the record with TTL 100.
4.1 How much load does caching save?
Assume 500M daily users, each device resolving the API hostname 20×/day (app opens, network changes)
device-level lookups = 10 billion/day ≈ 116,000 per second
Assume those devices sit behind ~100,000 recursive resolver instances and the TTL is 60 s
worst case at the authoritative = 100,000 resolvers × 1 query / 60 s ≈ 1,700 QPS
→ resolver caching cuts authoritative load by ~70× even with a short 60 s TTL.
With TTL = 3600 s it would be ~28 QPS — but changes would take up to an hour to propagate.
5. Record types
A zone is a list of resource records: name, TTL, class (almost always IN), type, value. The ones every engineer should know:
| Type | Purpose | Example | Notes |
|---|---|---|---|
| A | Name → IPv4 address | i.instagram.com. 60 IN A 203.0.113.10 | Multiple A records = several IPs (client picks one); the core record type |
| AAAA | Name → IPv6 address | i.instagram.com. 60 IN AAAA 2001:db8::10 | "Quad-A". Clients race IPv6 and IPv4 ("Happy Eyeballs") and use whichever connects first |
| CNAME | Alias: "this name is really that name" | www.example.com. 300 IN CNAME example.cdnprovider.net. | Resolver follows the chain. A CNAME can't coexist with other records at the same name, so it can't be used at the zone apex (example.com itself) — providers offer ALIAS/ANAME "flattening" instead. Each hop may cost an extra lookup |
| NS | Which servers are authoritative for a zone (delegation) | instagram.com. 172800 IN NS a.ns.example.net. | Lives in the parent (TLD) and in the zone itself; long TTLs (often 2 days) |
| MX | Mail servers for the domain, with priority | example.com. 3600 IN MX 10 mx1.example.com. | Lower number = preferred. Only used for email |
| TXT | Arbitrary text | example.com. 300 IN TXT "v=spf1 include:_spf.example.net -all" | Domain ownership verification, email security (SPF, DKIM, DMARC), other policies |
| SOA | Start of Authority: zone metadata | example.com. IN SOA ns1.example.com. dns-admin.example.com. 2026102301 7200 900 1209600 300 | Primary server, admin contact, serial number (version of the zone), refresh/retry/expire timers for secondaries, and the negative-caching TTL |
| PTR | Reverse lookup: IP → name | 10.113.0.203.in-addr.arpa. PTR edge1.example.com. | Used by mail servers, logging, traceroute |
| SRV | Service location: host + port + priority/weight | _sip._tcp.example.com. SRV 10 60 5060 sip1.example.com. | Used in some service-discovery setups (e.g. Kubernetes, Consul) |
| CAA | Which CAs may issue certificates for the domain | example.com. CAA 0 issue "letsencrypt.org" | Security hardening for TLS certificates |
Here is a tiny, illustrative zone (documentation IP ranges, not Instagram's real records):
$ORIGIN example-photos.com.
@ 3600 IN SOA ns1.example-photos.com. hostmaster.example-photos.com. (
2026102301 ; serial (bump on every change)
7200 ; refresh: secondaries check every 2 h
900 ; retry
1209600 ; expire: secondaries give up after 14 days
300 ) ; negative-cache TTL
@ 172800 IN NS ns1.example-photos.com.
@ 172800 IN NS ns2.other-provider.net. ; second provider = no single point of failure
api 60 IN A 203.0.113.10 ; short TTL: steered dynamically
api 60 IN AAAA 2001:db8::10
www 300 IN CNAME web.example-photos.com.
media 300 IN CNAME photos.cdn-provider.example. ; hand media off to a CDN
@ 3600 IN MX 10 mail.example-photos.com.
@ 300 IN TXT "v=spf1 -all"
Use dig to explore real DNS: dig i.instagram.com A, dig +trace instagram.com (shows the root → TLD → authoritative walk), dig instagram.com NS.
6. DNS as a traffic-steering tool
A simple authoritative server returns the same static records to everyone. A smart authoritative server (sometimes called a Global Server Load Balancer, GSLB) computes the answer per query. This is the first layer of global load balancing in Instagram's architecture (see Load balancing).
6.1 GeoDNS and latency-based routing
- Geolocation routing maps the query's source IP to a country/region using a GeoIP database and returns the PoP or region assigned to that area. Also used for data residency rules (e.g. keep EU users on EU infrastructure — see Multi-region).
- Latency-based routing goes further: the provider continuously measures real latency from networks to each PoP (from probes or from real-user measurements in the app/browser) and returns the endpoint with the lowest measured latency for that network — which isn't always the geographically closest one.
The catch: the authoritative server sees the resolver's IP, not the user's. If a user in Chennai uses a public resolver whose nearest instance is in Singapore, a naive GeoDNS might send them to a Singapore PoP. The fix is EDNS Client Subnet (ECS): the resolver forwards a truncated prefix of the client's IP (e.g. a /24) so the authoritative server can geolocate the actual user. (Some privacy-focused resolvers deliberately don't send ECS.) Anycast resolvers with instances in many cities also mitigate the problem.
6.2 Weighted routing
Return different answers in configured proportions: 90% of responses point at the old cluster, 10% at the new one. Uses: canary releases of a new region or load balancer, gradual migrations between data centers or clouds, and balancing between regions of different capacity. Because resolvers cache answers and share them among many users, weights are approximate — one resolver serving 1M users who got the "10%" answer moves a big chunk of traffic at once.
6.3 DNS failover with health checks
The DNS provider continuously health-checks each endpoint (e.g. an HTTPS request to /healthz every 10 s from several vantage points). If a region fails N consecutive checks, it's removed from answers; traffic shifts to the remaining healthy endpoints. Variants: active-passive (return the primary unless it's unhealthy, then the secondary) and active-active (return all healthy endpoints).
worst-case failover time ≈ detection time + TTL + client stickiness
detection: 3 failed checks × 10 s = 30 s
TTL = 60 s
clients that keep existing connections open = until those connections fail
→ ~1.5 minutes for most users, longer for stragglers that ignore TTLs
That's why DNS failover is good for region-level disasters but too slow and coarse for individual server failures — those are handled by load balancer health checks in seconds.
| Routing policy | Answer depends on | Use it for | Watch out for |
|---|---|---|---|
| Simple / round-robin | Nothing — return all IPs (often rotated) | Spreading load across a few equal servers | No health awareness; clients may stick to the first IP |
| Geolocation | Client/resolver location | Nearest PoP, data residency, localized content | Resolver location ≠ user location (use ECS) |
| Latency-based | Measured network latency | Lowest-latency region for each network | Needs good measurement data |
| Weighted | Configured percentages | Canary, migration, capacity balancing | Coarse because resolvers aggregate many users |
| Failover | Health checks | Region / data-center disaster recovery | Bounded by TTL and client caching |
| Multi-value | Health — returns several healthy IPs | Client-side retry across endpoints | Clients must actually try alternatives |
7. Anycast DNS
Anycast means announcing the same IP address from many locations via BGP. Internet routing then delivers each packet to the "closest" location in network terms. (Contrast with unicast, where one IP = one machine.) DNS is the perfect anycast workload: a query and its answer are each a single UDP packet, so there is no long-lived connection that could break if routing shifts mid-conversation.
- Speed: users automatically reach the nearest DNS server instance — all 13 root server names are anycast, and so are major public resolvers (8.8.8.8, 1.1.1.1) and big authoritative providers.
- Resilience: if one site fails, it stops announcing the route and traffic flows to the next-closest site — no TTLs involved.
- DDoS absorption: an attack is split across every site instead of concentrating on one; each site only absorbs the attack traffic originating near it.
GeoDNS and anycast are often combined: anycast gets the DNS query to a nearby DNS server, and GeoDNS logic in that server picks a nearby PoP for the actual traffic. Anycast is also used directly for HTTP edges and L4 load balancers — see Load balancing and CDN.
8. TTL trade-offs
| Short TTL (30–300 s) | Long TTL (1 h – 2 days) | |
|---|---|---|
| Failover / change speed | Fast — minutes | Slow — hours |
| Traffic steering precision | Can react to load and health continuously | Coarse, static |
| Query volume on authoritative servers | High | Low |
| User latency | More cache misses → more lookups (each 10–100+ ms) | Almost always cached |
| Resilience if your DNS is down | Poor — caches empty within minutes | Good — cached answers keep working for hours |
| Typical use | Dynamically steered endpoints: API and CDN hostnames, GSLB records | NS and glue records, MX, static hosts, TXT verification |
Practical rules:
- Use short TTLs (e.g. 30–300 s) on hostnames you steer dynamically, and long TTLs on NS records and anything static.
- Before a planned migration, lower the TTL (e.g. from 1 day to 60 s) at least one old-TTL period in advance, make the change, verify, then raise it again.
- Don't rely on DNS alone to drain traffic: some clients and resolvers cache longer than you asked. Keep old endpoints serving (or redirecting) for a while.
- Remember the resilience paradox: very short TTLs make you more dependent on your DNS servers being reachable every minute.
9. DNS as a single point of failure
Every request to Instagram starts with DNS. If clients can't resolve the hostname, it doesn't matter that every server, database and cache is perfectly healthy — to users, the service is down. And because DNS outages affect every hostname in a zone at once, they tend to be total rather than partial. Caching softens the blow (answers already cached keep working until their TTL expires), but with short TTLs the grace period is minutes.
9.1 Case study: the 2016 Dyn DDoS
On 21 October 2016, Dyn — a major managed DNS provider serving as the authoritative DNS for many large websites — was hit by a series of massive distributed denial-of-service attacks. The traffic came from the Mirai botnet: a large army of compromised Internet-of-Things devices (cameras, DVRs, home routers with default passwords) flooding Dyn's servers with DNS queries.
- For several hours, especially on the US East Coast and in Europe, resolvers couldn't get answers from Dyn's name servers.
- As cached records expired, sites such as Twitter, GitHub, Reddit, Netflix, Spotify and many others became unreachable for large numbers of users — even though their own servers were fine.
- Companies that used only Dyn had no fallback. Companies with a second DNS provider listed in their NS records stayed largely reachable, because resolvers retry other name servers when one doesn't answer.
- Use multiple, independent authoritative DNS providers (or your own plus a provider) with records kept in sync — the NS set is your redundancy.
- Over-provision and anycast DNS infrastructure so attacks are spread out and absorbed.
- Don't make every TTL tiny: longer TTLs on stable records let caches carry you through a DNS outage.
- Your availability includes your vendors' availability — DNS, CDN and certificate providers are part of your critical path.
9.2 Case study: the October 2021 Facebook / Instagram / WhatsApp outage
On 4 October 2021, Facebook, Instagram, WhatsApp and Messenger disappeared from the internet for roughly six hours — one of the largest outages in internet history. Meta's public post-mortem explained the chain of events:
1. Routine maintenance: an engineer runs a command intended to ASSESS global backbone capacity.
│ a bug in the audit tool that should have blocked it lets it through
▼
2. The command takes down ALL connections in Meta's backbone network
→ data centers are disconnected from each other and from the edge PoPs.
▼
3. Meta's authoritative DNS servers (at the edge) run a safety check:
"If I can't reach the data centers, I'm unhealthy → stop advertising my anycast IPs via BGP."
Every DNS site reaches the same conclusion at the same time.
▼
4. BGP withdrawal: the internet's routers forget how to reach Meta's DNS server IP prefixes.
The DNS servers are RUNNING — but unreachable.
▼
5. Resolvers worldwide: "A? i.instagram.com" → no route to the name servers → SERVFAIL.
Cached answers expire within minutes; apps and users RETRY aggressively
→ public resolvers see a big surge in queries for Meta's domains.
▼
6. Internal tools that depended on the same network/DNS are also down;
engineers must get PHYSICAL access to data-center hardware (behind strict security) to fix it.
▼
7. Backbone restored → BGP routes re-announced → DNS reachable → traffic returns.
Load is ramped back carefully: suddenly restoring all traffic risks power surges and cache stampedes.
Why this case study is so instructive for system design:
- A "safe" local rule caused a global failure. Withdrawing an unhealthy site from anycast is correct for one site; doing it everywhere simultaneously removed the whole service. Health-check logic needs a "don't all fail closed at once" safeguard (e.g. never withdraw the last N sites, or fail open when every site is affected).
- DNS + BGP sit beneath everything. Even perfectly healthy data centers are useless if nobody can find them.
- Shared fate between production and recovery tooling. When the network and DNS went down, so did the internal tools engineers would normally use to fix them. Out-of-band management access is critical.
- Retry storms amplify outages — for third parties too (public resolvers got hammered). Clients need backoff with jitter (see Resilience patterns).
- Recovery is its own risk: restoring billions of users at once can overload power, caches and databases. Meta had rehearsed "storm" drills for exactly this kind of recovery.
- Change safety: audit tools, staged rollouts and blast-radius limits for network changes are as important as for code deploys.
10. DNS security and privacy
10.1 Attacks
- Spoofing / cache poisoning: classic DNS over UDP has no authentication. An attacker who guesses a query's ID and port can inject a forged answer into a resolver's cache, sending everyone using that resolver to a malicious IP. The 2008 "Kaminsky attack" made this practical; resolvers responded by randomising source ports and other hardening.
- Hijacking: compromise the domain's registrar account or DNS provider account and change the NS or A records. Mitigate with registrar locks, MFA and change alerts.
- DDoS on authoritative servers (Dyn) or reflection/amplification attacks that abuse open resolvers to flood a victim.
- Surveillance and tampering: plaintext DNS reveals every hostname you visit to anyone on the path, and some networks rewrite answers (censorship, ad injection).
10.2 Defences
| Technology | What it protects | How | Limits |
|---|---|---|---|
| DNSSEC | Authenticity & integrity of answers | Zones are cryptographically signed; resolvers validate a chain of trust from the root | No privacy; operational complexity; partial adoption |
| DNS over TLS (DoT) | Privacy & integrity between stub and resolver | DNS inside TLS on port 853 | Dedicated port is easy to block/identify |
| DNS over HTTPS (DoH) | Privacy & integrity between stub and resolver | DNS messages sent as HTTPS requests on port 443 (looks like normal web traffic); supported by major browsers and OSes | Centralises queries at a few big resolvers; bypasses enterprise DNS controls; resolver still sees queries |
| DNS over QUIC (DoQ) | Same as DoT, lower latency | DNS over QUIC streams | Newer, less deployed |
| Registrar lock, MFA, CAA records | Domain hijacking, rogue certificates | Organisational controls | Process discipline required |
For a mobile app, DoH has a practical bonus: the app (or OS) can resolve names over the same HTTPS stack it already uses, which avoids broken or hijacking ISP resolvers. Note that DoH protects the hop to the resolver — the TLS SNI field and the destination IP can still reveal which site you're connecting to (Encrypted Client Hello is the emerging fix). See also Security.
11. How Instagram uses DNS
Instagram's DNS has two jobs: tell clients where to connect, and steer them to the right nearby place — for two very different kinds of traffic.
| Hostname (publicly observable) | Purpose | Where DNS points it |
|---|---|---|
i.instagram.com | Mobile app API (feed, likes, uploads, etc.) | A nearby Meta edge PoP running L4 + L7 (Proxygen) load balancers, which forward to a data-center region |
www.instagram.com | Web app | Similar edge infrastructure as the API |
scontent-xxx#-#.cdninstagram.com (and *.fbcdn.net) | Photos, video segments, thumbnails | A specific CDN cache cluster — the hostname itself often encodes the location, e.g. an airport code like bom (Mumbai) |
| Real-time / chat endpoints | Persistent DM/notification connections | Edge endpoints that terminate long-lived connections (see Direct messaging) |
11.1 Why separate hostnames for API and media?
- Different infrastructure: media goes to CDN cache servers optimised for throughput and disk; API calls go to proxies that forward to application servers. Separate names let DNS send each to the right fleet.
- Different routing and TTL policies: media hostnames can be pinned to a specific cache cluster to maximise cache hit ratio; API hostnames are steered to the best region for that user.
- Cookieless, isolated domain: putting user-generated media on a separate registrable domain (
cdninstagram.com, notinstagram.com) means browsers never attach Instagram login cookies to image requests (saving bytes on every request) and isolates any malicious uploaded content from the main site's security origin. - Independent scaling and failure domains: a CDN problem doesn't have to break the API, and vice versa.
11.2 Steering users to nearby PoPs and regions
- The app asks for
i.instagram.com. The query reaches one of Meta's anycast authoritative DNS servers — a nearby one, thanks to anycast. - That server looks up the resolver's network (and the client subnet via ECS, if provided) in a mapping computed centrally from latency measurements, PoP capacity and health. Meta engineers have publicly described such a system (named Cartographer) that computes which edge PoP each client network should use and pushes the map to the DNS servers.
- The answer — the VIP (virtual IP) of the best nearby PoP — comes back with a short TTL, so the mapping can change quickly when a PoP is overloaded, drained for maintenance, or fails.
- The app connects to that PoP. From there, Meta's own L4/L7 load balancers and backbone take over (see Load balancing).
- The feed response contains media URLs on CDN hostnames, which the app resolves the same way — landing on a nearby cache. See CDN.
Rough numbers
Assume 500M DAU, 20 lookups/device/day for the API host and ~5 distinct CDN hostnames
device lookups ≈ 500M × 20 × (1 + 5) = 60 billion/day ≈ 700K/s at the device level
most are answered by OS or resolver caches;
authoritative QPS ≈ (number of active resolvers × hostnames) / TTL
≈ (200,000 × 6) / 60 s ≈ 20,000 QPS — modest for an anycast fleet.
A cache miss adds ~20–150 ms to the first request; with a 60 s TTL and long-lived
connections, that cost is paid on only a small fraction of requests.
12. Trade-offs & common pitfalls
✅ What DNS gives you
- Indirection: move, add or remove servers without changing clients
- Cheap global traffic steering (geo, latency, weights, failover)
- Massive scale through hierarchical delegation and caching
- Anycast makes lookups fast and DDoS-resistant
⚠️ Limitations
- Changes are only as fast as the TTL (and stragglers ignore it)
- Coarse: steers resolvers, not individual users or requests
- Adds latency to the first request on a cache miss
- A critical dependency: a DNS outage = total outage
- Plain DNS is unauthenticated and unencrypted
Common pitfalls
- Single DNS provider (Dyn 2016): add a second, independent provider or self-hosted secondary.
- Using DNS for fast failover of individual servers: use load balancer health checks for that; DNS is for region-level steering.
- Forgetting to lower the TTL before a migration, then waiting a day for caches to expire.
- Tiny TTLs everywhere: higher latency and query cost, and no cushion if DNS itself has problems.
- CNAME at the zone apex or long CNAME chains (each hop can add a lookup).
- Clients that cache DNS forever (long-running JVMs, connection pools that never re-resolve) and keep hitting decommissioned IPs.
- Health checks that can all fail together and withdraw every site (Meta 2021).
- Unprotected registrar accounts: domain hijacking via a phished password.
- Ignoring resolver geography: GeoDNS without ECS sends some users to far-away PoPs.
13. Real-world technologies
| Product / tool | Type | When to use it |
|---|---|---|
| Amazon Route 53 | Managed authoritative DNS with geo, latency, weighted, failover and health checks | AWS-hosted systems needing GSLB-style routing |
| Cloudflare DNS, NS1, Akamai Edge DNS, UltraDNS | Anycast managed authoritative DNS, traffic steering, DDoS protection | High-availability public domains; often used in pairs for redundancy |
| Google Cloud DNS, Azure DNS / Traffic Manager | Cloud-native authoritative DNS (+ traffic management) | Systems on those clouds |
| BIND, PowerDNS, Knot, NSD | Self-hosted authoritative (and recursive) DNS servers | Running your own DNS at scale (as Meta does with in-house systems) |
| Unbound, Knot Resolver, dnsmasq | Recursive / caching resolvers | Corporate or data-center internal resolution |
| Google Public DNS (8.8.8.8), Cloudflare (1.1.1.1), Quad9 (9.9.9.9) | Public anycast recursive resolvers with DoH/DoT | End users; fallback resolvers in apps |
| CoreDNS, Consul DNS | DNS-based service discovery inside clusters | Kubernetes / microservices (see Microservices) |
dig, nslookup, dig +trace | Debugging tools | Inspecting records, TTLs and delegation paths |
14. Interview corner
What happens, step by step, when the app resolves i.instagram.com for the first time?
The OS stub resolver checks its cache, then asks the configured recursive resolver (ISP or public) over UDP 53 or DoH. The resolver checks its cache; on a miss it asks a root server (usually skipped because the .com referral is cached), gets a referral to the .com TLD servers, asks them and gets a referral (NS + glue) to Meta's authoritative name servers, then asks those. Meta's anycast authoritative server picks a nearby healthy edge PoP for that resolver/client subnet and returns its A/AAAA record with a short TTL. The resolver caches every answer for its TTL and returns the IP; the OS and app cache it; the app then opens a QUIC or TCP+TLS connection.
How would you use DNS to route users to the nearest data center, and what are the limitations?
Use GeoDNS or latency-based routing at the authoritative layer (a GSLB): map the resolver/client subnet to the best region based on geography or measured latency, filtered by health checks and capacity, and return that region's VIP with a short TTL. Limitations: the authoritative sees the resolver, not the user (mitigated by EDNS Client Subnet); changes are bounded by TTL and resolvers/clients that ignore it; granularity is per resolver, not per user; and it can't react to per-request conditions. Inside the region, L4/L7 load balancers do fine-grained balancing; anycast can complement DNS for faster failover.
What TTL would you pick for the API hostname, and why?
Short — around 30–300 s (e.g. 60 s) — because we steer it dynamically and want region failover within minutes. That raises authoritative query volume, but resolver caching aggregates millions of users, so the load is modest for an anycast fleet. NS records and static records get long TTLs (hours to days) for resilience. Before a planned migration, lower TTLs in advance. And because short TTLs increase dependence on DNS availability, use multiple anycast sites and ideally redundant providers.
Explain the October 2021 Facebook outage. What would you change in the design?
A maintenance command meant to assess backbone capacity accidentally took down Meta's entire backbone; an audit tool that should have blocked it had a bug. Meta's edge DNS servers, unable to reach the data centers, marked themselves unhealthy and withdrew their BGP anycast announcements — all of them at once — so the name servers became unreachable and every Meta domain failed to resolve worldwide for about six hours. Internal tools were affected too, requiring on-site access. Design changes: health-check logic that never withdraws all sites simultaneously (fail open / keep a minimum set announced); stronger change safety (staged network changes, independent verification, smaller blast radius); out-of-band management networks independent of production DNS/backbone; possibly a secondary DNS presence; and client retry backoff to avoid query storms.
Anycast vs GeoDNS — how do they differ and when would you use each?
GeoDNS returns different IPs to different resolvers; routing decisions are made by your DNS logic and are bounded by TTLs. Anycast advertises the same IP from many sites and lets BGP deliver packets to the nearest one; failover happens as fast as BGP converges (seconds to minutes) with no TTLs, and DDoS is naturally spread. Anycast suits stateless, short exchanges (DNS itself) and L4 edges with connection-aware LBs; GeoDNS gives explicit, policy-driven control (capacity, residency, weights). Large platforms combine them: anycast DNS servers running GeoDNS logic.
Why does Instagram serve media from a different domain than its API?
Separate hostnames let DNS route media to CDN cache clusters and API calls to proxy/edge fleets with different policies; a separate registrable domain (cdninstagram.com) keeps login cookies off millions of image requests and isolates user-uploaded content from the main site's security origin; and it separates failure and scaling domains. Media URLs can even encode a specific cache cluster to maximise hit ratio.
How do you make DNS not be a single point of failure?
Redundancy at every layer: multiple authoritative name servers on separate networks, anycast across many sites, ideally two independent providers with synchronised zones; sensible TTLs so caches carry you through short outages; DDoS capacity and rate limiting; health-check logic that can't take everything down at once; registrar locks and MFA; monitoring of resolution from many vantage points; and clients that cache last-known-good answers and back off on failure.
15. Check your understanding
A resolver received an A record with TTL 300 s two minutes ago. A phone now asks it. What TTL does the phone see, and when will the resolver next contact the authoritative server for this name?
The phone sees TTL ≈ 180 s (300 − 120). The resolver re-queries the authoritative server only after those 180 s expire and someone asks again.
You switch a hostname's A record to a new data center. The old TTL was 86,400 s. What's the worst case before all well-behaved resolvers use the new IP, and how should you have done it?
Up to 24 hours. Better: at least a day before the move, lower the TTL to ~60 s; once the old 24 h TTL has expired everywhere, switch the record (most traffic moves within a minute or two), keep the old site serving for stragglers, then raise the TTL again.
Which record type would you use for each: (a) point photos.example.com at a CDN's hostname, (b) prove domain ownership to a vendor, (c) give the IPv6 address of the API, (d) delegate eu.example.com to a different set of name servers?
(a) CNAME, (b) TXT, (c) AAAA, (d) NS records for eu.example.com in the parent zone (plus glue A/AAAA records if the name servers are inside that subdomain).
A user in Chennai using a public resolver gets sent to a Singapore PoP instead of the Chennai one. Why might that happen and what fixes it?
The authoritative GeoDNS only sees the resolver's IP, and the resolver instance answering the user may be located (or geolocated) in Singapore. Fixes: EDNS Client Subnet so the authoritative sees the user's prefix; resolvers with anycast instances in India; latency-based mapping built from real-user measurements; or anycast for the PoP addresses themselves.
Health checks run every 10 s, a region is removed after 3 failures, and the record TTL is 60 s. Roughly how long until most users move off a dead region?
Detection ≈ 3 × 10 = 30 s, plus up to 60 s of cached answers ≈ ~90 seconds for most users — longer for clients that ignore TTLs or keep existing connections to the dead region until they time out.
In October 2021, were Meta's DNS servers down? Explain precisely what failed.
Mostly no — they were running but unreachable. After the backbone failure, they withdrew their BGP route advertisements (because they couldn't reach the data centers), so the internet had no route to their IP prefixes. Resolvers couldn't reach any authoritative server for Meta's domains and returned SERVFAIL, so the apps couldn't resolve any hostname.
DNSSEC or DoH — which one stops your ISP from seeing which sites you look up? Which one stops a forged answer from being accepted?
DoH (or DoT/DoQ) encrypts the query between your device and the resolver, hiding it from the ISP (though the resolver still sees it). DNSSEC signs records so a validating resolver can reject forged answers — but it doesn't encrypt anything. They solve different problems and can be used together.
- DNS maps names to IPs through a hierarchy — root → TLD → authoritative — walked by recursive resolvers on behalf of stub resolvers.
- Caching with TTLs at app, OS and resolver layers makes it scale; "propagation" is just cache expiry.
- Know A, AAAA, CNAME, NS, MX, TXT, SOA (plus PTR, SRV, CAA).
- DNS is the first global load balancer: GeoDNS / latency, weighted, health-checked failover, with anycast for speed and DDoS resilience.
- TTL is a trade-off between agility and resilience/latency; lower it before migrations.
- DNS is a critical single point of failure — Dyn 2016 and Meta 2021 show why you need redundancy, safe health-check logic and independent recovery paths.
- Instagram uses separate API and media hostnames, steered by its own anycast DNS to nearby edge PoPs and CDN caches.
Related lessons
- Networking basics — IP, BGP, UDP and what happens after the IP is known
- CDN — how DNS steers media requests to nearby PoPs
- Load balancing — GSLB vs local load balancing and anycast L4 edges
- Clients — DNS caching, pre-connecting and the client's view of the first hop
- Multi-region — DNS-based regional failover and data residency
- Security — DDoS protection, DNSSEC, DoH and domain hijacking
- Resilience patterns — retries with backoff to avoid DNS query storms
- Core principles — single points of failure and availability math