Idempotency
A payment callback may arrive more than once, but the same order must count as paid only once.
A payment callback may arrive more than once, but the same order must count as paid only once.
Repeating the operation changes the target result.
Replace duplicate handling with an atomic claim: The provider may deliver event evt_7f2 concurrently. The server identifies one business action by its event id and uses a unique constraint or equivalent operation to claim processing atomically. Other requests only read the in-progress or saved result without creating or charging again.
How to observe the improvement: Give both first and repeated callbacks a clear result so the caller can stop retrying. After delivering the event concurrently, verify that there is still one order, one payment state change, and a matching trace record.
Another case: repeated form submission: When a slow network makes someone click Create project several times, the client can reuse one idempotency key for that creation. The server atomically claims the key and reuses the first result instead of creating multiple projects.
Make the payment callback idempotent: use the provider's stable event id as a unique key and claim processing with a unique constraint or equivalent atomic operation before the business effect. Return an already-processing or saved result for repeats without creating or charging twice. Deliver the same callback concurrently at least twice and verify that one request gains ownership and only one business state change occurs. Protect the external charge with the same idempotency key or an equivalent mechanism.