user1533201
user1533201

Reputation: 1

Dynamodb many to many relationship with strong consistency

One issue with GSI is the eventual consistency issue. So how to design a many-to-many relationship with strong consistency.

Say i have a partitionkey as customerid and sortkey as accountnumber

And a gsi on accountnumber

After inserting the record i need to support a lookup by accountnumber also.

But with gsi on accountnumber i can run into race condition that then lookup by accountnumber my not return results

So what to do? How to solve for many to many relationship with strong consistency?

Ref doc -https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html

Upvotes: -1

Views: 53

Answers (1)

hunterhacker
hunterhacker

Reputation: 7142

The GSI is a convenience allowing you to do one insert and get two items (one in the base table, one in the index).

You can instead drop the GSI and insert the two items yourself (one to the base table, another with different keys to a different base table that replaces the GSI) and you can use a transaction on the write to get strong consistency.

Upvotes: 0

Related Questions