aws-lambda - How to use Event-Driven architecture to remove "api-based lambda calling another lambda" anti-pattern?
问题描述
Suppose, I have an api POST /order
which invokes PlaceOrder
lambda and expects response from this. PlaceOrder
lambda does some works, invokes another lambda ProcessPayment
lambda and expects response. Also, ProcessPayment
invokes CreateInvoice
lambda expecting response. Whole architecture is like a RequestResponse
cycle. I woulde like to achieve that without lambda invoking another lambda as it is considered as anti-pattern. My question is what is the best design pattern to achieve this behavior within 29 seconds with event-driven architecture.
What AWS suggests: As per this official documentation, they suggests to use SQS. But regarding using SQS, I have some thoughts.
My thoughts:
- At event sources architecture, I can orchestrate these lambdas with SQS, SNS etc other event sources, but in that case, the nature would not be synchronous and thus I would not get response from the api.
My other solution:
- Using Step Function: I can orchestrate this workflow with step function, and I think it is more elegant solution in this synchronous calling case. But I would like to achieve this via event sources.
How can I design this scenerio with best practices using event-based achitecture?
解决方案
在事件驱动架构中,生产者和消费者之间的通信在设计上是异步的,这就是架构扩展的方式。
您可以在 EDA 中的 2 个服务之间获得几乎同步的通信,通过创建专用队列/通道在它们之间进行通信,确保它们被放大到延迟可接受的水平(接近同步值)。
这增加了一些复杂性,因为需要响应的服务必须在热循环中等待以尽快获取它们,并且如果消息丢失,您需要有重试策略等。
推荐阅读
- python - 如何将 tkinter 窗口的内容复制到演示幻灯片?
- sql - 在 SQL 中,主表应与多列的查找表匹配
- java - 我想快速进入图表但绘制缓慢
- webpack - Webpack 构建任务覆盖优化
- go - 如何在 golang webview 中指定浏览器?
- cors - CORS 问题:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段授权
- swift - 在 collectionview 单元格中添加到 uiview 时,点击手势无法按预期工作
- android - 默认共享首选项写入哪里?
- angular - S3 存储桶引用旧代码/api?角 5
- php - php unset foreach loop is not unsetting the value of array