Messaging

Idempotent job handling

An idempotent consumer makes repeated delivery of the same logical operation safe. A retry should not create a second receipt or apply the same inventory change twice. The crucial distinction is between deduplicating job delivery and making the business effect idempotent. Do not use a process-local Set for durable deduplication. Do not acknowledge merely because an event was seen before its effect committed. Do not retry permanent validation errors as transient failures. Source: https://docs.bullmq.io/patterns/idempotent-jobs Local examples do not establish third-party integration support.

Formal Syntax & Structure

nodejs syntaxnodejs
stable event ID + atomic unique record and business update (design pattern)

Working Example

Example Snippetnodejs
const completed=new Map();let total=0;function apply(id,delta){  if(completed.has(id)){if(completed.get(id)!==delta)throw new Error('conflict');return false;}  completed.set(id,delta);total+=delta;return true;}console.log(apply('e1',3),apply('e1',3),apply('e2',2));try{apply('e1',4);}catch(e){console.log(e.message);}console.log(total);
Node.js Reference