Bird
Raised Fist0

Why CDN Exists and What Origin Servers Cannot Do Alone

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/5
DNS Resolver

Resolves user domain to CDN edge IP

User's browser queries DNS to find nearest CDN edge server IP

Protocol:DNS (UDP)
BeforeUser has domain name but no IP address
AfterUser obtains CDN edge IP address to send HTTP request
CDN Edge Cache (e.g., Cloudflare, Akamai)

Receives HTTP GET request for static asset

Checks local cache for requested content

Protocol:HTTP GET (TCP)
BeforeCDN edge cache may or may not have asset cached
AfterIf cached, serves asset immediately; else forwards request to origin
Load Balancer (e.g., ELB, NGINX)

Distributes cache miss request to healthy origin server

Selects origin server based on health and load

Protocol:HTTP GET (TCP)
BeforeOrigin servers are ready to serve requests
AfterOne origin server receives the request for processing
Origin Servers

Processes request and generates dynamic or static content

Responds with requested content to load balancer

Protocol:HTTP Response (TCP)
BeforeOrigin server has no cached response for this request
AfterOrigin server sends fresh content back to load balancer
Cache Invalidation Service

Triggers CDN cache purge after content update

Ensures CDN edge caches remove stale content

Protocol:API Call (HTTPS)
BeforeCDN edge cache may hold stale content
AfterCDN edge cache invalidates outdated content to serve fresh data
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────────┐
│   DNS Resolver    │
└─────────┬─────────┘
          │ DNS Lookup (UDP)
          ▼
┌───────────────────────────────┐
│ CDN Edge Cache (Cloudflare)   │
│  - caches static content       │
│  - reduces origin load         │
└─────────────┬─────────────────┘
              │ HTTP GET (TCP)
              ▼
     ┌───────────────────────┐
     │ Load Balancer (ELB)   │
     │  - distributes load   │
     │  - health checks      │
     └──────────┬────────────┘
                │ HTTP GET (TCP)
                ▼
         ┌───────────────┐
         │ Origin Servers│
         │  - dynamic    │
         │    content    │
         └──────┬────────┘
                │ Cache Miss Response (HTTP)
                ▼
    ┌─────────────────────────────┐
    │ Cache Invalidation Service   │
    │  - updates CDN cache         │
    │  - triggers purge on change  │
    └─────────────────────────────┘

This architecture illustrates why CDNs exist: to cache static content close to users, reducing latency and origin server load. The DNS Resolver directs clients to the nearest CDN edge cache, which serves cached content immediately if available. On a cache miss, the request flows through a load balancer that distributes traffic across origin servers, which generate dynamic or uncached content. The Cache Invalidation Service ensures that when origin content changes, stale cached copies at CDN edges are purged promptly. Origin servers alone cannot handle global scale or reduce latency effectively, which is why CDNs are critical for performance and scalability.

Primary Focus

✓

Practice

(1/5)
1. In a system where Step 4 is the Delivery Worker checking message delivery status, what happens if the Delivery Worker finds the recipient's presence TTL expired?
easy
A. The Delivery Worker queues the message for offline delivery and updates status to 'sent but not delivered'
B. The Delivery Worker immediately marks the message as delivered without retry
C. The Delivery Worker deletes the message assuming recipient is unreachable
D. The Delivery Worker retries sending indefinitely until TTL is refreshed

Solution

  1. Step 1: Trace Delivery Worker decision at Step 4 -- Bob's presence TTL

    If TTL expired, recipient is offline; message can't be delivered immediately.
  2. Step 2: Understand offline delivery handling

    Delivery Worker queues message for later delivery and marks status as 'sent but not delivered' to reflect state.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Expired TTL -> queue message, status 'sent but not delivered' [check]
Hint: Expired TTL means offline, queue message for later delivery [check]
Common Mistakes:
2. A system design interview requires you to explain how you handle conflicting requirements between latency and consistency. Which component or approach best helps you present this trade-off clearly to the interviewer?
easy
A. Use a decision matrix comparing latency and consistency impacts per component
B. Avoid discussing trade-offs and emphasize only the chosen technology
C. Describe only the eventual consistency model without latency details
D. Focus solely on the fastest technology without discussing consistency implications

Solution

  1. Step 1: Identify the need to clarify trade-offs

    Presenting trade-offs requires explicit comparison of conflicting requirements, such as latency vs consistency.
  2. Step 2: Use a decision matrix for clarity

    A decision matrix systematically compares options, showing pros and cons clearly, which helps interviewers understand your reasoning.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Decision matrix clarifies trade-offs explicitly [check]
Hint: Use decision matrices to clarify conflicting trade-offs [check]
Common Mistakes:
3. For a distributed message queue requiring exactly-once delivery semantics, which architecture choice best balances complexity and correctness?
medium
A. Use at-least-once delivery with idempotent consumers to handle duplicates
B. Implement transactional writes in the broker with two-phase commit across producers and consumers
C. Use at-most-once delivery to avoid duplicates but risk message loss
D. Use a best-effort fire-and-forget model for maximum throughput

Solution

  1. Step 1: Analyze delivery semantics

    Exactly-once requires atomicity across producer and consumer; at-least-once (A) can cause duplicates; at-most-once (C) risks loss; fire-and-forget (D) ignores reliability.
  2. Step 2: Evaluate architecture complexity

    Two-phase commit (B) ensures atomic commit across components, enabling exactly-once semantics despite complexity; idempotent consumers (A) reduce duplicates but don't guarantee exactly-once.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Two-phase commit -> atomic exactly-once delivery despite complexity [check]
Hint: Two-phase commit enables atomic exactly-once delivery [check]
Common Mistakes:
4. If the Booking Service loses connectivity to the Calendar Availability Service during booking confirmation, what is the most likely failure mode experienced by the user?
medium
A. The booking is queued locally and confirmed later without user notification
B. The booking request times out and the user sees an error without confirmation
C. The booking is confirmed but the calendar is not updated, causing double bookings
D. The system automatically retries and confirms booking without user delay

Solution

  1. Step 1: Trace failure impact on booking flow

    Loss of connectivity prevents immediate calendar update, risking inconsistency.
  2. Step 2: Analyze failure handling

    Immediate confirmation without calendar update (A) risks double bookings; timeout with error (B) hurts UX; automatic retry without delay (D) is unrealistic under network failure. Local queuing (C) allows eventual consistency with delayed confirmation.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Local queuing delays confirmation but prevents data loss [check]
Hint: Booking queues locally on calendar service failure, delaying confirmation [check]
Common Mistakes:
5. For a global DNS service aiming to minimize latency for users worldwide, which architecture is more appropriate and why?
medium
A. A single centralized authoritative DNS server with a large cache to serve all queries
B. A recursive DNS server that forwards all queries to root servers directly without caching
C. A distributed network of authoritative DNS servers geographically located near users with DNS Anycast routing
D. A peer-to-peer DNS system where clients query each other for domain resolution

Solution

  1. Step 1: Analyze latency requirements and architecture options

    A single centralized server creates latency for distant users and is a single point of failure. Peer-to-peer systems lack reliability and consistency guarantees. Recursive servers forwarding to root servers without caching cause excessive load and latency.
  2. Step 2: Identify benefits of distributed authoritative servers with Anycast

    Geographically distributed authoritative servers with Anycast routing direct users to the nearest server, minimizing latency and improving availability.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Distributed authoritative servers + Anycast reduce latency globally [check]
Hint: Anycast + distributed authoritative servers minimize global latency [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard