Fastly Surrogate Keys: A Better Way to Purge API Caches
Caching API responses at the edge sounds great until you hit the invalidation problem. A TTL that's too short and your origin keeps getting hammered, too long and your users see stale data for who knows how long. If what you're looking for is to cache aggressively and purge surgically, the moment something changes and only what changed, there's a solution for that. Spoiler alert: the usual AWS suspects don't really compete here.
Putting your API behind Fastly
The setup is the usual reverse proxy dance: you create a Fastly service, point it to your API as the origin (or "host"), and move your DNS to Fastly. From that moment on, every request goes through their points of presence (POP) and cacheable responses get stored close to your users.
Now that caching is set up, what about the "fine-grained purging controls"? This is where the Surrogate-Key headercomes in....
Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE