I plan to use PHP to connect to 2 remote servers. One is a MySQL database. The other one is a Job Queue server.
For every Job that I push to the Job Queue server, I want to ensure that (exactly) 1 record is inserted into the MySQL DB. I want to ensure that the MySQL DB records and the Job Queue tasks execution are 100% in sync.
Since both are remote servers, I am worried that sometimes there may be connection problem to one of the servers (or both).
In my PHP application, how can I ensure that 2 remote operations complete successfully, and rollback all operations if 1 of the remote operations fails? Is there any programming best practices that I should follow for this kind of scenario?