在 CQRS 系统中,我应该如何向用户表明他们的请求已收到?

发布于 2024-12-14 03:21:44 字数 605 浏览 2 评论 0原文

我正在尝试解耦我们的大泥球架构的一些部分,并确定了几个边界,这些边界是使用 CQRS 提供更具弹性和可扩展性的解决方案的明显候选者。

典型示例:当客户下订单时,我们会在订单提交付款、销售系统批准等时阻塞他们的线程。

这一切都可以异步处理 - 允许我们在接受订单并排队的同时支付处理系统不可用等 - 但我不确定应该如何管理客户的 UI 数据。

换句话说 - 他们下了订单。他们的订单排在队列中。如果他们五秒钟后重新登录帐户并单击“查看订单” - 会发生什么?

  • 如果我从中央存储库(或从基于该存储库更新的缓存)中提取它,那么用户将看不到他们的订单,并且可能会尝试再次放置它 - 或者打电话给我们并恐慌。
  • 如果我从本地数据库中提取它,那么我需要维护另一个订单数据库的开销 - 该数据库需要在负载平衡的环境中同步,并且似乎破坏了很多优势的 CQRS。

我想在很多地方这样做 - 但并非所有地方都像确认订单一样重要;在某些情况下,就像客户更改电话号码或其他内容一样简单 - 因此并非所有情况我都可以说“非常感谢,我们会向您发送确认电子邮件” - 因为发送确认电子邮件 -对记录的每次修改都发送邮件让我觉得有点过分了。

我应该考虑什么模式或解决方案来帮助解决这个问题?

I'm trying to decouple some of the bits of our big-ball-of-mud architecture, and identified several boundaries that are obvious candidates for using CQRS to provide a more resilient and scalable solution.

Typical example: when a customer places an order, at the moment we block their thread whilst the order is submitted for payment, approved by the sales system, etc, etc.

This can all be handled asynchronously - allowing us to accept and queue orders whilst the payment processing system is unavailable, etc. - but I'm not sure how I should manage the UI data for the customer.

