DNS Proxies CDNs and Safe Address Changes

Scaling DNS and Load Balancing · 40 min

System Design · Module 5 · Lesson 2 of 4 · 40 min

DNS Proxies CDNs and Safe Address Changes

Distinguish naming from request routing, place forward and reverse proxies correctly, and plan a DNS migration with cache overlap.

DNS selects an entry address under caching rules; downstream proxies and application contracts govern what happens to requests.

01 The idea

The problem this lesson solves

A domain can point to a CDN, which forwards a cache miss through a reverse proxy to an application. These components solve different problems. DNS discovers an address; proxies relay traffic; a CDN may serve a permitted cached representation near the reader. Understanding the boundaries prevents migration plans that assume DNS changes are instant or caching rules that accidentally share private content.

Use the peak traffic and failure budgets from module 4 to judge whether an added server actually helps.

Recursive resolverA DNS service that resolves names for a client, using caches and further lookups as needed.
Reverse proxyA service fronting origin servers and forwarding requests to them.
CDNA distributed serving layer that can cache eligible content near callers.

02 Worked example

Resolve a name, then connect to its entry point

Address resolution and HTTP are separate pathsResolve the nameClient → resolverAddress returnedSend the HTTP requestClient → edge / proxyConnect to addressForward eligible workEdge / proxy → originCache misses or bypassAddress resolution and HTTP are separate pathsResolve the nameClient → resolverAddress returnedSend the HTTP requestClient → edge / proxyConnect to addressForward eligible workEdge / proxy → originCache misses or bypass
DNS resolution happens before the connection to the edge. The recursive resolver does not forward the HTTP request to the origin.
1
Client asksA stub resolver requests the service address from a recursive resolver.
2
Resolver followsIt uses cached answers or follows the relevant delegation chain.
3
Client connectsThe returned entry point may be a reverse proxy or CDN.
4
Origin handles missesThe intermediary forwards only the work its policy requires.

03 The method

Understand the mechanism

Separate recursive lookup from authoritative ownership

A client usually asks a recursive resolver for a name’s address. The resolver can answer from cache or perform the necessary lookups through the DNS hierarchy. Authoritative servers provide the records for the zones they serve.

The client does not normally contact every DNS server in the hierarchy itself for each HTTP request. Cached answers at several layers can avoid repeated work. Records may also contain aliases that lead to another name before an address is obtained.

This structure separates who publishes a record from who answers a particular client using a cached copy. Changing the authoritative record does not immediately replace every copy already held by recursive resolvers, operating systems or applications.

After obtaining an address, the client makes its transport connection to the service entry point. The DNS resolver is not on the subsequent HTTP forwarding path merely because it helped find the address.

Treat TTL as cache lifetime, not a global switch

A TTL influences how long an answer can be cached under DNS rules. If an old answer was obtained with a long TTL, lowering the authoritative TTL at cutover time does not retroactively shorten that already cached lifetime.

For a planned address change, lower TTL sufficiently in advance, allow old cached answers to age under the previous policy, verify the new target, change the record and keep both targets serving during the required overlap. Existing connections may persist beyond the moment a client would otherwise resolve again.

DNS-based traffic steering is therefore useful but coarse. Different resolvers and clients observe changes at different times. Health-aware answers can reduce future traffic to an unhealthy destination, but caching delays and existing sessions remain relevant.

Test migration behavior with the actual clients and resolvers you care about. Do not define success as “dig on my laptop shows the new address” while shutting down the old endpoint immediately.

Distinguish forward and reverse proxies

A forward proxy acts on behalf of clients, such as an organization controlling outbound traffic. A reverse proxy acts as the entry point for servers, accepting incoming requests and forwarding them to an appropriate backend.

A reverse proxy can terminate TLS, apply routing, enforce size or timeout limits, and collect request metrics. An API gateway is a role that may combine reverse-proxy behavior with authentication integration, quotas, transformations or API-specific policies.

