How to deal with the failure of using rpc

A registration scenario, operation 1, when the user registers, the account is generated on the sub-platform, operation 2, the rpc service is invoked, and the account is generated on the main platform (1 and 2 are two different databases). The problem is what to do if the call to rpc fails (request timed out, or rpc returns an error, etc.), but operation 1 has been performed

Mar.28,2021

generally rely on two main points to ensure data consistency:
1. Transaction control, for example, operation 1 here does not commit the transaction after execution, operation 2, such as operation 2, returns the normal request, and then commits the transaction of operation 1
2. Compensation mechanisms, such as the business here, can save request information and status, and then scan for inconsistencies between the master database and local library members through scheduled tasks and other operations. If so, do business processing


whether the final consistency can be received in business


timeouts and return errors need to be handled separately

  1. an error is returned: users are generally prompted to try again. Of course, operation 1 also needs to be rolled back
  2. timeout: prompt the user to succeed, confirm whether 2 is successful by message, and retry unsuccessfully

this is the problem of distributed transactions.

is difficult to solve, and there is currently no good solution (open source) for this piece.
look at your project business requirements and control the transaction manually.


look at your business scenario. According to my practice, since the operation of the 1 sub-account has been successful, keep it successful and ensure the function of the user on the sub-platform. The call to the RPC service was generated on the main platform with an error or (connection timeout). Should that be recorded:

if there is an error, an early warning should be sent or a warning email should be sent to the person in charge.
the connection timed out and persisted before execution.

I think if there is an error in the basic function of registration, it is better not to use the user to perceive it, but to deal with it invisibly.
if there is an error in registration and can't register, what is the user's confidence in your product?


transaction rollback, actions 1 and 2 are written in try,catch. Any step that goes wrong will be throw Exception. For example,
try {

$db->beginTransaction();
//if(//1===false){
    throw new Exception('1');
}
if(//2===false){
    throw Exception('2');
}
$db->commit();

} catch (Exception $e) {

$db->rollBack();
return $e->getMessage();

}

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e51326-45104.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e51326-45104.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?