I want to implement idempotency for the creation of new process instances. New processes are created by incoming messages (in a MessageListener).
The message payload has a ProcessDefinitionKey and arbitrary variables incl. a BusinessKey.
Goal: Duplicate messages must not start a process again (no time constraint yet).
Defintions in this Context:
Two messages are the same (Duplicates) when the ProcessDefinitionKey and all Variables in the message payload are the same (Payload is a JSON String).
We do not want to rely on the unique constraint for the business key - or at least not for now, although this might be the easiest approach to achieve idempotency.
For the implementation I looked at the HistoryService as the “Cache” for identifying Duplicates. There I need to query:
processes with a given ProcessDefinitionKey and initial variables, i.e. variable values at the start of the process.
You could consider normalising your process variable name/value pairs, then producing a hash of the content and storing it as another process variable. This hash would represent the initial state which would not change with subsequent updates. Thus you can also perform a variable query through history using this value which should be more efficient than scanning for multiple variables…