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

API responses can't be cached #26

Closed
andreogle opened this issue Jul 9, 2020 · 6 comments
Closed

API responses can't be cached #26

andreogle opened this issue Jul 9, 2020 · 6 comments
Labels
long-term Not an urgent requirement node About the @airnode/node package

Comments

@andreogle
Copy link
Member

andreogle commented Jul 9, 2020

Description

API calls may or may not be idempotent so the API provider might not want to make duplicate API calls between serverless function invocations while the transaction is pending. The API response needs to be optionally cached.

The cache should store the following information against the requestId:

  1. The raw value extracted from _path or the error
  2. The timestamp
  3. The status boolean - either successful or failure.

Cache keys need to have an expiration mechanism too.

Before making an API call, the cache should be checked for the requestId. If a value is found, skip making that call and attempt another transaction with that value.

API calls should default to cached if a cache is configured. Otherwise, a new call should be made each serverless invocation.

Questions

  1. How exactly to implement the cache. What AWS service to use etc.
  2. When should the cache key be cleared? If a requestid exists in the cache, but no unfulfilled request is found?
@andreogle andreogle added the node About the @airnode/node package label Jul 9, 2020
@bbenligiray
Copy link
Member

2 is very possible with something like a block reorg. We can safely let them expire on their own.

@bbenligiray bbenligiray added discussion Open ended discussion about a feature/problem long-term Not an urgent requirement labels Oct 7, 2020
@bbenligiray
Copy link
Member

bbenligiray commented Oct 7, 2020

One option we have for this is to call the API through a gateway and let it handle the caching (AWS can go up to an hour)
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html
The issue here is that how reliable the cache is (because an unexpected cache miss would mean a duplicate API call).

The obvious solution is to use a NoSQL database, cache by requestId and expire each item in an hour.

Note that both solutions are cloud provider-specific.

@MrAngus666
Copy link
Contributor

An implementation that supports the AWS, Azure and GCP can use the redis services that are provided as a service on the three providers:
https://cloud.google.com/memorystore
https://azure.microsoft.com/en-us/services/cache/#overview
https://aws.amazon.com/elasticache/redis/

We will have code specific for each provider but at the end it is the same core product, redis, using it as as key, value pair.

@bbenligiray
Copy link
Member

This will be easier to implement if we migrate to bare Terraform, which is currently being worked on

@bbenligiray
Copy link
Member

We'll probably not support this for the containerized version (at least initially)

@bbenligiray bbenligiray removed the discussion Open ended discussion about a feature/problem label Aug 23, 2021
@bbenligiray bbenligiray changed the title Caching API responses API responses can't be cached Aug 23, 2021
@bbenligiray
Copy link
Member

0.7.0 allows caching in the global scope with no hard guarantees. Closing this issue in line with the changes in how we use Github issues internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
long-term Not an urgent requirement node About the @airnode/node package
Projects
None yet
Development

No branches or pull requests

3 participants