Search code examples
cdnapi-gateway3scale

Should I manage my cache control headers in each app or in the api gateway?


This is a design/architecture best practice question.

I've been asked to put a CDN in front of an API Gateway. I am very new to CDN.

Provide Cache instructions within responses and instruct the CDN on caching.

From my perspective I have two options.

  1. My api gateway supports header injection policies. Add the cache control policies here by configuration by the developer based on what they know about how their api works.

  2. Ask every single app behind the gateway to implement add their cache control headers.

I'm looking for opinions on how best to implement these requirements given the options above.

My initial thoughts is that the cache control might be best managed at the gateway by configuration. i.e. During CD process the developer configures an api policies configuration file to be deployed based on what they know about how their api works.

thanks


Solution

  • My suggestion is to follow what you were already leaning for, so let the API developers configure the cache control policies on the API gateway, because they might now best what is the backend like and what information needs and needs not to be cached.

    Let me just add also that for 3scale, the API Gateway will soon include some caching capabilities itself (https://github.com/3scale/APIcast/tree/master/gateway/src/apicast/policy/content_caching ) although you might still want to adopt the CDN caching capabilities if the traffic is not geographically routed to several distributed gateways.