NOTE

2.8 Reliable-Message Eventual-Consistency Implementation: Local Message Table

Using points awarded after an order as an example, the service creates the order and writes a message within a local transaction, then uses messaging to drive the points service.

Distributed Systems1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. What Is a Local Message Table?

Consider two transactions: placing an order and then awarding points.

Service A handles orders, and Service B handles points.

  1. Service A executes ordering logic.
begin transaction;

1. place order
2. insert log into local message table

commit transaction;
  1. After Service A successfully places the order, it sends a message to MQ.
  2. Service B consumes the message and processes its local transaction.
begin transaction;

1. insert message into local message table
2. add points

commit transaction;
  1. After Service B executes successfully, update the status in the local message table.
  2. Service B message-table status [ZooKeeper can be used for decoupling].
  3. Service A periodically scans the message table and sends unprocessed messages to MQ.

2. Characteristics

This approach depends on MQ and a database. The initiator can implement a scheduled task to poll for failed messages and resend them.

2PC vs Local Message Table

The local message table introduces MQ and executes distributed transactions asynchronously, improving throughput.

Local Message Table Implementation

RocketMQ Transaction Messages

RocketMQ Transaction Messages

3. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub