Docs
Type to search every article.
  1. Docs
  2. Zones

Origin shield

5 min read Updated

On this page
  1. Choosing a Home PoP
  2. Auto Detect
  3. When the Home PoP cannot answer
  4. What goes through it
  5. Home PoP for dynamic requests
  6. With the Caching strategy
  7. What the statistics show
  8. When it helps

The origin shield puts one of our locations between your origin and the rest of the network. With a Home PoP chosen, only that location fetches from your origin; every other location fetches through it any file it does not take from another location's copy first, and a file fetched once is served to all of them from its cache, so your origin sees one location instead of all of them and its traffic falls to roughly one fetch per file. The same applies to the pieces of a large file and to the background refresh of a file that has expired.

Choosing a Home PoP#

Origin shield (Home PoP), under Connecting to your origin on the zone page's Origin tab, is a switch that turns Auto Detect on or off. Specific locations can no longer be chosen by hand: switching Origin shield (Home PoP) on enables Auto Detect, which automatically measures and chooses the location nearest your origin for you. From the API the setting is HOME_POP: auto to turn Auto Detect on, or an empty string for off. HOME_POP_LOCATION reports the location in use (read only). A tunnel zone has no such setting: the location its connector joins is its Home PoP, for files and every other request.

Auto Detect#

Every location measures its round trip to your origin every five minutes, and the location with the shortest becomes the Home PoP. The note under the switch names the location in use. Another location takes over only when it is clearly nearer, at least 20% and 5 milliseconds shorter, so two locations at a similar distance never trade the zone back and forth; a location that can no longer reach your origin, or that is out of service, hands the zone to the next nearest. When switched on, every location fetches from your origin directly until the first measurements arrive, within about ten minutes (or keeps the previously active location if already known). The measurement is a connection that opens and closes, three times from each location, and nothing is requested.

When the Home PoP cannot answer#

If the Home PoP is offline, or a fetch through it fails or comes back with a 5xx or a 403, the location that wanted the file fetches it from your origin directly and carries on; your origin just sees more than one location until it is back. Any other answer through the Home PoP is your origin's answer, relayed: a 404 through the shield is your 404.

What goes through it#

Every GET and HEAD: fetches to fill the cache, the pieces of large files, the refresh of expired files, and a request passed straight through because of a cookie or an Authorization header. A POST, PUT, PATCH, DELETE or OPTIONS, and a WebSocket, go to your origin directly from the location that took them, unless Home PoP for dynamic requests is on.

Home PoP for dynamic requests#

Home PoP for dynamic requests, under Origin shield (Home PoP) in the same box, sends the requests that are never cached through the Home PoP as well: every POST, PUT, PATCH, DELETE and OPTIONS with its body (forms, logins, API calls, uploads) and every WebSocket. Your origin then hears from one location for everything, not only for files. It can be switched on only while Origin shield (Home PoP) is on, and switching Origin shield (Home PoP) off or on again turns it off. It does not apply to a bucket, which takes reads only, or to a tunnel zone, whose every request already goes through its entry location. From the API it is HOME_POP_DYNAMIC: 1 or 0.

If the Home PoP is offline or cannot be reached, these requests go to your origin directly, as files do. A request with a body is never sent twice: when the connection to the Home PoP fails after the request may already have reached it, your visitor gets a 502 rather than the request being repeated, so a form or a payment is never submitted twice. Whatever the Home PoP answers, an error included, is the answer your visitor gets.

With the Caching strategy#

On a miss a location first asks another of our locations that holds the file, as the zone's Caching strategy allows, then the Home PoP if Origin shield (Home PoP) is on, then your origin. The two settings are separate and work together. The Home PoP makes one location the only one that fetches from your origin for the zone, so your origin hears from one location whatever the file. The Caching strategy lets any location's copy serve another location, so a file already held somewhere is not fetched again; a file no location holds yet still goes through the Home PoP when it is on.

What the statistics show#

The zone's statistics gain an Origin shield chart of the bytes the Home PoP sent to the other locations, with the number of requests it answered for them above it. That traffic is between our own locations and is neither counted as viewer traffic nor billed. Origin bandwidth is counted where your origin was actually fetched, which with a shield is the Home PoP. A request another location answered with a file the Home PoP already held is a cache hit: your origin was never asked.

When it helps#

Origin shield (Home PoP) is set per zone, and is worth switching on when:

  • your origin's bandwidth is metered or costs more than ours: each file leaves it about once, however many locations serve it;
  • your origin is far from most of your viewers, so the long trip to it is made once by the Home PoP instead of by every location;
  • your origin is a server rather than a store, and copes better being asked once than by every location at the same moment, as when a new episode or an update goes out to everyone at once.

Leave it off when your origin is a bucket or store already close to your viewers and cheap to read from: the extra hop costs a few milliseconds on the first fetch of each file in every other location and saves little.

Home PoP for dynamic requests is for a zone whose origin should hear from one place for everything, files and the rest:

  • a website or application whose logins, forms and API calls you want to arrive from the same location as its pages, so its logs, its rate limits and its security rules see one location rather than many;
  • an origin that limits how many connections it accepts, since every location's requests then share the Home PoP's connections to it;
  • WebSockets or uploads to an origin that should see a single location connecting.

Leave it off when those requests must be as fast as possible for visitors far from the Home PoP: a form or an API call from another continent then travels to the Home PoP before it reaches your origin, which can take longer than going straight there. It changes nothing for files, which go through the Home PoP either way.