workflow —— A Guide to Building Workflow Based Application with AWS SWF
原文:https://hashedin.com/blog/a-guide-to-building-workflow-based-application-with-aws-swf/
Business workflows are very common in applications and often play the most critical role. In this post, we will explore AWS SWF service to handle business workflows.
Before understanding the SWF, let’s be on the same page by understanding what I mean by a workflow. A Workflow is a sequence of activities which we perform to achieve a goal. Now, sequence of activities may be dynamic and decided based on some inputs, usually the output of previous activity or may be some external signal. We often represent a workflow using flow diagrams. For an example – An online taxi booking system might have a workflow for taxi booking as:
- Search for nearby taxis which matches taxi-type criteria of search.
- If the search gives the results, then:2.1. Send notification all taxi drivers about the order and wait for the fixed time period for confirmation.
2.2. If the confirmation came in time, then it sends confirmation to the customer. Else after timeout send SMS to customer to retry after sometime. - Else, it sends a message about non availability of the taxi and asks to retry after some time.
Of course, this is just the booking flow. But, in reality, this will be more complicated for complete order lifecycle. Here is the flowchart for this.
You can easily observe the technical challenges involved in handling this simple workflow where we have to maintain the state at each steps to take next decision. Let’s see what AWS SWF provides to solve this.
You can easily observe the technical challenges involved in handling this simple workflow where we have to maintain the state at each steps to take next decision. Let’s see what AWS SWF provides to solve this.
AWS SWF is a reliable & scalable solution to run jobs that have parallel or sequential steps. It provides task coordination and state tracking and allows you to completely control the decision making and activity functioning.
Terminologies for SWF:
Following are the terminologies for SWF.
- Worker An application which perform some task. There are two type of workers in SWF, Decider & Activity workers. Decider Workers are responsible for performing decisions by taking the state history and returning next activity task to perform or completing the workflow execution. Decider corresponds to diamond box in flow-chart. Activity Workers are responsible for performing the actual task.
- Tasks: SWF interacts with workers by providing them some unit of work called task. It can be an activity task which needs to be performed by Activity Worker or decision task which needs to be performed by a decider or a lambda task, which is a special activity task that can be executed using AWS lambda function.
- WorkflowType: Every workflow in SWF needs to be registered by providing name and version. This is just to identify a workflow. e.g. for above discussed taxi booking system, we can have a workflow type as ‘TaxiBookingWorkflow’
- Domain: Provides a way to scope AWS resource within AWS account. All tasks and workflow needs to be associated with a domain.
- Workflow Starter: An application which kicks of the workflow execution. In our taxi booking app, a backend API handler for booking request could be the workflow starter.
Brief on how SWF based application works
- Create a domain in SWF and workflow in SWF. And then register activity tasks in the workflow.
- Start workflow execution.
- Next, initiate the decider worker which will Poll for decision tasks and find the next step to do.
- Start Activity workers which will poll for activity task and perform required task.
Here is a simple diagram explaining how SWF works
So, for our above discussed taxi booking system we will,
- Register a domain(a name to scope all the related SWF entities), workflow-type(just an identifier to booking workflow) and activities with SWF.
- Create decider – python program which keeps polling decider queue and output next step.
- Create Activity worker – python program which keeps polling activity queue and executes task.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· 面试官:你是如何进行SQL调优的?
2020-03-06 git cherry-pick —— 团队中git merge时冲突——待续
2020-03-06 PostgreSQL 数据库开发规范——命名规范 & 设计规范
2020-03-06 C# 编码约定(C# 编程指南)
2020-03-06 vs 代码分析工具——FxCop analyzers & nuget 包 排除