0
votes

I have an Invoice table in dynamodb with hash-sort combo key. The hash is a uuid "tenantId" and the sort is a uuid named "id" for the invoice. However I have a field called "InvoiceNumber" which is the human readable sequential identifier for the invoices.

What is the best/optimal way to increment the InvoiceNumber when I create a new record while ensuring uniqueness and avoid race conditions?

Edit: Uniqueness would need to be enforced for each hash or tenant but not across the table.

1
Is the InvoiceNumber unique within each tenantId or global? Also, does any of your items ever get deleted? - Andre.IDK
For now they can be deleted but if it helps the process I can archive them instead. As for uniqueness. It would need to be unique within the same hash (tenantId) but not across the entire table. - user3376065
@Andre.IDK any thoughts? - user3376065

1 Answers

1
votes

Take a look at this Atomic Counter example. It is exactly what you are looking for.