Graphql-engine: Best practices for caching hasura responses in redis?

Created on 4 May 2020  路  6Comments  路  Source: hasura/graphql-engine

I was wondering whether there are any officially recommended patterns for caching hasura responses to a redis instance.

Couldn't find any documentation/open issues/blog posts talking about this, here's what I have in mind:

  1. Run a core server (for caching, auth) alongside hasura as a microservice
  2. Add a middleware to intercept any graphql requests
  3. Check if the exact request exists in redis, if so return (or whatever caching logic)
  4. Otherwise, ask hasura microservice to generate a new response, cache that and then send to client
question supporneeds-action

Most helpful comment

Crazy feature idea for hasura: Let users set redis/cluster endpoints within hasura and allow users to specify caching behavior for given tables/relationships/queries => Boom. Automatic caching 馃く

All 6 comments

Crazy feature idea for hasura: Let users set redis/cluster endpoints within hasura and allow users to specify caching behavior for given tables/relationships/queries => Boom. Automatic caching 馃く

Just wondering if there is any guidance for caching for Hasura? In my particular use case, I have a remote schema that runs business logic on an Apollo GQL server running on serverless. Ideally I鈥檇 like Hasura to check Redis for the cached version and if there鈥檚 a hit, skip the call to the remote schema and return the Redis data.

At the moment, what I am planning to do is have Redis with Apollo (maybe I鈥檒l use Apollo鈥檚 inbuilt caching- will test it out) so the serverless function will have to execute but should only run for a fraction of the time it would otherwise as a cache hit will be the result 99% of the time.

As @AdityaAnand1 says above, it would be great to have Hasura manage the caching with Redis or some other method.

Any thoughts on whether this could be picked up soon?

@rikinsk @shahidhk @rakeshkky

A managed caching system on top of hasura would be a total killer! I see custom invalidation rules with built in triggers

Unfortunately that this feature is available only on Hasura Cloud. :/ Hope that open source version still able to attach caching middleware or gateway.

https://hasura.io/docs/1.0/graphql/cloud/response-caching.html

@jukbot According to https://hasura.io/docs/1.0/graphql/cloud/response-caching.html there's a few gotchas there, namely

  1. The query does not make use of remote schemas or remote joins
  2. The query and any related user permissions do not make use of session variables

I use both points heavily so I am not sure I'll get any benefit out of Hasura Clouds caching vs the free version. I hope over time these are supported as I would probably head to Hasura Cloud if so (but ideally they are in the open source version too).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cpursley picture cpursley  路  3Comments

revskill10 picture revskill10  路  3Comments

sachaarbonel picture sachaarbonel  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

shahidhk picture shahidhk  路  3Comments