3

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.

Mojimi
  • 2,561
  • 9
  • 52
  • 116

1 Answers1

1

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.

kaskelotti
  • 4,709
  • 9
  • 45
  • 72
  • 1
    Thank you, I was actually aware of the API limitations. I think the only way is to calculate the costs of having to do two requests to get the related info on every read versus doing several requests to update the duplicated info on every update/delete. – Mojimi May 08 '19 at 11:54