DynamoDB Atomic Counters

0

Greetings!

I have an application that utilizes a DynamoDB table to manage counters. When we update the value of the counter, we consume the returned value - this returned value is the old value of the counter. This counter is then used to retrieve a value in an array, it is effectively an index.

I currently increment these counters with Lambda functions - it's highly likely that many Lambdas may attempt to update the value of a given counter at the same time. It's important that each Lambda function receives a different value of the counter.

Utilizing DynamoDB atomic counters, can I expect that each Lambda function will receive a different value for the counter?

Example:

  • 10 Lambdas attempt to update value of a counter where its current value is 0
  • The Update Expression is "ADD count :incr" where ":incr" is 1
  • Each Lambdas update is processed
  • The returned value from each update is unique per Lambda and the values are 0 - 9
  • The final value of the counter is 10
gefragt vor 2 Jahren5612 Aufrufe
1 Antwort
2

Yes, this is exactly how atomic counters work. You can find more info here

profile pictureAWS
EXPERTE
Uri
beantwortet vor 2 Jahren
profile pictureAWS
EXPERTE
überprüft vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen