socket_var
socket_var

Reputation: 1093

DynamoDB hierarchical one-to-many update-friendly pattern

I have heirarchical data that need to support CRUD operations on all levels. I have seen patterns like composite key with hash bangs mentioned in https://www.alexdebrie.com/posts/dynamodb-one-to-many/#composite-sort-keys-with-hierarchical-data , this is very smart for retrieving things but it doesn't seem efficient enough for updating things.

For example if I have to update a country name which has 50 states and those 50 states have 50 cities, the I need to update a whooping 2500 records just to update the country name. Same goes with updating a state name which needs 50 records to be updated.

A reasonable alternative to this seems to be maintaining Global Secondary indices for states and cities apart from a primary partition key on country. Is that the best way or am I missing a better approach?

Bonus: I need the best update-friendly approach for not just a 3 level heirarchy but a 4 or 5 or potentially a n level hierarchy

Upvotes: 0

Views: 159

Answers (1)

Charles
Charles

Reputation: 23783

It's worse than you think...

DDB doesn't allow you to update the key of an existing record. You'd have to delete those 2500 records and re-add them.

Luckily, countries don't change their names that often..

Without knowing more about your actual data, I can't offer any suggestions other than you may want to consider Aurora instead of DDB.

Upvotes: 1

Related Questions