How can I do Distributed Transaction with EventBridge?

0

I'm using the following scenario to explain the problem.

I have an ecommerce app which allows the customers to sign up and get an immediate coupon to use in the application. I want to use **EventBridge ** and a few other resources like a Microsoft SQL Database and Lambdas. The coupon is retrieved from a third-party API which exists outside of AWS. The event flow is:

Customer --- sends web form data --> EventBridge Bus --> Lambda -- create customer in SQL DB --get a coupon from third-party API -- sends customer created successfully event --> EventBridge Bus

Creating a customer in SQL DB, getting the coupon from the third-party API should happen in a single transaction. There is a good chance that either of that can fail due to network error or whatever information that the customer provides. Even if the customer has provided the correct data and a new customer is created in the SQL DB, the third-party API call can fail. These two operations should succeed only if both succeed.

Does EventBridge provide distributed transaction through its .NET SDK? In the above example, if the third-party call fails, the data created in the SQL database for the customer is rolled back as well as the message is sent back to the queue so it can be tried again later.

I'm looking for something similar to TransactionScope that is available in Azure. If that is not available, how can I achieve distributed transaction with EventBridge, other AWS resources and third-party services which have a greater chance of failure as a unit.

3개 답변
3
수락된 답변

There is not transaction scope in EventBridge. Each target handles the events it receives in an independent way. As you do need some coordination between them I would recommend that you invoke a Step Functions state machine from EventBridge. The state machine will implement a Saga Pattern to perform both operations and roll back in case of failures.

profile pictureAWS
전문가
Uri
답변함 2년 전
profile picture
전문가
검토됨 한 달 전
1

EventBridge by itself is not transactional.
The Lambda can do both create User in DB and create Coupon. If this fails, you can handle this in your Lambda function and then throw an error.
EventBridge has an retry for failed Lambda functions.

AWS
Marco
답변함 2년 전
  • This situation can happen. The user is created in the DB, but the coupon retrieval has failed. Because the coupon retrieval also has failed, the created user also should be rolled back. Deleting the already created user like it was created seems to the solution if there is no transaction scope can be created around both those operations. Do you see any other option to add transaction scope?

1

As @Uri explained, this would be more a case for coordinating using Step Functions, here's one example of implementation https://github.com/aws-samples/aws-step-functions-saga-pattern-with-sam

AWS
답변함 2년 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