Skip to content

Feature request: add local cache to Idempotency persistence layer #1299

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

Closed
1 of 2 tasks
saragerion opened this issue Feb 17, 2023 · 1 comment · Fixed by #1396
Closed
1 of 2 tasks

Feature request: add local cache to Idempotency persistence layer #1299

saragerion opened this issue Feb 17, 2023 · 1 comment · Fixed by #1396
Assignees
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility idempotency This item relates to the Idempotency Utility

Comments

@saragerion
Copy link
Contributor

saragerion commented Feb 17, 2023

Use case

To improve performance, the Idempotency utility can be configured to use a local cache to store idempotency records.

Solution/User Experience

import { IdempotencyConfig } from '@aws-lambda-powertools/idempotency';

const config = new IdempotencyConfig({
  useLocalCache: true,
});

Optionally, the user can also set a max number of items to store in the cache before older ones start get evicted:

import { IdempotencyConfig } from '@aws-lambda-powertools/idempotency';

const config = new IdempotencyConfig({
  useLocalCache: true,
  localCacheMaxItems: 10, // defaults to 256
});

Use the Python implementation as reference and extend the BasePersistenceLayer.

The IdempotencyConfig class already supports the useLocalCache field. The localCacheMaxItems one is not yet implemented and should default to 256.

Below comments from @dreamorosi:

Contrary to Python, Node.js doesn't have a LRU Cache in its standard library. Looking at popular libraries there seem to be two options:

  • lru_map 3.7M weekly downloads - last published 3 yrs ago - 27.9 kB unpacked size
  • lru-cache 123M weekly downloads - last published 2 days ago - 638 kB

Both libraries appear to be extremely popular. The former, lru_map is a lot less popular than the other and hasn't been updated in a long time, however it has a small footprint when compared to the other alternative.

In terms of features, the lru-cache module has a wide range of features like TTL, retrieval functions from remote, etc. - all these features contribute to the significant size. On the other hand, lru_map only supports one config/feature: the ability to set a maximum of items to keep in the cache.

Our currently published Powertools utilities range between 70 and 110 kB. Given that lru_map supports exactly the features that we need, has zero dependencies, and a relatively stable implementation, I'm inclined to recommend this module over the other larger and more feature complete one.

Alternative solutions

No response

Acknowledgment

@saragerion saragerion added triage This item has not been triaged by a maintainer, please wait feature-request This item refers to a feature request for an existing or new utility labels Feb 17, 2023
@saragerion saragerion added this to the Idempotency - Beta release milestone Feb 17, 2023
@saragerion saragerion added the idempotency This item relates to the Idempotency Utility label Feb 17, 2023
@dreamorosi dreamorosi added discussing The issue needs to be discussed, elaborated, or refined and removed triage This item has not been triaged by a maintainer, please wait labels Feb 17, 2023
@dreamorosi dreamorosi changed the title Feature request (idempotency): Custom Config - Locally cache idempotency results Feature request: Custom Config - Locally cache idempotency results Feb 17, 2023
@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation and removed discussing The issue needs to be discussed, elaborated, or refined labels Mar 18, 2023
@dreamorosi dreamorosi changed the title Feature request: Custom Config - Locally cache idempotency results Feature request: add local cache to Idempotency persistence layer Mar 20, 2023
@dreamorosi dreamorosi self-assigned this Apr 3, 2023
@dreamorosi dreamorosi moved this from Backlog to Working on it in AWS Lambda Powertools for TypeScript Apr 5, 2023
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in AWS Lambda Powertools for TypeScript Apr 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2023

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release This item has been merged and will be released soon label Apr 7, 2023
@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon confirmed The scope is clear, ready for implementation labels Apr 7, 2023
@dreamorosi dreamorosi moved this from Coming soon to Shipped in AWS Lambda Powertools for TypeScript Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility idempotency This item relates to the Idempotency Utility
Projects
None yet
2 participants