Race condition in Amazon DynamoDB Streams Lambda Trigger

0

In Amazon DynamoDB Streams, when similar entries are added simultaneously to a DynamoDB table and you have a Lambda function processing the stream to count the number of events, is there a possibility of a race condition. will this condition occur if both similar entries are processed by the Lambda function at the same time? How can I make sure this race condition never happens?

2 Answers
2

DynamoDB Streams guarantees exactly once deliver of all mutations to items in the table. This is done by using the internal log sequence number in DynamoDB which is unique to every modification.

While it may seem that both mutations happened at the same time on the client side, each of those mutations carry a unique log sequence number, which ensures they all make it to the stream exactly once.

Exactly once delivery:

PUT item (LSN=001) on stream ONLY IF item (LSN=001) NOT EXISTS

Item ordering:

PUT item (LSN=002) on stream ONLY IF item (LSN=001) EXISTS

Streams and their behaviour is documented here

profile pictureAWS
EXPERT
answered 6 months ago
0

A DynamoDB stream is an ordered flow of information about changes to items in a DynamoDB table. When you enable a stream on a table, DynamoDB captures information about every modification to data items in the table.

Whenever an application creates, updates, or deletes items in the table, DynamoDB Streams writes a stream record with the primary key attributes of the items that were modified. A stream record contains information about a data modification to a single item in a DynamoDB table. You can configure the stream so that the stream records capture additional information, such as the "before" and "after" images of modified items.

DynamoDB Streams helps ensure the following:

Each stream record appears exactly once in the stream.

For each item that is modified in a DynamoDB table, the stream records appear in the same sequence as the actual modifications to the item

See : https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html

profile pictureAWS
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions