Description:
I would like to kindly bring attention to a potential issue with the ProcessAnswersStreamFunction, which is invoked when incoming star rating answers or geo answers enter the DynamoDB through either ProcessAnswerStarFunction or ProcessAnswerGeoFunction. In the star.updateQuestionsTable and geo.updateQuestionsTable methods, the program uses the Dynamo’s ADD UpdateExpression to change the absolute count of star rating answers or geo answers. However, this implementation is not idempotent. Suppose when the function is invoked, the star rating of a specific answer is increased by 1; if the function crashes and retries, the star rating will be increased again by 1. This is not desired, as it duplicates the user's action (starring the answer) at untimely retries.
Suggested Fix:
To address this issue, please consider adding a LastRequestId
field to the record that logs the most recent lambda's request id, and use a ConditionExpression along with the original ADD UpdateExpression. Specifically, only if context.aws_request_id != item.LastRequestId
, apply the star rating change and update the LastRequestId
field. This approach should help ensure idempotency and improve the reliability of the ProcessAnswersStreamFunction since the request id is constant across retries.
Thank you for considering this issue. I hope my suggestion proves helpful in enhancing the reliability and idempotency of the ProcessAnswersStreamFunction. Please don't hesitate to reach out if you have any questions or concerns.