How do I ensure issue creation is idempotent?

To ensure we don’t create duplicate issues in jira, our process is:

  1. Create a record in our database with a unique id
  2. Check if we have already created the associated issue by searching for the unique id from step 1. using the /rest/api/2/search endpoint
  3. If it exists, associate the issue key with the record. If it doesn’t, create a new issue

I see that the search endpoint has been deprecated in favour of this one.
Unfortunately that doesn’t guarantee read-after-write, so the issue may be missing from the results. The request has a reconcileIssues parameter to retrieve the latest state, but we do not know those ids!
Does anyone have any advice?

1 Like

I have similar problem with Jira Cloud. 1. our process may not remember all created/edited issue IDs in all scenarios 2. The process may create hundreds or even low thousands of new issues while reconcileIssues may have max. 50 IDs.

I have tried our process with the new search endpoint search/jql on our Jira Cloud dev site, and it seems all changes are propagated immediately or very fast. So, I could not simulate the problem.

I miss some explanation when read-after-write inconsistency may occur and what to do when reconcileIssues cannot be used.

I got a response here with a possible solution. It would be too much work for us to implement.

I can tell you: it can and will happen. We detected a duplicate in our system within the last couple of weeks. There was ~5 seconds between the issue being created and the search for issues, which failed to return the ticket.
We are not creating a high volume of tickets in a short space of time.

1 Like

Thanks for the reply. I guess @radek.dostal proposed solution - custom endpoint with cluster locks and/or use of the db - is just for the Jira server (datacenter) only?

How do you store your unique id in Jira? As a custom field, custom issue property, … or other way? Just curious for which type of JQL read-after-write has failed.

is just for the Jira server (datacenter) only?

I’m sorry, I have no idea.

How do you store your unique id in Jira? As a custom field, custom issue property, … or other way?

Custom field.

1 Like

FYI I have created a similar post for Jira Cloud: Jira API search with reconcile all issues in a project