Storing items in a DynamoDB table where the key and range key may overlap

I'm looking to store a large collection of photos in a DynamoDB table. Each photo can belong to an an "album" -- in fact, a photo can belong to multiple albums. I'd like to set the data up so I can perform a query of the album_id and retrive all the photo_ids that belong to that album.

For example: "get me all the photos that belong to album 1"

table "album-photo-map"
keys(album_id, timestamp) - photo_id

I could then perform a range query on on the table album-photo-map asking for all photo_ids that belong to album "1" with a range_key of timestamp greater than 0.

The problem is -- what if there are two photos with the same timestamp? DynamoDB won't let me have multiple items with the same key.

One way around this might be to store a binary list of photo_ids in one of the data fields for the album_id, but then the list of photos becomes limited by 64K which I'd rather not do.

Am I thinking about this correctly? Is there a solution to the duplicate timestamp problem? Perhaps I could do something like:

timestamp = str(time.time()).replace('.','')
>> 134704419008

and store that? Would that be fast enough to eliminate the duplicate problem?


You can use a hash of the image as the range_key. If the hash function is well chosen, there will be very little chance that images overlaps while not being identical. This key would be even better as it is directly related to the content.

If performance matters, you may simply append a random number to the key.

Need Your Help

How to scroll elements on canvas in different states and in different containers and not move others

flex scroll state move dynamic

I generate panels dynamically and put them in other states in that way so in one state you have a list of panels on the left and one big panel on the right for example in one state and when you cli...

Android - draw bitmap

android canvas bitmap

My test Android app has a single activity, LoadImage, with two methods: an onCreate method that processes images with OpenCV, and a Display method which displays the image on the screen for 5 secon...

Timeouts on read and writes

c++ boost tcp boost-asio

I have been searching for a way to cancel a Boost ASIO read or write operation if it takes over a certain amount of time. My server is sending out HTTP requests, and reading results from those req...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.