Avoiding Double Payments in a Distributed Payments System
medium.com
medium.com
they mention using a deterministic key for this kind of problem but that can be tough too
But more importantly, as far as I can tell, the ID generation happens in the preRPC phase and is commuted to the database. The RPC call is only done after the ID is persisted so if any crashes occur the pre and post logs can be automatically reconciled.
This system looks a lot like a combination of command and event sourcing with a nice library for putting the right actions in pre, rpc, and post.