views:

120

answers:

2

Is there an equivalent to an identity Seed in SimpleDB?

If the answer is no, how do you handle creating something like a customer number or order number that will prevent the creation duplicate numbers?

My experience is mainly from SQL Server in which I would either create a primary key with an identity seed or use transactions in a stored procedure to increment the number.

Thanks for your help!

+1  A: 

If you don't already have something unique that will work, using a GUID for the Item is probably the typical solution.

Darryl
Thanks for your response! Creating a guid would work, but I would like to generate something that is more human readable.
Zaffiro
+2  A: 

You can create unique keys using conditional writes. Just do a PutAttributes with the next customer number you want to use and the data you want to store. You can't add a condition for the actual item name, but you can use an attribute that always exists, (like creation date or user group).

Set the conditions:

   Expected.1.Name=creation_date
   Expected.1.Exists=false

The call will succeed only if there is no creation_date in an item with that item name. If you always write the creation_date, then you get the effect of optimistic locking on the new item name. Of course you can use any attribute you want, so long you always include it in that first conditional put.

The performance of the conditional write is the same as a normal write in most situations but when SimpleDB is under heavy load or high internal network latencies, these calls will take longer, compared to normal writes. During rare failure scenarios inside SimpleDB, the conditional writes will fail completely for a period of time.

If you can't tolerate this, you will have to code some sort of alternate way to get your unique keys during outages. A different SimpleDB region could be used for key generation only, since SimpleDB will still accept the normal writes (non-conditional PutAttributes) during outages.

Mocky
Thanks for the answer! After reading this, I went back to the documentation which now clear to me. It can be found here: http://docs.amazonwebservices.com/AmazonSimpleDB/2009-04-15/DeveloperGuide/ConditionalPut.html
Zaffiro