These functions introduce responsibility. If the proxy adds identity or client-address headers, the backend must trust them only from the intended proxy path and ensure callers cannot spoof equivalent authority. If the proxy retries requests, its retry behavior must match the API’s idempotency contract.

The proxy also has capacity and availability limits. A design with many healthy app servers behind one fragile entry process still has an entry-point failure problem. Redundancy, configuration rollout and certificate management belong to the operational design.

Explain what a CDN actually caches

A content delivery network places serving capacity near users and can cache eligible responses at its edges. A hit avoids some or all origin work. A miss or bypass forwards the request according to the CDN and origin configuration.

Cacheability is a policy, not a consequence of being public on the internet. Responses can vary by path, query, language, headers, cookies or authorization. The cache key and variation rules must distinguish representations that must not be shared.

Static versioned assets are a straightforward case: a changed file can receive a new URL, allowing long caching of immutable versions. Mutable destinations or personalized responses need a more careful freshness and privacy contract.

A CDN can reduce latency, origin bandwidth and repeated work, but it does not make an uncached origin infinitely scalable. Expiry waves, purges or a cold region can send a surge to the origin. Model that miss path and its capacity.

Handle invalidation and multiple layers

There may be a browser cache, edge cache, reverse-proxy cache, local app cache and shared object cache. Updating the database affects none of those copies automatically unless the design connects them through policy or invalidation.

Suppose a7’s destination changes. Deleting an app-cache key does not necessarily invalidate a cached HTTP redirect in the browser or edge. Choose redirect status and cache headers consistent with destination mutability, and include every layer in the freshness contract.

Versioned URLs simplify immutable assets because old and new representations have different identities. They do not solve every mutable-resource problem. Purge APIs can help, but their completion and propagation behavior must be understood rather than assumed instantaneous.

Observe cache status and origin fetches at each layer. A high edge hit rate with incorrect cache variation is a correctness problem, not a success. A low hit rate may be caused by unbounded query-string variation rather than insufficient cache capacity.

Plan safe change and failure behavior

For a domain migration, verify the new target’s certificate, routing, dependencies and responses before directing users to it. Keep the old target available during overlap. Record how to revert the record and how that interacts with caches already observing the new answer.

For a CDN origin outage, decide whether an acceptable stale representation may be served. That choice depends on the resource. A versioned documentation asset and a revoked access decision have very different stale-data consequences.

Monitor resolver outcomes, connection errors, TLS errors, edge status, origin status and cache hit/miss behavior separately. Otherwise an origin outage may be misdiagnosed as DNS merely because users say “the website does not open.”

The diagram should show two paths: name resolution and request forwarding. Label the authority for DNS records and the authority for application data. This makes migrations and cache failures understandable without treating every intermediary as the same kind of box.

Guided tutorial

  1. Observe naming and HTTP separately

    Run dig example.com A and curl -I https://example.com. Identify address-answer information in the first output and HTTP metadata in the second. Explain why a valid DNS answer does not prove the application is healthy and why the resolver does not relay the later HTTP request.

  2. Draw the forwarding path

    Draw client → CDN or reverse proxy → application. Add a cache-hit branch that returns from the edge and a miss branch that reaches the origin. Label where TLS is terminated and which component is trusted to set forwarded metadata.

  3. Rehearse a DNS migration

    Write a timeline for lowering TTL ahead of the move, waiting for prior answers to age, validating the new endpoint, changing the address and overlapping service. Place one client with an old cached answer and another with an established connection on the timeline.

  4. Review a mutable redirect

    Assume a7 can change destinations. List browser, edge and app caches that may retain the old value. Choose a documented freshness policy across those layers and explain why deleting only the app’s key cannot guarantee immediate global visibility.

Shell commands and migration checklist

dig example.com A
curl -I https://example.com
# Migration: lower TTL ahead of cutover → verify new target
# → change answer → overlap old/new serving → observe → retire old

Check your result

