Search code examples
firebasecachingcdnfirebase-hosting

Firebase Hosting CDN Cache not distributing across all regions


Caching a static page in one region doesn't distribute across other regions. Our server is located in Europe-West3 (Franfkurt, Germany). When we cache a static page, it only hits cache when we visit the website from Germany. Other countries don't hit the cache and they create their own version in their region, which is not distributed across other regions. We aren't setting any cookies, vary headers or anything that has to do with creating a cache key.

Our goal is to create cache from a region we are currently in and spread the created cache across other regions, which Firebase Hosting CDN usually does out of the box (as mentioned in an article - https://firebase.blog/posts/2022/03/firebase-hosting-origin-servers-europe-asia).

When you deploy your site, Firebase Hosting replicates your content in the United States and on origin servers located in Europe and Asia. Before this launch, if content was not in the CDN cache, the request would be routed all the way back to the single origin server in the US.


Solution

  • In Firebase Hosting's caching model nothing is every automatically pushed to the CDN. The flow is always that the client requests a URL from an edge server of the CDN. If that server doesn't have the file for that URL, it requests it from the closest origin server, stores it with the cache headers the origin returned, and returns it to the client.

    So it's expected behavior that origin servers will see multiple requests for the same content.