#workpool duplication
3 messages · Page 1 of 1 (latest)
Hi @covert needle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To avoid adding duplicate items to a Convex Workpool, the best practice is to ensure idempotency at the application level. This means you should check for the existence of a "work item" before enqueuing it, typically by asserting invariants within a transaction. Convex mutations are sequentially consistent transactions, so you can safely check your table state before updating records—no race conditions will occur. If you want an "add or skip" behavior, you can implement logic in your mutation to check if the work item already exists (e.g., by a unique key or constraint) and only enqueue if it does not. This avoids the need for additional queries or mutations outside the transaction, and ensures atomicity and correctness.
From a Discord support thread:
"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"
Discord support thread: Idempotency