Tournament Bracket Processing

This workflow processes a round of tournament match results concurrently using a Map state. Each match result is independently validated and recorded, bracket standings are updated, and the workflow determines whether the tournament round is complete. On round completion, Amazon Bedrock generates a highlight recap, and prizes or advancement tokens are distributed to qualifying players.

{
  "Comment": "Tournament bracket processing — runs match results concurrently via Map state, then generates a Bedrock highlight recap and advances winners to the next round.",
  "StartAt": "ProcessMatchResults",
  "States": {
    "ProcessMatchResults": {
      "Type": "Map",
      "ItemsPath": "$.matchResults",
      "MaxConcurrency": 5,
      "ItemProcessor": {
        "ProcessorConfig": {
          "Mode": "INLINE"
        },
        "StartAt": "ProcessSingleMatch",
        "States": {
          "ProcessSingleMatch": {
            "Type": "Task",
            "Resource": "arn:aws:states:::lambda:invoke",
            "Parameters": {
              "FunctionName": "${ProcessMatchResultFunctionArn}",
              "Payload.$": "$"
            },
            "ResultSelector": {
              "success.$": "$.Payload.success",
              "matchId.$": "$.Payload.matchId",
              "tournamentId.$": "$.Payload.tournamentId",
              "winnerId.$": "$.Payload.winnerId",
              "loserId.$": "$.Payload.loserId",
              "score.$": "$.Payload.score",
              "advancementToken.$": "$.Payload.advancementToken",
              "processedAt.$": "$.Payload.processedAt"
            },
            "Retry": [
              {
                "ErrorEquals": [
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException"
                ],
                "IntervalSeconds": 2,
                "MaxAttempts": 3,
                "BackoffRate": 2.0
              }
            ],
            "End": true
          }
        }
      },
      "ResultPath": "$.processedMatches",
      "Catch": [
        {
          "ErrorEquals": ["States.ALL"],
          "ResultPath": "$.error",
          "Next": "MatchProcessingFailed"
        }
      ],
      "Next": "GenerateTournamentRecap"
    },
    "MatchProcessingFailed": {
      "Type": "Fail",
      "Error": "MatchProcessingFailed",
      "Cause": "One or more match results failed to process"
    },
    "GenerateTournamentRecap": {
      "Type": "Task",
      "Resource": "arn:aws:states:::bedrock:invokeModel",
      "Parameters": {
        "ModelId": "anthropic.claude-3-5-sonnet-20241022-v2:0",
        "Body": {
          "anthropic_version": "bedrock-2023-05-31",
          "max_tokens": 250,
          "messages": [
            {
              "role": "user",
              "content.$": "States.Format('Write an exciting tournament recap (3-4 sentences) for round {} of \"{}\". {} matches were played this round. Describe the fierce competition, dramatic upsets, and the champions who advanced. Write it like a sports broadcast highlight reel.', $.round, $.tournamentName, $.processedMatches[0].tournamentId)"
            }
          ]
        }
      },
      "ResultSelector": {
        "recapText.$": "$.Body.content[0].text"
      },
      "ResultPath": "$.tournamentRecap",
      "Catch": [
        {
          "ErrorEquals": ["States.ALL"],
          "ResultPath": "$.tournamentRecap",
          "Next": "AdvanceRound"
        }
      ],
      "Next": "AdvanceRound"
    },
    "AdvanceRound": {
      "Type": "Pass",
      "Parameters": {
        "tournamentId.$": "$.tournamentId",
        "tournamentName.$": "$.tournamentName",
        "round.$": "$.round",
        "processedMatches.$": "$.processedMatches",
        "recap.$": "$.tournamentRecap",
        "status": "ROUND_COMPLETE",
        "completedAt.$": "$$.Execution.StartTime"
      },
      "ResultPath": "$.roundSummary",
      "Next": "TournamentRoundComplete"
    },
    "TournamentRoundComplete": {
      "Type": "Succeed"
    }
  }
}
JSON
Expand
100%

Gaming 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