Edgar C Garzon
Edgar C Garzon

Reputation: 51

DynamoDB Many-to-Many relations

I have a problem modeling my data in DynamoDB. My APP creates notes with the possibility to share a note with other user and allow the other user to update the Note (as done by https://keep.google.com/).

As I need to share notes between users, I decide that my primary table key will be the identifier of a Note.

Then I come with the following data-model for my DynamoDB tables:

The "Type" will indicate if it is the BODY of the note (where information regarding the note will be save) or an identifier that indicate if the note has been shared with other user.

enter image description here But I do have a problem: I use the secondary global key to retrieve all the notes for a user.

Once I have the list of noteId(s), I will enquiry my primary table to get all shared-notes for the user (as the notes for the user are already present in the SGK).

However, for doing this I need to use the function: "BatchGetItem".

The problem is that it is only allow to get 100 items and 16MB data.

In case of more than 100 shared-notes I have to call this functions several times. Moreover in case the data exceeds 16MB I need to implement a mechanism to read the rest of the requested data.

This operation could get really slow depending on the data size and number of shareId.

As you can imagine this is easily solved using a RDB and "join".

But the idea here is to use DynamoDB.

Data Access patterns:

Any ideas of how I can change my data-model to improve the access pattern to read all notes?

Upvotes: 0

Views: 107

Answers (1)

dariusjs
dariusjs

Reputation: 31

Modelling your schema to utilise item collections will allow you to use the Query API which does not have a limit of items returned except a 1MB limit that still needs to be paged through.

Upvotes: 2

Related Questions