Search code examples
amazon-web-servicesamazon-dynamodbaws-appsync

AppSync $util.autoId() and DynamoDB Partition and Sort Keys Design Questions


The limits for partition and sort keys of dynamoDB are such that if I want to create a table with lots of users (e.g. the entire world population), then I can't just use a unique partition key to represent the personId, I need to use both partition key and sort key to represent a personId.

$util.autoId() in AppSync returns a 128-bit String. If I want to use this as the primary key in the dynamoDB table, then I need to split it into two Strings, one being the partition key and the other being the sort key.

What is the best way to perform this split? Or if this is not the best way to approach the design, how should I design it instead?

Also, do the limits on partition and sort keys apply to secondary indexes as well?

Regarding $util.autoId(), since it's generated randomly, if I call it many times, is there a chance that it will generate two id's that are exactly the same?


Solution

  • I think I'm misunderstanding something from your question's premise because to my brain, using AppSync's $util.autoId() gives you back a 128 bit UUID. The point of UUIDs is that they're unique, so you can absolutely have one UUID per person in the world. And the UUID string will definitely fit within the maximum character length limits of Dynamo's partition key requirements.

    You also asked:

    if I call it many times, is there a chance that it will generate two id's that are exactly the same?

    It's extremely unlikely.