How to dynamically set process instance TTL for subprocesses based on variables (optimize cleanup for long-running parent process)

Hi everyone,

I’m working on optimizing database cleanup in a Camunda 7 environment, since our database has grown quite large over time. Our processes are long-running (spanning years) and involve multiple subprocesses.

I want to use characteristics from the parent instance to dynamically determine the Time to Live (TTL) of each subprocess — without having to wait for the root process instance to finish.

Here’s the scenario:

  • The root process represents a customer subscription.
  • Each subprocess represents a periodic billing cycle.
  • Depending on the subscription type, a variable frequency is defined:
  • If frequency = monthly, the billing subprocess data should be kept for 3 months.
  • If frequency = yearly, the billing subprocess data should be kept for 1 year.

I’m looking for the best way to implement this.

My initial idea was to, at the end of each billing subprocess, store its process instance ID and make an API call (via script) to update the TTL of those instances. But this approach doesn’t seem very efficient or elegant.

Is there any recommended way to set or adjust the TTL dynamically, based on process variables, for subprocesses that belong to a long-running parent instance?

Or any best practices for cleanup configuration in this type of use case?

Thanks in advance for any insights or suggestions!

Update: best solution I’ve found so far is to use the parent process to overwrite the removal time for child’s processInstanceId via script.

It works as intended, but I’ve got serious concerns about performance issues.

Any other ideas?

Hi @Neeniih

I believe your approach of using the parent process to overwrite the removal time through a script is valid.

You can monitor its performance and if any issues arise, you can configure the update removal time logic to run on the same day during off-peak hours.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.