Back to All Discussions
Production-Grade Full-Stack Django & Modern Web Engineering Solved

How do we handle Paystack webhook idempotency when network retries occur?

John Mabadeje
Posted Sep 15, 2026 - 12:23 25 views
If Paystack retries the charge.success webhook multiple times, what is the best pattern in Django to avoid duplicating enrollments or receipts?

Answers & Solutions (1)

ACCEPTED SOLUTION
Kenechukwu Okolie Instructor
2 months, 2 weeks ago
0
Great question! You should store the transaction `reference` as a unique database constraint. When the webhook fires: 1. Lookup the `PaymentTransaction` with `status != SUCCESS`. 2. Wrap the enrollment creation in `transaction.atomic()`. 3. If already marked `SUCCESS`, return HTTP 200 immediately without doing extra work. This guarantees idempotent handling regardless of how many times the webhook retries!

Please log in to reply to this discussion.

Log In to Reply