How do you safely retry a transaction after an error?

A payment service charges customers within a database transaction. Sometimes PostgreSQL returns a serialization failure. In other cases, the application sends COMMIT, but the connection drops before the database responds. How are these situations different? Design a retry strategy that prevents customers from being charged twice.

ExplainTransactions and locksSeniorBackendData EngineerQA