Refactoring to ServerlessReplace Polling with Callback1 min

Description

Step Functions provide integration patterns to interact with services invoked. Waiting for a long-running process might lead users to build a polling workflows including control flows (e.g. Choice, Map, Wait) or calls made against other AWS services (e.g. LambdaInvoke). This would lead to the before architecture shown below where a Lambda function is invoked repeatedly after a specified wait period to continue with the workflow once the message was processed.

An example might look as follows:

Solution

Use Step Function's Callback Integration Pattern to call a service with a task token and have Step Functions wait until that token is returned with a payload.

See the CDK implementation of this pattern in Typescript on GitHub

Considerations

Advantages

  • The Step function state machine workflow waits until the callback token is received. This abandons the need for a polling machanism and reduces the number of function integrations.

Applicability

Related Refactorings


Created by:

Gregor Hohpe
Gregor HohpeI contemplate and write about architecture strategy, cloud, and IT transformation. In between I - extract order from chaos - dive into the engine room to give the penthouse better IT strategies - fight relentlessly against unnecessary complexity and corporate politics I've been called the ''IT transformation jester'' - unbiased, trusted, influential, and witty.
Sindhu Pillai
Sindhu PillaiAs Regional SA Lead, I focus on enterprise Education Technology customers. In my role, I guide my SA team in the delivery and execution of complex technical solutions to support our customer's business and technical goals.
Bhuvan Annamreddi
Bhuvan AnnamreddiAssociate Solutions Architect, AWS