REST 和事务回滚 [英] REST and transaction rollbacks

查看:61
本文介绍了REST 和事务回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个不同的 RESTful 服务,它们托管在使用不同数据库的不同服务器上.我有一些 RESTful 服务,它们在应该是事务单元的地方调用了多个这样的服务.如果这些 RESTful 服务中的任何一个失败,我们最终会遇到数据一致性问题.是否有一种巧妙的架构方式来编排回滚?还是让事务管理器成为可行的方法?

I have a few different RESTful services that are hosted on different servers which use different DBs. I have a few RESTful services which call multiple such services above in what is supposed to be a transactional unit. We end up with data consistency issues if any of these RESTful services fail. Is there a neat architectural way of orchestrating a rollback? Or is having transaction managers the way to go?

举一个简单的例子,RESTful 服务 1 有一个 POST 请求,它将 thingamajig 的项目数减少了 1.RESTful 服务 2 发布付款.如果服务 2 失败了,我们如何在没有新的 RESTful 退款服务的情况下干净地实现服务 1 的回滚(如果必须这样做,也可以).我正在寻找上述问题的架构答案,这符合 REST 原则.

As a simplistic example, RESTful service 1 has a POST request which reduces item count of thingamajig by 1. RESTful service 2 POSTs a payment. If service 2 fails, how can we cleanly implement a rollback on service 1, without having a new RESTful refund service (it is ok if this has to be the way to go). I am looking for an architectural answer to above issue, which is in keeping with REST principles.

推荐答案

分布式事务很复杂,需要每个参与系统都支持回滚的概念.就您的服务而言,它们都必须支持某种形式的回滚.以同步的方式在分布式系统中协调这样的事情可能不切实际或不可取.在这种情况下,您可能希望异步回滚,系统最终会在未来的某个时间点达到一致性.显然还有很多其他细节(超时、错误处理、重试等).

Distributed transactions are complex and require each participating system to support a notion of rollback. In the case of your services, they would each have to support some form of rollback. Co-ordinating something like this in a distributed system may not be practical or advisable in a synchronous way. In a situation like this, you would want to asynchronously roll back and the system would eventually reach consistency at a certain point in the future. There are obviously many other details (timeouts, error handling, retries, etc.).

有关最终一致性的更多详细信息,请查看维基百科条目此处.

For more details on eventual consistency, check out the wikipedia entry here.

这篇关于REST 和事务回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