Lesson 7 of 16
26. CDNs

26.6 What is an origin shield?

3 min read+10 XP

In the warehouse: A new biscuit launches. Fifty warehouses each find an empty shelf and each phone the factory. The factory gets fifty calls for the same thing. Put a regional depot in between: warehouses call the depot, the depot calls the factory once, then supplies all fifty.

In the system: An origin shield is a designated cache layer (one PoP, or a regional tier) that sits between all the edges and your origin. Edge misses go to the shield; only shield misses go to the origin.

without a shield, 50 PoP misses become 50 origin fetches; with one, a single fetch.

Figure: the shield turns many edge misses into one origin request.

  • Fewer origin requests for new or expired content: in the chapter's code, a new cover requested at 50 PoPs means 50 origin fetches without a shield, 1 with it.
  • Higher overall hit ratio, because the shield is shared by all edges.
  • Combined with request collapsing (the shield sends one request for many simultaneous misses on the same object), it protects the origin from stampedes, much like single-flight in Chapter 13.

Cost: an extra hop on misses, and the shield itself must be well connected to the origin; pick a shield location close to your origin (Mumbai for the bookstore). Most CDNs offer it as a setting (for example, CloudFront Origin Shield, or Fastly's shielding).

Memory code: "Warehouses call the depot; only the depot calls the factory."