Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an application cache for REST API #9111

Closed
xin-hedera opened this issue Aug 22, 2024 · 0 comments · Fixed by #9626
Closed

Add an application cache for REST API #9111

xin-hedera opened this issue Aug 22, 2024 · 0 comments · Fixed by #9626
Assignees
Labels
citus Area: Citus enhancement Type: New feature performance rest Area: REST API
Milestone

Comments

@xin-hedera
Copy link
Collaborator

xin-hedera commented Aug 22, 2024

Problem

There are many times that the same request from different sessions all hit our REST server even though cloud CDN is enabled and the responses have proper cache control header set.

There are also periodic high rate of response code 304 from our REST server because some clients will issue a HEAD request with cache id to probe if the cache is still valid. Due to lack of head handler in our js REST module, it ends up to go though the get handler and query data, then expressjs learns the cache is still valid, zeros out the response body and sends a 304 response.

We should add a application layer cache to handle such scenarios so the rest server doesn't unnecessarily go to the database for the data.

Solution

  • Add logic in response handler middleware to cache responses in redis
    • we can use the hash of the request as the key
    • we should set the cache ttl the same as how it's configured by path in the response cache-control header
  • Add a middleware before any of the handlers to check if the request url has a cached response, and if so, respond with the cached response and terminate the request handling

Alternatives

No response

@xin-hedera xin-hedera added enhancement Type: New feature performance rest Area: REST API labels Aug 22, 2024
@xin-hedera xin-hedera self-assigned this Aug 22, 2024
@xin-hedera xin-hedera added this to the 0.113.0 milestone Aug 22, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Mirror Node Aug 22, 2024
@steven-sheehy steven-sheehy moved this from 📋 Backlog to 👷 In progress in Mirror Node Aug 22, 2024
@jascks jascks assigned jascks and unassigned xin-hedera Aug 23, 2024
@jascks jascks linked a pull request Aug 27, 2024 that will close this issue
2 tasks
@steven-sheehy steven-sheehy added the citus Area: Citus label Aug 30, 2024
@steven-sheehy steven-sheehy modified the milestones: 0.113.0, 0.114.0 Sep 2, 2024
@steven-sheehy steven-sheehy modified the milestones: 0.114.0, 0.115.0 Sep 15, 2024
@steven-sheehy steven-sheehy modified the milestones: 0.115.0, 0.116.0 Sep 29, 2024
@xin-hedera xin-hedera self-assigned this Oct 9, 2024
@steven-sheehy steven-sheehy assigned jnels124 and unassigned xin-hedera and jascks Oct 10, 2024
@steven-sheehy steven-sheehy modified the milestones: 0.116.0, 0.117.0 Oct 13, 2024
@steven-sheehy steven-sheehy modified the milestones: 0.117.0, 0.118.0 Oct 28, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Mirror Node Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
citus Area: Citus enhancement Type: New feature performance rest Area: REST API
Projects
Status: Done
4 participants