Idempotency
I’m looking for any recommended ways to implement “idempotent mutations” with Convex.
For instance, in MySQL, idempotency can be achieved using a unique constraint on a column. Similarly, in Temporal, it can be achieved using a workflow ID.
Could I implement it by using the .unique() query to throw an error and fail the transaction? Are there any potential pitfalls I should be aware of? Thanks in advance!
3 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
hi! yes, convex mutations are sequentially consistent transactions
so your latter suspcion is correct. just assert whatever invariants you want in your transaction before you commit
if you want to apply something only once, you can just check your table state before updating records. no race conditions will occur
Got it. Thank you!