In other words - they place an order. Their order goes in a queue. If they log back into their account five seconds later and click "review orders" - what happens?

  • If I draw it from the central repo (or from a cache that's updated based on that repo), then the user won't see their order and will probably try and place it again - or phone us and panic.
  • If I draw it from a local database, then I have the overhead of maintaining another database of orders - which will need to be synchronised in a load-balanced environment, and seems to undermine a lot of the advantages of CQRS.

I want to do this in lots of places - and not all of them are actions as significant as confirming an order; in some cases it's as simple as a customer changing a phone number or something - so they're not all cases where I can just say "thanks a lot, we'll send you a confirmation e-mail" - because sending confirmation e-mails for every modification to a record strikes me as a little excessive.

Any patterns or solutions I should look at to help with this?

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

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

发布评论

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

评论(4

熟人话多 2024-12-21 03:21:44
  • 值得考虑的是“用户”收件箱:用户可以在应用程序中查阅“正在进行的”命令的位置。当用户已经移至另一个屏幕但仍驻留在您的应用程序中时,您还可以将通知“推送”回用户的 UI。当用户重新登录时,这也可能是一个选项。
  • 另一种选择可能是伪造同步体验,即等待并在后台进行轮询,所有事情都异步发生。当然,这可能还涉及超时,但我认为这些也包含在当今的同步处理中。
  • 最重要的是,您可能希望告知最终用户并征求他们对您的应用程序及其行为的体验的反馈。
  • 不管别人告诉你什么,如果你想优雅地处理这件事,你需要付出一些努力。
  • Something worth considering is a 'user' inbox: a place in your app the user can consult 'in-progress' commands at. You could also 'push' notifications back to the user's UI when he has already moved onto another screen, but still resides in your app. This might also be an option when the user logs back on.
  • Another option could be faking the synchronous experience, i.e. wait around and do polling while in the background everything happens asynchronously. Granted, this might involve including timeouts as well, but I'd argue that those are embraced in today's synchronous processing as well.
  • On top of all this, you may want to both inform and solicit feedback from your end users about how they experience your app and its behavior.
  • Regardless what anybody tells you, if you want to handle this elegantly, it will take some effort on your part.
や莫失莫忘 2024-12-21 03:21:44

最好的办法就是撒谎!

用户不应该知道他们的交易实际上有点像薛定谔的猫,要么是死的,要么是活的。从他们的角度来看,事务是成功的,因为您只需向他们表明事务已成功并将作业排队以进行离线处理。

因为绝大多数交易都是成功的,所以您可以通过适当的补偿机制来处理那些不成功的交易。

The best thing to do is lie!

The user should have no idea that their transaction is in fact a little like Schrödinger's cat, either dead or alive. From their perspective the transaction was a success, because you just indicate to them that it was successful and queue the job away for offline processing.

Because the vast majority of transactions are successful you can then handle those that are not with an appropriate compensationary mechanism.

和我恋爱吧 2024-12-21 03:21:44

无关紧要的情况,例如修改某些记录:

  1. 将用户发送到确认页面,告诉他类似“谢谢,您的输入正在处理。下一步您想做什么?”和几个链接。
  2. 如果您绝对必须将用户发送回已编辑的记录或其列表,那么在非分布式系统中,我们可能正在谈论读取存储更新之前的毫秒数。只要将用户重定向到新页面需要更长的时间,从用户的角度来看,一切都很好。
  3. 如果在某些情况下用户实际上没有“立即”看到他的更新,他可能会致电用户支持。他们告诉他按 F5。什么?现在还在吗?伟大的!在拿起电话之前猜猜他下次会做什么。

离线订单处理等重要案例:

您的域中可能存在“已接收订单”或“待处理订单”的隐式概念。如果你明确这个概念,你就可以向用户呈现准确的信息。

“非常感谢!您的订单已收到,发货后我们会及时通知您最新情况。[单击此处]查看您的待处理订单列表...”

Insignificant cases, like modification of some record:

  1. Send the user to a confirmation page telling him something around the lines of "Thanks, your input is being processed. What do you want to do next?" and a couple of links.
  2. If you absolutely have to send the user back to the edited record or a list thereof, in non-distributed systems we're probably talking about milliseconds until the read store has been updated. As long as it takes longer to redirect the user to the new page, from the user's POV everything's fine.
  3. If in some cases the user actually doesn't see his update "immediately", he might call user support. They tell him to hit F5. What? It's there now? Great! Guess what he does next time before reaching for the phone.

Significant cases like offline order processing:

There might be an implicit concept of a Received Order or Pending Order in your domain. If you make this concept explicit, you can present the user with accurate information.

"Thank you very much! Your order has been received an we'll keep you updated once it has been shipped. [Click here] to see a list of your pending orders..."

甜尕妞 2024-12-21 03:21:44

我认为最简单的事情,什么都不做,往往就足够了。如果用户更改电话号码,并且系统在 1-2 秒内处理此命令,则用户很可能没有机会在此操作之间看到旧数据。

如果这不令人满意,并且您的用户必须绝对知道他的请求已得到满足,您的 UI 可以订阅域事件。命令成功执行后,您的 UI 会收到通知并通知用户。您可以通过多种方式在 UI 中执行此操作。您可以简单地阻止,直到成功通知到达。或者您可以说“我们收到了您的请求”,一旦您得到确认,请在角落的某处显示“您的请求已满足”的通知窗口。

I think the simplest thing, doing nothing, can often be good enough. If user changes phone number, and the system processes this command in 1-2s, it is a good chance user has not had the opportunity to see old data in-between this operation.

If that is not satisfactory, and your user must absolutely know that his request was fulfilled, your UI can subscribe to domain events. Once the command is executed successfully, your UI gets notification and can inform the user. There are various ways you could do this in UI. You could simply block until the success notification arrives. Or you can say "we received your request", and once you get confirmation, show the notification window "your request was fulfilled" somewhere in the corner.

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