dig reports an address answer or a DNS outcome; curl reports HTTP response headers. These are separate observations. Keep both targets serving during the planned cache and connection overlap.

04 Cheat sheet

Review the decisions

Use this table to explain the mechanism and its limit without memorizing a product name.

Choice or conceptRememberCheck
DNSName → recordsCaches and existing connections
Forward proxyActs for clientsClient policy boundary
Reverse proxyFronts serversRouting and upstream contract
CDNServes eligible edge contentCorrect cache key and privacy rules

05 Where & why

Check the primary references

Use official references for protocol and implementation details. The questions here are teaching prompts.

Primary reference
DNS concepts and facilities

Read DNS concepts and facilities

Primary reference
HTTP caching semantics

Read HTTP caching semantics

State the implementation version and the workload assumptions when defending your own design.

06 Interview questions

Explain the reasoning out loud

Answer before opening the explanation. The questions progress from vocabulary to decisions and failure behavior.

What does Recursive resolver mean?
A DNS service that resolves names for a client, using caches and further lookups as needed.
What does Reverse proxy mean?
A service fronting origin servers and forwarding requests to them.
What does CDN mean?
A distributed serving layer that can cache eligible content near callers.
Does a five-minute TTL flush an older cached answer?
No. A resolver holding the old answer may retain it for the older remaining lifetime. Plan the TTL reduction ahead of the cutover.
Does a DNS change close existing connections?
No. Established connections have their own lifetime and may continue using the prior address.
How is a CDN miss served?
The edge follows its configured upstream policy to fetch or revalidate content, then may store the eligible result. The origin still needs a capacity and failure plan.
Why distinguish forward from reverse proxy?
It identifies whose behalf the intermediary acts on and where policy is applied. The same forwarding technology can serve different roles.
Can a CDN safely cache every successful API response?
No. Eligibility, privacy, authorization scope and cache-key inputs must be defined. A successful response can still be private.

07 Practice problems

Practice a new case

Solve the new cases before revealing hints. Complete worked solutions follow the set.

Name the proxy

Easy
Classify a corporate browsing proxy and an ingress proxy in front of an API.
Follow-up
The proxy's position alone is less useful than whose behalf it acts on.
Show the hint
Ask whether it represents clients or servers.

Name a record

Easy
State which problem a DNS address answer solves and which HTTP permission problem it does not solve.
Show the hint
Location and authorization are separate.

DNS overlap

Medium
Plan a migration from a record with a 24-hour TTL to a new origin using a later five-minute TTL.
Follow-up
Caches holding the old TTL do not immediately learn the new one.
Show the hint
Lower the TTL before changing the address.

Private cache

Medium
Explain the risk of caching /profile using only its URL as a public CDN key.
Show the hint
Different users can receive different bodies for the same path.

Connection overlap

Medium
Why keep an old origin serving after its DNS answer changes?
Show the hint
Clients may retain answers or open connections.

Migration review

Hard
Plan a hostname cutover when old clients can keep long-lived streams.
Show the hint
DNS TTL does not move streams.

Worked solutions

1. Name the proxy

The corporate browsing proxy is a forward proxy for clients. The ingress proxy is a reverse proxy for the API servers.

2. Name a record

It helps locate an entry address for a hostname. It does not decide whether the caller may read a private resource.

3. DNS overlap

Lower TTL at least an old-TTL interval ahead under the standard caching model, verify the new origin, change the address, and keep the old origin serving through the overlap. Account for connection lifetimes and monitor stragglers rather than claiming an exact universal cutoff.

4. Private cache

One user’s private representation may be served to another. Define private/no-store behavior or a correct authorized cache design instead of a global URL-only entry.

5. Connection overlap

Some callers can still reach the old address. An overlap period and monitoring prevent avoidable failures while their routing state changes.

6. Migration review

Verify the new target, prepare TTL changes, overlap serving, and define stream draining/reconnect behavior. Monitor both endpoints and retain a rollback plan until the intended client population has migrated.