Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Improve API performance with a cache #26

Open
RadW2020 opened this issue Apr 5, 2021 · 2 comments
Open

Improve API performance with a cache #26

RadW2020 opened this issue Apr 5, 2021 · 2 comments

Comments

@RadW2020
Copy link

RadW2020 commented Apr 5, 2021

API responses speed could be dramatically increased if a memory cache like REDIS is implemented.
What do you think about this?
I could give a hand if you need it
https://redis.io/topics/client-side-caching

@tarwin
Copy link
Contributor

tarwin commented Apr 6, 2021

Without adding new hardware (for the time being) would it be easier to add caching on calls to resources that don't change often but are requested often?

For example we could cache the feed query for even 10 seconds, in memory (JS). We don't really want people sitting there updating the feed more than every 10 seconds anyway right?

We could even add this to random feed which I'm sure would save a LOT of bandwidth. Why update it on each call? 10-30 seconds would be fine to give people time to actually look through the items returned.

All that said it looks like there is some code in a pull request to do some caching, although I don't quite understand it yet? Or at least some throttling.
#15

There also seems to be code in the main branch that has been commented out that looks like it was meant to do some caching but unsure as it seems incomplete.

@wyc
Copy link

wyc commented Jun 11, 2021

I think this could improve the page load time by 15s, or almost 10x. The opportunity is that fetching here is currently uncached:
https://github.com/hicetnunc2000/hicetnunc-api/blob/master/lib/router/readFeed.js#L7

For example, this link:
https://51rknuvw76.execute-api.us-east-1.amazonaws.com/dev/featured?counter=0&max_time=1623454080000

So there are two ways forward if we want to cache.
(1) Add a CloudFront caching layer in front of the Lambda function, caching on the GET request.
(2) Instrument application-level caching using Elasticache or Redis with the route itself.

Here's a good tutorial on caching options with Lambda functions on AWS: https://theburningmonk.com/2019/10/all-you-need-to-know-about-caching-for-serverless-applications/

Engineering considerations:

  • What timeout is good for the front page? I think we can reuse the OBJKTs cache.
  • What other opportunities to cache are there?

17s load, 15s of it from that JSON query:
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants