Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB - How to handle updates using adjacency list pattern?

So, in DynamoDB the reccomended approach to a many-to-many relationship is using Adjacency List Pattern.

Now, it works great for when you need to read the Data because you can easily read several items with one request.

But what if I need to update/delete the Data? These operations happen on a specific item instead of a query result.

So if I have thousands of replicated data to facilitate a GET operation, how am I going to update all of these replicas?

The easiest way I can think of is instead of duplicating the data, I only store an immutable ID, but that's pretty much emulating a relational database and will take at least 2 requests.

like image 820
Mojimi Avatar asked Dec 06 '25 04:12

Mojimi


1 Answers

Simple answer: You just update the duplicated items :) AFAIK redundant data is preferred in NoSQL databases and there are no shortcuts to updating data.

This of course works best when read/write ratio of the data is heavily on the read side. And in most everyday apps that is the case (my gut feeling that could be wrong), so updates to data are rare compared to queries.

DynamoDB has a couple of utils that might be applicable here. Both have their shortcomings though

  1. BatchWriteItem allows to put or delete multiple items in one or more tables. Unfortunately, it does not allow updates, so probably not applicable to your case. The number of operations is also limited to 25.
  2. TransactWriteItems allows to perform an atomic operation that groups up to 10 action requests in one or more tables. Again the number of operations is limited for your case

My understanding is that both of these should be used with caution and consideration, since they might cause performance bottlenecks for example. The simple way of updating each item separately is usually just fine. And since the data is redundant, you can use async operations to make multiple updates in parallel.

like image 110
kaskelotti Avatar answered Dec 08 '25 18:12

kaskelotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!