问题
在了解一致性哈希算法之前,最好先了解一下缓存中的一个应用场景,了解了这个应用场景之后,再来理解一致性哈希算法,就容易多了,也更能体现出一致性哈希算法的优点。
...You have applied the Database per Service pattern. Each service has its own database. Some business transactions, however, span multiple service so you need a mechanism to implement transactions that span services. For example, let’s imagine that you are building an e-commerce store where customers have a credit limit. The application must ensure that a new order will not exceed the customer’s credit limit. Since Orders and Customers are in different databases owned by different services the application cannot simply use a local ACID transaction.
...咱们先来看看业务场景,假设你现在有一个电商系统,里面有一个支付订单的场景。
那对一个订单支付之后,我们需要做下面的步骤:
这是一系列比较真实的步骤,无论大家有没有做过电商系统,应该都能理解。
进一步思考
好,业务场景有了,现在我们要更进一步,实现一个 TCC 分布式事务的效果。
什么意思呢?也就是说
上述这几个步骤,要么一起成功,要么一起失败,必须是一个整体性的事务。
假设现在订单的状态都修改为 “已支付” 了,结果库存此时库存已经是 0,因此该订单下单失败。
结果呢?还是扣了用户的钱,这不是坑人吗?
...