telescope
telescope copied to clipboard
Add appropriate cache headers to microservices, cache them in nginx
In production we have our services running behind nginx, and it's amazing at caching. If we set the appropriate cache headers (e.g., cache-control
, etag
, etc), nginx and the users' browsers will improve performance by caching everything.
Some resources:
- https://restfulapi.net/caching/
- https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers
We can either do this manually in each service, or we could add some helper middleware in Satellite to allow each microservice to opt-in to various types of caching.
You can see how we do the caching for various things in nginx now: https://github.com/Seneca-CDOT/telescope/blob/master/config/nginx.conf.template#L173-L230.
See also https://github.com/Seneca-CDOT/telescope/blob/master/config/nginx.conf.template#L127-L133 and https://github.com/Seneca-CDOT/telescope/blob/master/config/nginx.conf.template#L233-L244 for how we do the nginx caching for the Telescope 1.0 backend. We'd need something similar for the API server definition https://github.com/Seneca-CDOT/telescope/blob/master/config/nginx.conf.template#L152-L164.
#1978 adds cache headers for the status service.
I might just make a module in Satellite that will add headers onto the passed Response object, I'll add in a test specifically for Cache-Control
@Metropass there are npm modules that will do this, we could research one and use it.
I found this, it might be useful specifically for Cache-Control
, I'm currently researching a module that will work for any type of CORS headers.
https://www.npmjs.com/package/http-cache-semantics
I don't think that module will help us here. I'm also not 100% sure we need to do anything special in Satellite for this: we just need to specify headers on a per-route basis in each microservice.
If we later find out that there are common patterns, we can extract them into something generic in Satellite; but let's not start there.
@aserputov, what is your progress related to this?
@JerryHue work in progress.
@JerryHue I think we should move this one too.