Lesson 2 of 2 Amazon API Gateway and AWS Step Functions

Coordinating Services with AWS Step Functions

This lesson explains how Step Functions coordinates several services into serverless workflows defined as state machines.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the states that make up a workflow.
  • Choose between Standard and Express workflows.
  • Explain how callback tokens let a workflow wait for people or systems.
  • Choose between orchestration and choreography.

Building workflows

AWS Step Functions workflows are written in Amazon States Language, a JSON format, or built visually in Workflow Studio. They are made of states: Task states do work, Choice states branch, Parallel states run branches at once, Map states process each item in a list, Wait states pause, and Pass, Succeed and Fail states control flow. Distributed Map processes very large datasets, such as millions of objects in Amazon S3, with thousands of parallel child executions.

Built-in retries, catchers and error handling remove that logic from application code. Step Functions integrates directly with more than 200 AWS services, including Lambda, ECS and Fargate, AWS Batch, AWS Glue, SageMaker AI, DynamoDB, SNS and SQS, so many steps need no Lambda function at all. A process too long for Lambda's 15-minute limit is split into steps that the workflow coordinates.

Match the pairs

Step Functions states

Exam skills 2.1.1

Match each requirement with the Step Functions state that meets it.

Log in to try this activity Interactive activities are free with an account.

Standard or Express

Step Functions offers two workflow types. A Standard workflow can run for up to a year, runs each step exactly once, and keeps a full execution history that can be inspected step by step. It suits long-running business processes, such as order processing or a workflow that waits for a human approval.

An Express workflow runs for at most five minutes and is designed for high rates of execution at lower cost, such as processing each message from IoT devices or transforming streaming data; asynchronous Express workflows may run a step more than once, so steps should be idempotent. The following table summarises the differences.

Standard
DurationUp to 1 year
ExecutionExactly once, full history
Use forOrder processing, human approval
Express
DurationUp to 5 minutes
ExecutionHigh rate, lower cost
Use forIoT ingestion, streaming transforms

Waiting for people or systems

A task with a callback token pauses (up to a year in Standard) until an external system or person returns the token, e.g. approving via an email link.

The following diagram shows an approval step that waits for a callback token.

Waiting for a person with a callback token. A Step Functions task sends an approval email containing a link with the task token, then pauses, up to a year in a Standard workflow. When the approver clicks the link, the handler returns the token with SendTaskSuccess or SendTaskFailure, and the workflow continues down the matching path.
While it waits, the paused workflow consumes no compute.

Orchestration or choreography

When a process spans several services, they can be coordinated in two ways. With orchestration, a central coordinator, typically a Step Functions state machine, calls each service in turn and decides the next step from the result. The whole process is visible in one place, each execution can be inspected, and retries, error handling and compensating steps are defined centrally, which suits processes whose order, error handling and audit trail matter, such as payments.

With choreography, there is no coordinator: each service publishes events about what it has done, through EventBridge or SNS, and other services react independently. Services stay loosely coupled, and a new consumer can be added without changing the others, but the overall process is harder to see and to change. The following table summarises the choice.

ApproachHowChoose when
Orchestration (Step Functions)A central, visible sequenceOrder, error handling and auditing of the whole process matter
Choreography (EventBridge, SNS)Services react independentlyLoose coupling matters most

The following diagram compares the two approaches.

Orchestration compared with choreography. With orchestration, a Step Functions state machine calls each service in turn, so the process, its retries and its error handling are visible in one place. With choreography, each service publishes events to EventBridge or SNS and others react independently, so services stay loosely coupled but the overall process is harder to see.
Many systems use both: orchestration inside a business process, and events between independent processes.
Sort into groups

Orchestration or choreography?

Exam skills 2.1.1 · 2.1.3

Decide which coordination approach each statement describes.

Log in to try this activity Interactive activities are free with an account.
Worked example

An order workflow with a human step

A high-value order process must check stock, charge the card, wait up to two days for a manager's approval if the amount exceeds $10,000, then ship.

RequirementStep Functions feature
Steps in order with branching on the amountChoice state
Retry the payment service on transient errorsRetry with backoff
Refund if shipping failsCatch leading to a compensating step
Wait for a manager, up to two daysTask with .waitForTaskToken
Runs for days, exactly onceStandard workflow

Writing this in a single Lambda function would be impossible, because Lambda runs for at most 15 minutes, and fragile, because the state would have to be stored and resumed by hand.

Check yourself

Which workflow type suits high-volume event processing that finishes within five minutes?

Show answer

An Express workflow, which is cheaper at high volume. Standard workflows run for up to a year and record a full execution history.

Exam Tips

Remember for the exam

  • To orchestrate a multi-step process with retries, branching and human approval, use Step Functions.
  • For long-running workflows lasting days use Standard; for high-volume short workflows use Express.
  • To process thousands of S3 objects in parallel, use Distributed Map.
  • When a workflow must wait for a manual approval, use a callback task token.
  • For central control and visibility of a multi-step process, orchestrate it with Step Functions.