Bulk Order Processing

Processes a batch of vehicle orders concurrently using a Map state, with a maximum concurrency of 3. Each order in the batch is independently validated and screened for inventory availability and credit eligibility in parallel branches before being confirmed or rejected.
{
  "Comment": "Batch vehicle order processing: iterates over multiple orders concurrently (Map), and within each order runs inventory availability and credit screening simultaneously (Parallel) before confirming or cancelling.",
  "StartAt": "ProcessOrderBatch",
  "States": {
    "ProcessOrderBatch": {
      "Type": "Map",
      "Comment": "Process each vehicle order in the batch concurrently, up to 3 at a time.",
      "ItemsPath": "$.orders",
      "MaxConcurrency": 3,
      "ItemProcessor": {
        "ProcessorConfig": {
          "Mode": "INLINE"
        },
        "StartAt": "ValidateItem",
        "States": {
          "ValidateItem": {
            "Type": "Task",
            "Resource": "arn:aws:states:::lambda:invoke",
            "Parameters": {
              "FunctionName": "${ValidateOrderFunctionArn}",
              "Payload.$": "$"
            },
            "ResultPath": "$.validation",
            "Retry": [
              {
                "ErrorEquals": [
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException"
                ],
                "IntervalSeconds": 2,
                "MaxAttempts": 2,
                "BackoffRate": 2
              }
            ],
            "Catch": [
              {
                "ErrorEquals": [
                  "States.ALL"
                ],
                "ResultPath": "$.error",
                "Next": "ItemValidationError"
              }
            ],
            "Next": "IsItemValid"
          },
          "IsItemValid": {
            "Type": "Choice",
            "Choices": [
              {
                "Variable": "$.validation.Payload.isValid",
                "BooleanEquals": true,
                "Next": "InventoryAndCreditScreening"
              }
            ],
            "Default": "CancelInvalidItem"
          },
          "CancelInvalidItem": {
            "Type": "Task",
            "Resource": "arn:aws:states:::lambda:invoke",
            "Parameters": {
              "FunctionName": "${CancelOrderFunctionArn}",
              "Payload": {
                "reason": "INVALID_ORDER",
                "order.$": "$"
              }
            },
            "ResultPath": "$.cancellation",
            "End": true
          },
          "ItemValidationError": {
            "Type": "Fail",
            "Error": "ValidationError",
            "Cause": "Order validation lambda failed unexpectedly"
          },
          "InventoryAndCreditScreening": {
            "Type": "Parallel",
            "Comment": "Run inventory check and credit assessment concurrently to minimise latency.",
            "Branches": [
              {
                "StartAt": "InventoryCheck",
                "States": {
                  "InventoryCheck": {
                    "Type": "Task",
                    "Resource": "arn:aws:states:::lambda:invoke",
                    "Parameters": {
                      "FunctionName": "${CheckInventoryFunctionArn}",
                      "Payload.$": "$"
                    },
                    "ResultPath": "$.inventory",
                    "End": true
                  }
                }
              },
              {
                "StartAt": "CreditAssessment",
                "States": {
                  "CreditAssessment": {
                    "Type": "Task",
                    "Resource": "arn:aws:states:::lambda:invoke",
                    "Parameters": {
                      "FunctionName": "${RunCreditCheckFunctionArn}",
                      "Payload.$": "$"
                    },
                    "ResultPath": "$.credit",
                    "End": true
                  }
                }
              }
            ],
            "ResultPath": "$.screeningResults",
            "Next": "ItemConfirmed"
          },
          "ItemConfirmed": {
            "Type": "Succeed"
          }
        }
      },
      "ResultPath": "$.batchResults",
      "Next": "BatchComplete"
    },
    "BatchComplete": {
      "Type": "Succeed"
    }
  }
}
JSON
Expand
100%

Automotive teams can use patterns like this to build reliable, compliant, and scalable automation for payment systems and can test and refine these flows locally with Thrubit to reduce cloud cost and speed up iteration.

Free Trial