Search code examples
geolocationcdn

cdn: proxy request to specific origin based on ip geolocation


I have a service with a few origin servers, each in a different continent. Every client request goes through a cdn that proxies to these servers. About half of requests are cacheable and the other half are not. It doesn't matter much which of the origins serves the cacheable responses because the distributed CDN will handle serving that response from the closest possible POP for those requests in the future (until cache expiration). However, for uncacheable responses, I'd like for the closest origin to the user to respond to requests that the CDN is proxying.

Is there such a feature that some CDNs have whereby you can specify something like: "make a best effort to geocode the request based on ip, if the ip is from continent north america use noram.originfoo.com, if the ip is from continent europe use eu.originfoo.com, etc"?

Maybe the architecture should instead be that DNS resolution chooses a CDN hostname based on the client ip and the CDN has different entries whereby one region specific-CDN hostname maps to one origin hostname.


Solution

  • Take a look fastly CDN solution. It uses varnish and allows for vcl rules to be used by the customer (see their docs). Here's a guide that appears to be doing what you need:

    Fastly allows you to change origin servers based on the user's geographic location. This is useful when you need to serve different content to users who are in different locations. For example, you could change origin servers to serve a restricted version of your website to users in a different country.