A sequence of

Listen to the next nai education sun Xuan big man’s class. The video lasted three hours. It would have been better if it had been reduced to an hour.

Take notes:

The second directory

2.1 The nature of distributed transactions

1 A request involves multiple storage systems

For example, multiple dB, or DB + Redis, DB + MQ, DB + ES

2. Business scenario Tolerance: goods + orders + payment

Service scenarios: Synchronous and asynchronous

2.2 Universal methodology

1. Split

2. Compensation: Forward compensation

  

Here’s how Redis executes transactions with multiple operations:

You can use lua scripts or redisson’s locking. The essence is to consolidate multiple atomic operations into a single local transaction.

Scenario 3: DB and MQ

Scenario 4: DB and ES: ES does not provide local transactions. This intelligent maximum retry mode is used to manually intervene with error logs after a failure.

3 Asynchronous Scenario

Timeout not paid: closed

Place the order with 1.

2. Send the mq:

Local transaction: possible, mq send timeout, style successful but ACK failed. This is where combining two into one local transaction is problematic.

The timing adjustment is not a solution.

2PC: If no compensation is provided, you can only retry after negotiation

Because ACK is unreliable, you need to rely on the backcheck interface that provides the DB to verify that the DB is written successfully. This MQ is transactional MQ.

The above scheme is too complex and not general enough. The optimization scheme is as follows:

This is theoretical. Because ack may time out, messages may not be idempotent, and repeated submissions may occur.

 

This is a complete process that relies on the scheduled task to handle:

If the task fails to be sent, it will join the retry queue (time round).

Because it is a memory queue, and when the system restarts: added a leak thread (check directly from db), this single thread processing line, do not need to run every node, so need to add a lock mark to do.

There are also cleaning threads: processing historical data.

* * * * * * * * * * * * * * * *

Can be tailored according to their own business conditions, not so complex.