I am migrating an application from Cassandra to DynamoDB. On Cassandra we used as key a combination of (entityName,TimeUUID), with DynamoDB as far as I have read I could use a Hash+Range Primary Key.
To mantain the same data structure of the Cassandra Database I have been thinking of using entityName as Hash and timestamp as range. Then, I thought that maybe the timestamps might not be Unique: I am speaking of corner cases, but the Cassandra Primary Key (entityName,TimeUUID) is more powerful than the DynamoDB Hash+Range (entityName, timestamp), since it allows the existence of elements with the same entityName and timestamp.
Can I use Cassandra's TimeUUID as DynamoDb's range? Are there any reason why I should not use this approach?
You can (and should, if you think you can have collisions on
timestamp). The only catch, I can think of, is that you might have to handlebetween time_x and time_yQueryon your own.For e.g., let's say you have these 5 items in your table:
h1. RK:t1_uuid1h1. RK:t1_uuid2h1. RK:t2_uuid3h1. RK:t3_uuid4h2. RK:t4_uuid5Also, assume that
t1<t2<t3and UUIDs are 4 character strings betweenaaaaandzzzzNow, if you need all items with HK
h1and RK betweent1andt2, then yourQuerywould contain something likebetween t1_aaaa and t2_zzzz.This is because DynamoDB does not, on its own, understand the concept of TimeUUIDs like Cassandra. So, you'll have to handle cases such as above in your application layer.