Recently I've been working on finding a proper solution for distributed transaction, and I found this: http://www.codeofhonor.com/blog/wp-content/uploads/2012/04/Patrick-Wyatt-Writing-reliable-online-game-services.pdf
The pdf file's content comes from a lecture by Patrick Wyatt in GDC 2012, and I believe many guys have read it.
In this lecture, Patrick showed how he solved the consistency of trade between two players distributed in two different databases(not by using XA), the approach is to achieve 'eventual consistency' by using a consistent 'transaction queue'. I will explain this approach below briefly.
------------------>>>>
1. Let's suppose player1 is in db1, player2 is in db2. And player1 wanna give $10 to player2.
2. We first commit a transaction to db1, like this
begin_transaction_in_db1
update player set money = money - 10 where id = money_giver_id;
insert into transaction_queue values(db2, 'increase_player_money', money_receiver_id, 10);
end_transaction
What we insert into the table transaction_queue is essentially a promise-- we will increase the money_receiver's money in the future.
3. A worker process will scan the table transaction_queue in db1, and when it gets the new record inserted above, it will commit a transaction to db2, like this
begin_transaction_in_db2
update player set money = money + 10 where id = money_receiver_id;
end_transaction
4. By implementing like above, we can acheive eventual consistency.
---------------<<<<
I have found many similar idea like this, to avoid using the high-latency XA function provided by mysql.
But I'm really wondering: what if transaction2 fails while transaction1 succeeds? Apparently, we will be unable to rollback transaction1 when we find transaction2 has failed, because at that time transaction1 has been committed already...