Moving value between two internal wallets should produce one coherent result: the source is debited and the destination is credited according to the same approved transfer. Separate updates leave room for partial outcomes and confusing recovery. An atomic design brings validation, balanced postings and the operation's durable status into a controlled transaction, while treating external side effects as a separate concern.

Define the transfer’s invariant

State what must remain true after every committed transfer. For a same-currency transfer without a fee, the debit and credit should balance. If a fee exists, represent its destination explicitly rather than allowing value to disappear into an unexplained difference. Keep currency and amount representation consistent with the ledger's precision rules.

Distinguish available funds from held or restricted amounts according to the product's existing balance model. The transfer must validate the balance it is actually allowed to consume. A displayed total is not necessarily the spendable amount. Document the invariant in business terms so product, finance operations and engineering can review the same rule before it becomes database code.

Validate and post within one controlled boundary

When both wallets are managed in the same transactional database, use a transaction that covers the relevant checks, postings and committed operation record. Concurrency control must prevent two simultaneous transfers from both spending funds that only support one of them. Choose locking or isolation behavior deliberately and test it under contention.

Do not assume wrapping statements in a transaction automatically resolves every race. A read followed by an update can still require appropriate isolation or locking to protect the intended invariant. Keep the transaction focused and avoid waiting on a remote provider while holding wallet locks. Slow external calls can turn a small transfer into a broad availability problem.

Separate durable postings from notifications

After commit, the application may need to update a read model, notify the user or publish an event. Those activities should not create a second transfer if they fail and retry. Use a durable event-publication pattern that links downstream work to the committed operation without pretending a database transaction extends automatically across unrelated services.

If the architecture places the wallets in separate transactional systems, acknowledge that the problem has changed. A local transaction cannot atomically commit both systems by itself. Use a deliberately designed distributed workflow and its recovery semantics, or reconsider the boundary. Calling several successful API requests atomic does not make partial failure disappear.

Prove retry and reversal behavior

Give the logical transfer a stable identifier and enforce uniqueness so a repeated request returns the existing outcome. Test a lost response immediately after commit, concurrent duplicate submissions and a process failure before commit. The final balances and posting count should remain consistent in each case.

Correct a committed mistake through an explicit linked reversal or adjustment according to the ledger model, preserving the original history. Do not erase evidence by editing past postings in place. The completion checklist covers balanced entries, protected availability, stable operation identity and recoverable downstream work. An internal transfer is dependable when repeated execution and interrupted execution both converge on the intended durable result.

TAKE IT FORWARD

The key decisions.

  • Express fees, currency and available funds in explicit invariants.
  • Protect checks and postings with appropriate transaction concurrency.
  • Keep retries unique and corrections linked to the original history.

Sources & further reading

Primary references for the concepts discussed. Check the applicable documentation when planning implementation.

  1. PostgreSQL: transactions