I have created one service X where accounting requests with some data comes from many other services Y. I create one idempotent_id from this data by adding many attributes so that this idempotent_id remains unique. I also create one idempotent_version and set it to 1. I store this record into dynamoDB (using idempotent_id and idempotent_version as partition key and sort key). now, I call some other service Z with this idempotent_id and idempotent_version. After some time, suppose request with same data comes I create idempotent_id but it will be same as before as we are processing same record. now I have to create idempotent_version which will be 2 in this case because same request have come before (this can be n if n-1 request have already come). how can i find what what will be idempotent_version for current data record because i will store the data into dynamoDB with this version and also call service Z with this version. (which will be 2 for current scenario)
Asked
Active
Viewed 610 times
0
-
I dont want to do scanning of records. please suggest some efficient solution. – Akash Patel Jun 17 '20 at 15:57
1 Answers
1
The docs have a section Using Sort Keys for Version Control.
Basically, when you create v1, also create as a copy of v1 as v0. Version 0 will always be the most recent. One additional attribute of v0 is named "Latest" and would start out as 1.
So when it's time for v2...
GetItem(hash:v0)
PutItem(hash:v2)
Copy v2 to v0, update "Latest" to 2
UpdateItem(hash:v0)
With the new transaction support, you can ensure that the Put of v2 and the update of v0 are consistent.

Charles
- 21,637
- 1
- 20
- 44
-
thanks, its helpful. actual problem is, I am creating a dynamoDB table. I am using an idempotentId as partition key and versionNumber as sort key. suppose there are 1000 versions for any particular idempotentId. for my use-case I always want to find out last version of any idempotentId. will there be any difference in performance when i want first versionNumber and when i want last versionNumber or both will take same time. – Akash Patel Jun 18 '20 at 09:15
-
The most recent version, say v1000, is also v0. Getting v0, or v1 would take the same amount time. – Charles Jun 18 '20 at 13:36
-
okay I got you solution. just for my knowledge, if I want to access any random version say 500 or 600. will it take same time? my question is accessing different version will take different time or access time will be same for all versions? – Akash Patel Jun 18 '20 at 17:40
-
DDB is design to provide "single-digit millisecond response times" for any given single record using GetItem(). – Charles Jun 18 '20 at 19:55
-
if i say i dont know the version number. for ex, given an idempotentId, find out the idempotentVersion when some attribute in the record is x. i guess scanning will occur in this case? – Akash Patel Jun 21 '20 at 08:50