User Task Not Immediately Available in Tasklist After Service Task

Hi, I’m using Camunda 8.6.7 to design a process.

  • I use a Worker Service in Node.js with @camunda8/sdk.

I’m designing a process similar to the diagram above (this is just an example, not the real process).

Node.js:

  • API: /start { word, apikey }
    → Calls Camunda Start Event
  • API: /translate { actions: [ { from: 'en', to: 'thai' }, ... ] }

Process Flow:

Start Event → Check Permission → Call Webhook API (send action list) → User Task → Handle → End

Code (complete user task):

ts

CopyEdit

async completeTask(processInstanceKey: string) {
  const camunda = this._client;
  const tasks = await camunda.getTasklistApiClient().searchTasks({
    processInstanceKey,
    taskDefinitionId: process.env.USER_SELECT_LANGUAGE_TASK
  });

  const task = tasks[0];

  if (!task) {
    throw new NotFoundException('Not found task');
  }

  return camunda.getTasklistApiClient().completeTask(task.id);
}

My Issue:

  • After calling the webhook API (to send the action list to the backend → then emit via socket to the frontend),
  • The user clicks on actions in the frontend and sends them to the backend → this triggers the /translate API call.
  • However, for some reason, the User Task (with activity ID taskDefinitionId: process.env.USER_SELECT_LANGUAGE_TASK) has not yet been created, so the process seems to pause, and an error is returned to the frontend.
  • I’ve tried using recursion to retry searchTasks (5 times, 5 seconds apart), but I don’t think this is a good solution.

First of all, it is recommended to use Camunda User Tasks (Zeebe User Tasks) instead of the Job Worker implementation for User Tasks. The Job Worker approach has been deprecated since Camunda 8.7 (you can check the docs).

This is important for your issue because Job Worker User Tasks are slower compared to Camunda User Tasks. Job Worker tasks go through a longer path since they are not managed directly by the Zeebe engine, so any modifications or creation events take more time. In contrast, Camunda User Tasks are managed and stored by the engine, making them much faster, the task is available immediately after the preceding service task completes.

If you want the task to be displayed instantly in your frontend, you can also implement custom listeners on User Task events. For example, listen for UserTask Created events and emit them to the frontend via WebSocket. With this architecture, you can achieve real-time user task updates, which should solve the issue of tasks not being available immediately after your service task.