Add AMP Cache Purge Ring
In order to support multiple amp-caches and ensure that publishers only need to update content in a single place a purge ring should be created.
When an AMP Cache receives a purge request it will 302 redirect to the next amp cache location.
In order to prevent a loop it will append a header saying which amp-cache has been purged.
- Should we use a new header or a standard header such as VIA?
- Do the amp caches hard code in the next location or should we create a file that is served as part of amphtml scripts that can be periodically queried?
Initially the only two locations will be cdn.ampproject.org and amp.cloudflare.com
Related to #6167
/to @vitaliybl
That is an interesting idea. I could see some downsides, too:
- If some member of the ring has trouble forwarding purge requests, it will be difficult for publishers to debug and take corrective action;
- What happens to propagation guarantees as the number of services in the ring grows?
- Members of the ring would be forced to implement each other's API or stick to the same API (the latter would probably be better for the ecosystem);
- How would authentication/authorization work in the ring? Google AMP Cache update-ping API uses implicit authorization by checking what's on the publisher's server, but the idea of using explicit auth has been brought up before.
I will defer to @cramforce who came up with the idea.
I'm not a huge fan of this due to the debugging issues identified above. In addition we may not want all caches updated.
There are two update scenarios. in one we detect the page change locally and ping all the caches or the cache ring - that works.
In the other we detect the change as we are building the page for one of the caches. Example the google cache requests a page and we notice the content has changed and return a new page. At that point we'd want to issue an update ping to any other amp caches to ensure they have the now updated page but we wouldn't want to update the google cache becasue we just gave it the new page.
We deliberately don't ping the cache for every single content change. Imagine for a moment a site with 100k articles on pages that have a latest headlines module. All 100k pages change every time we post something new. For this reason we have a much more complex update strategy that takes into account article age and velocity. That's how we end up with the second scenario above.
Beyond that update !== purge. It would be really nice to be able to say please update and have the cache make an If-None-Match request rather than just purging what it has. (it would purge on a 404 or 410 response to the If-None-Match request).
I do like the idea of a standard update ping format. I also like the idea of a json file in a well known location listing all the amp caches. We could easily ping them all in parallel.
Another request - if there is a list of AMP caches provided it should include either the IP addresses or User-agent strings (or both) each one uses so we can tell who is requesting.
@jpettitt , if you use Google AMP Cache update-ping on every routine update of your pages, you're likely to trip up automatic abuse detection. Update-ping is not meant for routine publishing, it's a tool meant for extrodinary circumstances, such as a court order.
If you want, you can simply issue a GET against Google AMP Cache URL to refresh the page in the cache. If the page is not getting any user generated traffic, your GET will trigger an If-None-Match request back to your server, like a real user. If the page is receiving a steady stream of user-initiated requests, it will be quickly refreshed (based on your Cache-Control max-age) anyway.
@dknecht , consistent with what I said above about update-ping being a tool for extrodinary circumstances, I think publishers who implement it would prefer control over convenience. In particular, if update-ping fails on any of the caches, they would likely want to escalate the issue to customer support of the offending cache, so good debugging experience is important.
On the other hand, it might be interesting to have a publisher-facing API that enumerates all the compliant caches in the ecosystem, or returns URIs/handlers to copies of a given page in every cache, similarly to what Google AMP URL API does now for Google AMP Cache.
I think that integration in regular publishing flow is the only realistic way of using the API. Of course, CMSes will need to make sure to not trigger mass updates (e.g. when decorator templates change, as opposed to content changes).
I felt that a redirect ring is an elegant way to minimize efforts with publishers. Sure, we could add an additional API for discovery (Who would run that?) but it would be more complex for the publishers.
@vitaliybl We have a lot of logic in our system to manage caches. (our local one, our cdn, your cdn). Our publishers require that we not serve stale content. It's really important to them. It's not clear what cache headers the amp-cache actually honours. Perhaps documenting that would help us understand when we need to do a ping and when we can let it just expire.
Right now we have a couple of mechanisms, one time/age based when we set the max-age according the how long it is since the article was last modified. We also have an amp-analytics based velocity system that will refresh an article from source if it gets 100 AMP views before it's max-age (but no more than every 60 seconds). In all cases we only ping the amp-cache if the content has changed. Running 50+ sites, some very large, we're running at about 3% of quota for cache-purges right now.
FWIW the biggest trigger of updates is googlebot requesting the amp page. (we only purge our cache in that instance not the CDN cache).
@cramforce the api could be a simple json file in a well known location on cdn.ampproject.org that's managed in github. Caches could use it to figure out who to ping next in your ring scenario.
Perhaps we can split the baby here and have individual endpoint urls, in a well known location and have the default be a 302 ring. That way we could call each cache and just ignore the 302 response if we wanted to.
One other concern is scale, how many caches do you envisage existing? 302's are going to get fragile as the count grows (and we do see an occasion 502 error from the current cache). An explicitly articulated retry/backoff guideline would be helpful to avoid thrashing all the caches that are still working if one is dead.
@jpettitt Now, that does sounds like an API I could get behind :)
bump.
@cramforce is on vacation, unfortunately. He'll be back next month.
Folks on this thread have agreed on a design I believe.
Quick update.
So, we'll create https://cdn.ampproject.org/caches.json See #7259
It needs to be documented for the update-ping that clients should fetch that file to discover caches as a first step.
@cramforce from a deployment pov do we always want master HEAD of caches.json to be always deployed to prod every release?
@erwinmombay Lets manually deploy for now.
This issue seems to be in Pending Triage for awhile. @cramforce Please triage this to an appropriate milestone.
This issue seems to be in Pending Triage for awhile. @cramforce Please triage this to an appropriate milestone.
This issue seems to be in Pending Triage for awhile. @cramforce Please triage this to an appropriate milestone.
Closing bug as this is an AMP Cache specific. That project has received the feedback.