共享数据库的微服务

发布于 2025-02-03 09:11:28 字数 536 浏览 2 评论 0原文

我有一个可以简化/简化此流程的应用程序:

  1. 用户将请求发送到应用
  2. 程序A a插入有关请求的信息,并将用户插入db(标记为“ b中的B”和“ c中的C中”)
  3. App a数据排入队列并返回到用户
  4. 应用程序B从队列中检索数据,并处理
  5. 应用程序B完成处理数据和标记DB中的记录,因为“ B DONDO”
  6. 应用程序C检索来自队列的数据和处理IT
  7. App C完成处理数据和标记记录记录在DB中,如“ C完成”

,用户将请求发送到应用程序,应用将记录保存到数据库并将其发送到队列,App B和C从队列中获取请求并处理IT(每个应用程序都会做不同的事情,但需要数据数据从请求),当它们完成后,我想将DB中的请求标记为两个应用程序。

如果所有应用共享DB,则可以实现这一点。然而,在微服务之间共享这样的DB被认为是反图案。

哪些设计模式可以解决这个问题?我真的只剩下一个选项吗?让应用程序公开REST API并调用App B和C的端点以更新DB中的行?

感谢您的帮助!

I have an application that can be reduced/simplify to this flow:

  1. user sends request to app A
  2. app A inserts info about the request and user into DB ( marked as "B in progress" and "C in progress")
  3. app A pushes the data into queue and returns to user
  4. app B retrieves data from queue and process it
  5. app B finishes processing the data and marks record in DB as "B done"
  6. app C retrieves data from queue and process it
  7. app C finishes processing the data and marks record in DB as "C done"

In other words, user sends request to app, app saves the record to the database and send it to queue, app B and C takes request from queue and process it ( each app does different thing but requires data from request ) and when they are done i want to mark the request in db as done for both APP.

This can be achieved, if all apps share DB. However sharing the DB like this between microservices is considered anti-pattern.

What are some design patterns to solve this? Am i really left with only option - make app A expose rest API and call the endpoint from app B and C to update the row in DB?

Thanks for help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘初心 2025-02-10 09:11:28

这听起来像是编舞,是事件驱动的过程。您是否考虑使用kafka,而不是DB,在每个发布中都会富含状态。

This more sounds like choreography , event driven process. Instead of DB, did u consider using Kafka where status gets enriched at each publish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文