How do you handle idempotency in Django REST APIs, especially for payment or order endpoints?
Last updated
Idempotency means a retried request causes no duplicate side effects. The client sends a unique key (e.g.
Idempotency-Keyheader) and the server stores it with the result, replaying the response on repeats.Save the key in the same transaction as the side effect with a unique constraint, using
transaction.atomic()andselect_for_updateso concurrent retries collide.POST is not naturally idempotent (unlike GET, PUT, DELETE), so payment/order POSTs need keys. Scope and expire keys, and reject reuse with a different payload.
- https://www.interviewbit.com/django-interview-questions/
- https://www.scribd.com/document/911648753/Headout-Backend-Engineering-Interview-Questions-Bank-CLAUDE
- https://www.uplers.com/
- https://medium.com/@anas-issath/the-django-career-guide-from-junior-to-senior-fea1c3e52aa6
- https://www.quora.com/What-are-some-interview-questions-asked-or-can-be-asked-related-to-Django-and-Python
- https://www.reddit.com/r/developersIndia/
- https://internshala.com/blog/infosys-python-interview-questions/