Step Functions Integration Patterns
What You'll Learn
You'll learn the three core integration patterns Step Functions uses to coordinate service calls: request-response, wait-for-callback, and run-a-job.
Understanding Integration Patterns
When Step Functions orchestrates tasks, it needs different ways to interact with other services depending on how those services operate. AWS provides three distinct integration patterns to handle both synchronous and asynchronous workflows.
Request-Response (.sync)
This is the default synchronous pattern. Step Functions calls a service, waits for the response, and immediately continues. Think of it like ordering fast food at the counter—you place your order and get your meal right away.
When you invoke a Lambda function without special suffixes, you're using request-response. The state machine waits for the function to complete and return a result before moving to the next state.
Wait-for-Callback (.waitForTaskToken)
This asynchronous pattern is for long-running tasks. Step Functions sends a unique task token to the service and pauses execution. The external service must explicitly send a success or failure signal back using that token when work completes—minutes, hours, or even days later.
Imagine dropping off dry cleaning: you get a ticket (the token), go about your day, and return later when notified it's ready.
Run-a-Job (.sync:2)
This pattern makes normally asynchronous services behave synchronously. Step Functions starts a job (like an AWS Batch job or an ECS task) and polls until completion, handling all the waiting logic for you.
It's like using a package tracking system that automatically refreshes until delivery—you started an async process but get a synchronous experience.
Choosing the Right Pattern
Use request-response for quick operations, wait-for-callback when you need human approval or external dependencies, and run-a-job when you want container or batch jobs to behave synchronously without manual polling logic.
Key Takeaway: Step Functions' three integration patterns—request-response, wait-for-callback, and run-a-job—give you precise control over synchronous and asynchronous service coordination in your state machines.