Giter Club home page Giter Club logo

aws-step-functions-long-lived-transactions's Introduction

Managing Long Lived Transactions with AWS Step Functions

AWS Step Functions is a fully managed Serverless workflow management service for managing long running processes and coordinating the components of distributed applications and microservices using visual workflows. But did you know it can also help you deal with the complexities of dealing with a long lived transaction across distributed components in your microservices architecture? In this Builder session, you will learn how AWS Step Function can help us implement the Saga design pattern.

What problems are we trying to solve?

When building cloud-based distributed architectures, one of the questions we need to ask ourselves is how do we maintain data consistency across microservices that have their own database / persistence mechanism? We do not have support for Distributed Transaction Coordinators (DTC) or two-phase commit protocols responsible for coordinating transactions across multiple cloud resources. We need a mechanism coordinate multiple local transactions.

What is the Saga pattern?

A Saga is a design pattern for dealing with “long-lived transactions” (LLT), published by Garcia-Molina and Salem in 1987. Their original paper can be found here https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf.

“LLT is a saga if it can be written as a sequence of transactions that can be interleaved with other transactions.” (Garcia-Molina, Salem 1987)

Fundamentally it is a failure management pattern, that provides us the means to establish semantic consistency in our distributed applications by providing compensating transactions for every transaction where you have more than one collaborating services or functions.

Why AWS Step Functions?

AWS Step Functions provide us with a mechanism for dealing with long-lived transactions, by providing us with the ability to build fully managed state machines that:

  • coordinate the components of distributed applications and microservices
  • allowing us to build our state machines using visual workflows
  • provides us with a way to manage state and deal with failure

Sample application

Scenario

You are creating an e-commerce application and are processing an order. This requires you to update order status, process a credit card transaction and update inventory levels. Each state integrates with a different backend with its own local transaction. You need to treat these as a single, distributed transaction.

Saga with Step Functions

Learning objectives

The goal is to demonstrate:

  • How to create a state machine that implements the Saga pattern
  • Understand how to use error handling and retry functionality using AWS Step Functions
  • Configure Task states to execute pre-provisioned AWS Lambda functions

Get started

  1. Read the Setup Information to deploy the artefacts necessary to complete this session.
  2. Use the Session Guide to assist you as you create your saga implementation for the e-commerce application scenario.

Additional Step Functions resources and reference architectures


License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.

aws-step-functions-long-lived-transactions's People

Contributors

jpeddicord avatar sliedig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-step-functions-long-lived-transactions's Issues

Error deploying cloudformation stacks

When pressing the Launch Stack button (regardless of the region), the stack won't deploy anymore. Would be nice if it got resolved fast. Thank you.

aws-xray-sdk upgrade

Current referenced version of aws xray sdk not compatible with lambda, update to latest (v1.0.0-rc.14)

Images Inconcsistency

The image on the front page doesn't appear to be the image that is then used for the testing. It appears to be slightly different on the bottom row. Not a huge issue but may throw some people off.

NewOrder Lambda failed to begin subsegment named 'dynamodb': segment cannot be found

Hi,

After deploying the cloud formation template.
Created a simple Step Functions:

{ "Comment": "re:Invent 2018 Builder Session - Managing Long Lived Transactions with AWS Step Functions State Machine", "StartAt": "ProcessOrder", "States": { "ProcessOrder": { "Comment": "First transaction to save the order and set the order status to new", "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:ACCOUNTID:function:NextGenOrderManagt-NewOrderFunction-xxxx", "TimeoutSeconds": 10, "Catch": [{ "ErrorEquals": ["ErrProcessOrder"], "ResultPath": "$.error", "Next": "UpdateOrderStatusFailed" }], "Next": "UpdateOrderStatusSucceeded" }, "UpdateOrderStatusFailed": { "Type": "Fail" }, "UpdateOrderStatusSucceeded": { "Type": "Succeed" } } }

And it fails on the scenario 1:
{ "order_id": "1ae4501d-ed92-4b27-bf0e-fd978ed45127", "order_date": "2018-10-19T10:50:16+08:00", "customer_id": "8d04ea6f-c6b2-4422-8550-839a16f01feb", "items": [{ "item_id": "987", "qty": 1.0, "description": "Cart item 1", "unit_price": 19.99 }, { "item_id": "546", "qty": 1.0, "description": "Cart item 2", "unit_price": 23.98 }, { "item_id": "3", "qty": 2.0, "description": "Cart item 3", "unit_price": 6.50 } ] }

with the error: failed to begin subsegment named 'dynamodb': segment cannot be found

Full stack:
{ "errorMessage": "failed to begin subsegment named 'dynamodb': segment cannot be found.", "errorType": "string", "stackTrace": [ { "path": "github.com/aws/[email protected]/lambda/function.go", "line": 27, "label": "(*Function).Invoke.func1" }, { "path": "runtime/asm_amd64.s", "line": 522, "label": "call32" }, { "path": "runtime/panic.go", "line": 513, "label": "gopanic" }, { "path": "github.com/aws/[email protected]/strategy/ctxmissing/default_context_missing.go", "line": 47, "label": "(*DefaultRuntimeErrorStrategy).ContextMissing" }, { "path": "github.com/aws/[email protected]/xray/segment.go", "line": 88, "label": "BeginSubsegment" }, { "path": "github.com/aws/[email protected]/xray/aws.go", "line": 52, "label": "glob..func1" }, { "path": "github.com/aws/[email protected]/aws/request/handlers.go", "line": 213, "label": "(*HandlerList).Run" }, { "path": "github.com/aws/[email protected]/aws/request/request.go", "line": 361, "label": "(*Request).Build" }, { "path": "github.com/aws/[email protected]/aws/request/request.go", "line": 382, "label": "(*Request).Sign" }, { "path": "github.com/aws/[email protected]/aws/request/request.go", "line": 490, "label": "(*Request).Send" }, { "path": "github.com/aws/[email protected]/service/dynamodb/api.go", "line": 2936, "label": "(*DynamoDB).PutItemWithContext" }, { "path": "new/main.go", "line": 68, "label": "saveOrder" }, { "path": "new/main.go", "line": 45, "label": "handler" }, { "path": "runtime/asm_amd64.s", "line": 527, "label": "call1024" }, { "path": "reflect/value.go", "line": 447, "label": "Value.call" }, { "path": "reflect/value.go", "line": 308, "label": "Value.Call" }, { "path": "github.com/aws/[email protected]/lambda/handler.go", "line": 114, "label": "NewHandler.func1" }, { "path": "github.com/aws/[email protected]/lambda/handler.go", "line": 22, "label": "lambdaHandler.Invoke" }, { "path": "github.com/aws/[email protected]/lambda/function.go", "line": 59, "label": "(*Function).Invoke" }, { "path": "runtime/asm_amd64.s", "line": 523, "label": "call64" }, { "path": "reflect/value.go", "line": 447, "label": "Value.call" }, { "path": "reflect/value.go", "line": 308, "label": "Value.Call" }, { "path": "net/rpc/server.go", "line": 384, "label": "(*service).call" }, { "path": "runtime/asm_amd64.s", "line": 1333, "label": "goexit" } ] }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.