You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
The function of writing username in index.js under aws-node-express-dynamodb-api is not idempotent and may cause data inconsistency.
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.The text was updated successfully, but these errors were encountered: