Simon
Simon

Reputation: 63

Keeping duplicated DynamoDB records synchronized

I am currently trying to model the data for our application. The data consists of identities and groups. One group can have multiple identities and one identity can be in multiple groups. (a typical many-to-many relationship).

data model

So I have used the Adjacency List Design Pattern to structure my data as recommended by AWS: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html

I keep all the info about identities duplicated inside the groups and reading the data works just fine - a normal query for the details and a query against the index to get the relations of my objects.

How can I ensure that all duplicated records have the same value? Every time the group changes, I am updating all the duplicated group records in the database. I am okay with updating multiple records at once as changes will happen rarely but I want to avoid inconsistent data.

All the tutorials and guides always just talk about reading and accessing data not about updating the data.

I know that there is a TransactWriteItem-Reuquest but it is limited to 25 items maximum. So is there another way/pattern to guarantee that all my identity records are updated when e.g. the name changes.

Upvotes: 2

Views: 560

Answers (1)

Mike Dinescu
Mike Dinescu

Reputation: 55760

You have to decide for yourself how consistent is consistent enough in your application.

The CAP theorem is alive and well and it says that to get availability and partition tolerance we have to sacrifice consistency.

Since updates happen infrequently, how does your application fail if it sees inconsistent records? If you can't use the transactional API because of the 25 item limit, maybe you could roll your own "lock-out" using an attribute you would set on items that must all be updated together:

  • first, you identify all items that need to be updated and set the "lock_out" attribute on them (this can be a timestamp indicating when the lock_out expires)
  • in your application, you can add business logic to treat items with the "lock_out" in a way that makes sense (maybe show them as being updated, or not show them at all etc.)
  • update the items
  • after the update is complete, clear the "lock-out" attribute

Upvotes: 0

Related Questions