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

[BUG] The function in aws-node-express-dynamodb-api is not idempotent #657

Open
Nsupyq opened this issue Nov 2, 2021 · 4 comments
Open

Comments

@Nsupyq
Copy link
Contributor

Nsupyq commented Nov 2, 2021

The function of writing username in index.js under aws-node-express-dynamodb-api is not idempotent and may cause data inconsistency.

try {
  await dynamoDbClient.put(params).promise();
  res.json({ userId, name });
}

Assuming two concurrent functions want to change the user name with the same userId. When one of them fails after executing dynamodb_client.put, AWS Lambda will retry it and change the user name again. Then the client will see the username is changed between two different names repeatedly even if there are only two functions changing the name. This should not happen if every function is executed only once and causes data inconsistency.

This can be fixed by making the function idempotent. DynamoDB has provided an idempotent write operation called TransactWriteItems. Replacing dynamodb_client.put with it can fix the idempotence bug. Users need to provide a unique client token to be the parameter of TransactWriteItems API. which helps DynamoDB to determine whether the incoming write is a retry.

@pgrzesik
Copy link
Contributor

pgrzesik commented Nov 2, 2021

Hello @Nsupyq, thanks for reporting, would you like to submit a PR with such improvement?

@Nsupyq
Copy link
Contributor Author

Nsupyq commented Nov 2, 2021

Ok, I will submit a PR soon.

@pgrzesik
Copy link
Contributor

pgrzesik commented Nov 2, 2021

Thank you @Nsupyq 🙇

@Nsupyq
Copy link
Contributor Author

Nsupyq commented Nov 2, 2021

Hello @pgrzesik, I have submitted a PR #658 with such improvement.

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

No branches or pull requests

2 participants