In the event you adhere to REST requirements, it is best to at all times have a simple approach to get an inventory of entities and get a single entity by id.
With DynamoDB, you may take the drill-down method with composite keys. This implies you may construction your hash and vary keys to incorporate a number of entities in an effort to question your lists or get a single entity.
For instance, I would construction my hash and vary key like this for a property:
And I might overload the type/vary key like this:
So if I needed to get particulars on the property, I might do a
GetItem with the primary
pk/sk combo. If I needed to get an inventory of
buildings on that property, I might use the identical pk, however do a question the place
begins_with(sk, 'constructing#'). If I needed to get particulars a couple of particular constructing, I might do a
GetItem with the
pk/sk for the constructing.
What you wish to keep away from is constructing a construction that requires a FilterExpression to search out the information you need. A
FilterExpression is utilized after the question, which implies you get charged for all of the Read Capacity Units (RCUs).
Serverless is all about paying for what you employ, and also you don’t wish to unnecessarily be paying for reads that you’re by no means going to make use of. If you end up in a scenario the place you is perhaps overusing
FilterExpression, take a step again and see if you happen to can method your knowledge mannequin in a different way.
The bug I used to be engaged on bumped into this. We had an improperly designed knowledge mannequin across the shared information that have been inflicting us to do a mixture of
FilterExpressions and post-query filtering. It was some critical over fetching!
Because of this, we shortly bumped into the problem (that was ignored for thus lengthy) the place DynamoDB was returning the
LastEvaluatedKey to tell us there was extra knowledge to be loaded.
However as a result of we hadn’t anticipated knowledge of this magnitude, our code wasn’t checking for that within the response. This triggered us to not course of all the entities and provides the looks that information have been lacking.
All of this might have been averted if we had designed the information mannequin accurately.