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

DynamoDB - Respect lineage #422

Merged
merged 4 commits into from
Jun 27, 2024
Merged

DynamoDB - Respect lineage #422

merged 4 commits into from
Jun 27, 2024

Conversation

Tang8330
Copy link
Collaborator

@Tang8330 Tang8330 commented Jun 27, 2024

There is an edge case with DynamoDB where if the same record appeared in two different DynamoDB shards (parent -> child), we are processing them in parallel as opposed to sequentially.

This is mainly an issue if a DynamoDB stream hasn't been consumed in a while since shards are records and time based.

Per SDK docs:

Because shards have a lineage (parent and children), an application must always process a parent shard before it processes a child shard. This helps ensure that the stream records are also processed in the correct order. (If you use the DynamoDB Streams Kinesis Adapter, this is handled for you. Your application processes the shards and stream records in the correct order. It automatically handles new or expired shards, in addition to shards that split while the application is running. For more information, see Using the DynamoDB Streams Kinesis adapter to process stream records.)

@Tang8330 Tang8330 marked this pull request as ready for review June 27, 2024 16:17
@Tang8330 Tang8330 added the bug Something isn't working label Jun 27, 2024
if parentID := shard.ParentShardId; parentID != nil {
// If the parent shard exists, is it still being processed? If so, let's wait a bit and then retry.
// We must process the parent shard first before processing the child shard.
if s.storage.GetShardProcessing(*parentID) && !s.storage.GetShardProcessed(*parentID) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the parent hasn't started processing yet? Is that possible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm interesting. I think we need to sort the shards that are returned since there's no guarantee it's ordered

@Tang8330 Tang8330 merged commit d7ff7f6 into master Jun 27, 2024
3 checks passed
@Tang8330 Tang8330 deleted the ddb-respect-lineage branch June 27, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants