If I understand your issue correctly, the 20-second delay occurs due to various API calls and the necessary wait time for tasks to appear in the Tasks search feature.
Currently, the search endpoint only delivers tasks a few seconds after creation. This is per-design, as Camunda 8 operates as a distributed system relying less on transactions to ensure high availability in Zeebe. However, it does result in a compromise, data consistency across different components is eventually achieved.
Efforts are underway to enhance this. For more information, please refer to this response in a related topic: Camunda 8: Searching for Active Tasks.
As alternative approaches, consider the following options:
- Utilize a custom exporter (see Exporters | Camunda 8 Docs), which enables building applications in a more event-driven manner.
- Embrace reactive programming and utilize promises for long-running API calls.
- For retrieving process instance keys, Zeebe can provide them synchronously upon starting a process instance.
- When fetching variables from the task list, do you have some response time metrics? Are there a high number of variables or variables with large sizes contributing to the delay? You can maybe specify in the query only the variables names that you really need.
Best regards,
Houssain