Skip to main content

System Design Prompt: Build a CDN From Scratch

Design a CDN from scratch: edge caching, cache invalidation, origin shielding, TLS at edge, and geographic routing for global delivery.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt asks the AI to design a CDN from scratch, serving [content_type] to [user_regions] at [peak_bandwidth]. It covers ten areas: edge server and PoP placement, a cache hierarchy from L1 edge through L2 regional to origin shield and origin, cache key and vary-header design, invalidation via [invalidation_method], origin pull versus push, geographic DNS routing, TLS termination at the edge, DDoS and WAF protection, real-time analytics, and cost optimization through cache hit ratios.

The structure works because a CDN is fundamentally a layered caching and routing problem, and each layer has its own keys, TTLs, and failure modes. Passing [content_type] shapes how cacheable the traffic is — static assets behave very differently from API responses. [user_regions] drives PoP placement and DNS routing, [peak_bandwidth] sizes capacity planning, and [invalidation_method] (like tag-based purge with stale-while-revalidate) determines how quickly stale content clears without hammering the origin.

When to use it

  • You're learning how CDNs work end to end and want a structured mental model
  • You're designing an edge/caching layer and need a cache hierarchy that offloads the origin
  • You need an invalidation strategy via [invalidation_method] that won't cause origin storms
  • You're planning PoP placement across [user_regions]
  • You're sizing capacity and cost against [peak_bandwidth] and hit-ratio targets
  • You want TLS-at-edge and DDoS/WAF integration designed in, not bolted on

Example output

Expect a layered design: edge and PoP topology for [user_regions], the L1/L2/origin-shield/origin hierarchy with cache-key and vary rules, an invalidation flow using [invalidation_method], a geographic DNS routing approach with latency fallback, a TLS and certificate-management section, and capacity planning sized to [peak_bandwidth]. It typically closes with failure-mode analysis and cost-optimization targets.

Pro tips

  • Set [content_type] precisely; cacheability of static images versus dynamic API responses changes the entire cache-key design
  • Use a real [peak_bandwidth] figure so the capacity planning and PoP sizing aren't fictional
  • Lean on [invalidation_method] — tag-based purge with stale-while-revalidate avoids origin storms that naive purging causes
  • Ask the model to detail the cache-key and vary-header rules; subtle vary mistakes cause cache fragmentation or poisoning
  • Push on the origin-shield layer; it's the piece that protects your origin when edge caches miss en masse
  • Have it spell out failure modes per layer — what happens when a PoP or the origin shield goes down

Frequently Asked Questions

Is this for building a CDN or using one?
It's a from-scratch design exercise, useful for understanding how providers like Cloudflare or Fastly work internally, or for building edge infrastructure. If you only need to configure an existing CDN, the cache-key and invalidation sections still transfer directly to your config.
How does cache invalidation work in this design?
The default `[invalidation_method]` is tag-based purge with stale-while-revalidate, which lets you clear groups of related objects by tag while serving slightly stale content during refresh. This avoids the origin-overload spikes that immediate, blanket purges can trigger.
What does the origin shield do?
The origin shield is an extra cache layer between regional edges and your origin. When many edges miss simultaneously, they hit the shield instead of the origin directly, collapsing duplicate requests and dramatically reducing origin load during cache misses.
Can it handle dynamic content and API responses?
Yes, if you include them in `[content_type]`. Dynamic content is harder to cache, so the model will rely on shorter TTLs, careful vary headers, and stale-while-revalidate rather than long-lived caching. Static assets remain the easiest win.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in System Design Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support