0

I want to make a database for an iOS application consisting of groups that can have the same name. I am hosting my database on AWSDynamo.

Since multiple groups can have the same name, I was planning on having a groupID as the hashkey, unless someone can suggest a better method.

My main problem is storing an integer that will be the number of groups. This is so that when a user creates a new group the number will be incremented and the new group will get that number as its groupID.

How can I store an integer in such a fashion that all users can access it from the app?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
havak5
  • 714
  • 1
  • 6
  • 20

1 Answers1

1

UUID – Universally unique identifier

You can use a UUID (String) as your groupID in your groups table, and use conditional writes (PutItem, UpdateItem) to handle the extremely rare case where there is a collision. If you create a UUID for a new group where the UUID already is assigned to another group, you will get a ConditionalCheckFailedException so you can retry with a new UUID. You don't need to use an incrementing sequence to uniquely identify groups.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Alexander Patrikalakis
  • 5,054
  • 1
  • 30
  • 48
  • Actually a UUID is *not* a String but a 128-bit value, more of an unimaginably large number. For presenting a UUID value we create a String representation of a UUID in a canonical format using [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) characters and 4 hyphens. Like this: `de305d54-75b4-431b-adb2-eb6b9e546014`. The spec for UUIDs requires lowercase hex, but many implementations of UUID generators violate this rule. iOS provides a facility for generating UUIDs; see [this Question](http://stackoverflow.com/questions/14352418/how-to-generate-uuid-in-ios). – Basil Bourque May 17 '15 at 23:31
  • As for collisions in generated UUID values, that is *not* a practical concern. In a proper implementation of a UUID generator, collisions are virtually impossible, and I mean "virtually" in the most extreme sense. Even more so if using the original Version 1 (MAC address & date-time). – Basil Bourque May 17 '15 at 23:40
  • I did say extremely unlikely. Otherwise, you still raised valid points. – Alexander Patrikalakis May 18 '15 at 04:41