Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction Strategies for DynamoDB in Spring

What would be the most appropriate way to enable transactionality of multi-operation updates on AWS DynamoDB in a Java Spring application?

AWS' DynamoDB is atomic only on a per-row update. I have a requirement to maintain secondary indices as separate tables, so I'd insert the 'main' row in the main table, and then insert a row into the secondary index table. If the second insert fails, I'd like to 'roll back' the first, in order to keep my data consistent. DynamoDB doesn't have any native support for transactions or rollbacks.

I'm familiar with using a Spring transaction manager when working with JPA datasources like Hibernate, but I'm not sure what the best approach to implementing my own transaction-management code would be.

like image 911
EngineerBetter_DJ Avatar asked Oct 22 '22 06:10

EngineerBetter_DJ


1 Answers

We have a similar requirement. What we are adopting is a "polyglot" approach. That is to keep the transactional part, your main table, in a relational database. Only update your secondary indices in DynamoDB after a transaction is committed in the main table.

like image 119
user1786434 Avatar answered Oct 27 '22 11:10

user1786434