Skip to content

Conversation

danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented Apr 14, 2025

Closes #324

By default, the AWS SDK uses eventual consistency for reads. However, from the beginning, the DynamoDB persister has opted for consistent reads to ensure that saga data is always retrieved in its most up-to-date form. This provides safety and correctness, especially when using optimistic concurrency—but comes at the cost of twice the read capacity units compared to eventual consistency.

This PR introduces a global configuration option that allows customers to opt into eventual consistent reads for saga data when using optimistic concurrency. This gives users more flexibility to trade off consistency for cost savings. In scenarios where eventual consistency is acceptable, this can help reduce DynamoDB read costs, although it may increase the likelihood of immediate or delayed retries if version mismatches occur.

Note: This setting only applies to optimistic concurrency. For pessimistic concurrency, eventual consistent reads are not supported, as the concurrency mechanism relies on obtaining an up-to-date record via a conditional update (lease), which requires consistent reads.

Documentation: https://docs.particular.net/persistence/dynamodb/sagas#saga-concurrency-pessimistic-locking-configuration

@danielmarbach danielmarbach self-assigned this Apr 14, 2025
@danielmarbach danielmarbach force-pushed the eventual-consistent-reads branch 2 times, most recently from ac49b2b to 35c2b6d Compare April 15, 2025 08:59
@danielmarbach danielmarbach changed the title Spike eventual consistent reads Add support for eventual consistent reads on sagas Apr 15, 2025
@danielmarbach danielmarbach force-pushed the eventual-consistent-reads branch from 35c2b6d to 8fcdcc2 Compare April 15, 2025 09:29
@danielmarbach danielmarbach marked this pull request as ready for review April 15, 2025 09:45
@danielmarbach danielmarbach force-pushed the eventual-consistent-reads branch from 8fcdcc2 to 4e5a048 Compare April 15, 2025 09:47
@danielmarbach danielmarbach added this to the 2.1.0 milestone Apr 15, 2025
Copy link

@lailabougria lailabougria left a comment

Choose a reason for hiding this comment

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

I'd probably go for UseEventuallyConsistentReads

@danielmarbach danielmarbach enabled auto-merge (squash) April 17, 2025 11:53
@danielmarbach danielmarbach merged commit 124b0b5 into main Apr 17, 2025
4 checks passed
@danielmarbach danielmarbach deleted the eventual-consistent-reads branch April 17, 2025 12:06
@mauroservienti mauroservienti changed the title Add support for eventual consistent reads on sagas Add support for eventual consistent reads on sagas with optimistic concurrency to reduce read operations Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider supporting inconsistent reads for saga lookups

2 participants