Best practice using autoCommit in camunda-engine

Hello community! I’d like to discuss how to use autoCommit option in camunda engine.

Short intro.
I,m using camunda-engine 7.16 with spring-boot-2.6.3 running on openjdk-15 and postgres-13 as storage.
As all you know, by default spring-boot uses HikariPool. There is an autoCommit option in this pool.

autoCommit
This property controls the default auto-commit behavior of connections returned from the pool. It is a boolean value. Default: true.

Spring boot uses same behaviour by default spring.datasource.hikari.auto-commit.

From the other hand, camunda-engine implementation is based on Command-pattern. There are various Commands, CommandContexts and CommandExecutors.
If we take a look into org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl we can see special CommandInterceptors for transaction handling. In case using spring and spring boot, org.camunda.bpm.engine.spring.SpringTransactionInterceptor implementation will be used.

Under the hood, SpringTransactionInterceptor interacts with spring TransactionManager and TransactionTemplate. In case using spring and spring boot, org.springframework.jdbc.datasource.DataSourceTransactionManager implementation will be used.

The problem
DataSourceTransactionManager can detect how autoCommit is configured. In case autoCommit is true, txManager sets its value false explicitly at the begin of transaction and change it back at the end.
See org.springframework.jdbc.datasource.DataSourceTransactionManager#doBegin and org.springframework.jdbc.datasource.DataSourceTransactionManager#doCleanupAfterCompletion for details.

Also there is important comment in doBegin method

// Switch to manual commit if necessary. This is very expensive in some JDBC drivers,
// so we don't want to do it unnecessarily (for example if we've explicitly
// configured the connection pool to set it already).
if (con.getAutoCommit()) {
	txObject.setMustRestoreAutoCommit(true);
	if (logger.isDebugEnabled()) {
		logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
	}
	con.setAutoCommit(false);
}

The question
I’d like to know should I use autoCommit=true or autoCommit=false with camunda-engine. Are there any best practices for this?

Respected community, can you please explain your point of view on the question how to use autoCommit.

Thanks!

Hi @AnonymousVovus,

some context is given here: Transactions in Processes | docs.camunda.org

Especially:

When you configure a transaction manager, make sure that it actually manages the data source that you have configured for the process engine. If that is not the case, the data source works in auto-commit mode. This can lead to inconsistencies in the database, because transaction commits and rollbacks are no longer performed.

Hope this helps, Ingo

Hello @Ingo_Richtsmeier!

Thanks for your answer.

I’m sure that DataSourceTransactionManager is configured properly and ProcessEngine uses same datasource.

I’ll try to reformulate my question.

For example i’m going to run default camunda distro: camunda-bpm-platform-run-7.16.0.

Does it make any sence changing autoCommit option?

  • autoCommit=true - will it affect db performance with some extra commits?
  • autoCommit=false - will i have some data inconsistency in db in this case?

Does it matter to pay much attention to this property, or camunda works well in any case?

Maybe there are some public statistics form customers. For example most customers are using autoCommit=true and they are happy ) or vice versa :slightly_smiling_face:

Hi @AnonymousVovus,

No. If you use autoCommit, you may see unexpected behavior of the process engine.

Hope this helps, Ingo

@Ingo_Richtsmeier sorry for my misunderstanding.

No. If you use autoCommit, you may see unexpected behavior of the process engine.

Do you mean autoCommit=true?

Yes.

In other words: Let the engine handle the commits by itself.

Hope this helps, Ingo

Thank you very much @Ingo_Richtsmeier! :+1: