Suggestion : Update multiple items based on a common query

0

One of the biggest difficulties I had was when I needed to model a many-to-many using the adjacency list pattern.

Ok, you duplicate the data, the queries are fast and efficient, but what if I need to update the data and keep all replicas in sync? As far as I know, the API does not support doing a update with "begins_with" on the sort key.

Basically I wanted to be able to do the following pseudo query :

UPDATE WHERE PK="user_001" AND SK="invoice_001" SET INVOICE_NAME="Invoice One"

In the end I realized that doing a batch update was far more expensive than simply doing two requests and emulating a SQL foreign key.

mojimi
질문됨 5년 전1176회 조회
4개 답변
1
수락된 답변

The idea with the Adjacency List Pattern is to distribute data that is immutable or does not change frequently. What we are looking to produce are aggregations of items that are related to each other by querying either the partitions or reverse lookup index. When you need to query for mutable attributes then you should setup the sort key so that the table/index query is delivering the entity item as well as relationship or edge items that are relevant to the query. This pattern works very well with a directed graph. For undirected graphs full denormalization is often required, and when this occurs it is most common to fully duplicate items in some way which includes data that might be updated. When this is the case the best option is to ensure the duplicated items can be efficiently queried and then use batchPutItem calls to clobber the duplicates. This is usually more efficient than trying to update each one. If the rate of change on the denormalized data is high then this is not the right pattern for the workload and we should look at optimizing for the write instead of the read.

RickH
답변함 5년 전
profile picture
전문가
검토됨 한 달 전
0

Thanks for the suggestion! To confirm I understand, you are looking to update a common attribute that is duplicated to multiple items that have the same partition key (or sort key?). Is that right?

Edited by: ArturoAtAWS on May 9, 2019 9:25 PM

답변함 5년 전
0

Yes! This is to help maintaining replicated data updated.

As Rick Houlihan masterfully explains it in his video here : https://www.youtube.com/watch?v=HaEPXoXVf2k , to make queries more efficient you're often duplicating data in many-to-many relationships, but he never explains it how to maintain the replicas.

And also I make a mistake in my example pseudo query, the correct way would be :

UPDATE WHERE PK="user_001" AND SK.BEGINS_WITH("invoice_") SET user_name="User one"
mojimi
답변함 5년 전
0

Thank you Rick, I understand your point of view.

I just wish DynamoDB was more friendly/batteries-ready with common case scenarios and community/industry standards for developers.

I like what the guys at FaunaDB are doing, they are taking a similar technology to DynamoDB and abstracting it as a "relational" database for the developers that don't care what's happening under the hood, but they still fall short on availability, documentation and pricing.

I understand this might not be the direction DynamoDB wants to go, but it would make it more accessible and all-around for medium-sized projects that have a few or sometimes a single full stack developer.

mojimi
답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