I'm trying to design a DynamoDB table. I'm choose the keys I insert, what my partition and sort keys will be, as well as whether or not to including a GSI.
My data, for sake of example, looks like this:
Table name: person
{
uuid: "649ed782-0d65-402d-968e-56f3b36a98c3",
name: "Mike",
state: "Massachusetts",
city: "Boston",
bio: "Mike makes DynamoDB tables",
age: 41,
}
I will need to perform the following operations on the table.
- Get the entire record of data about the person looked up by the UUID
- Get the list of names of people according to the city and state
- Get a list of city/state pairs that make up the data in the table
It seems to me like it's an obvious choice to have the table have a partition key of UUID which gives me a fast get lookup for operation #1 and I could create a GSI with both city and state as the primary key, or a concatenation of them, which allows me to satisfy #2. Operation #3 is a bit tricky. I want to just ask the GSI what its keys are but I have read that this is not possible on other stack overflow posts.
So I'm wondering if the best option is to create a secondary table with a stream and lambda that responds to updates on the main person table and just has one item in the entire table which is a list of city and state combinations. Maybe it would be good to create some sort of other database like a Reddis or Memcached instance that stores this stuff? I think that would potentially be needlessly expensive. Is there a standard way to design a table like this? Would it be expensive to do a full scan of my GSI looking just for partition keys? I think it is. At least it was pretty time consuming when I did a test.
Thanks for the input.