1

My application is running inside AWS lambda and needs to write to postgresql. There is a scenario that two lambdas will write to the same row in the db table. Below is the case:

Lambda1: receive order processing event then update order#1 status to processing

Lambda2: receive order completed event then update order#1 status to completed.

In above scenario, Lambda1 and Lambda2 can happen in any order. how can I make sure the final status of the order#1 is completed not processing?

I can do a query before update, but what happen if the other lambda writes to the table in between?

7
  • Postgres does row level locking for writes like that. As long as lambda1 starts its write first, it will be fine. Commented Feb 16, 2021 at 22:42
  • Locking a specific row in postgres Commented Feb 16, 2021 at 23:20
  • The problem in my case is that lambda1 and lambda2 may run in different order Commented Feb 16, 2021 at 23:22
  • How come lambda2 can run before lambda1? I think this is architecture design issue, not postgresql problem? Commented Feb 17, 2021 at 0:27
  • yes, this is architecture design issue. I am using event sourcing design and the events come to my lambda can be in any order. So that I need to fix in my lambda. The question is what is the best way to handle this case? Commented Feb 17, 2021 at 2:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.