Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Idempotency Concern in CartDBStreamHandler Function #67

Open
NullPointer4096 opened this issue Apr 16, 2023 · 0 comments
Open

Idempotency Concern in CartDBStreamHandler Function #67

NullPointer4096 opened this issue Apr 16, 2023 · 0 comments

Comments

@NullPointer4096
Copy link

Description:
I would like to kindly bring attention to a potential issue with the CartDBStreamHandler function, which is used to change the quantity of items in the shopping cart stored as records in DynamoDB. The function operates by iterating through each pair of (item, quantity delta) in quantity_change_counter and using DynamoDB’s UpdateExpression : "ADD … to change the absolute quantity stored in the table. However, this method is not idempotent. Suppose when the function is invoked for the first time, x is added to the absolute quantity of itemA. If the function crashes and retries, x more items will be added to the record. This is undesirable, as it duplicates the user's action of adding items to the cart if untimely retries ever happen.

Suggested Fix:
To address this issue, please consider adding a LastRequestId field to the record that stores the most recent lambda's request id, which is constant across retries. Then, use a condition expression along with the update expression; specifically, apply the quantity change and update the LastRequestId field only if context.aws_request_id != item.LastRequestId. This approach should help ensure idempotency and improve the reliability of the at-least-once executed CartDBStreamHandler function.

Closing Remarks:
I appreciate your attention to this matter and hope that my suggestion proves helpful in enhancing the reliability of the CartDBStreamHandler function. Thank you for considering this feedback, and please don't hesitate to reach out if you have any questions or concerns.

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

1 participant