# Multiple instances cf applications create multiple instances of flowable-engine as well

**URL:** <https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629>\
**Category:** Uncategorized\
**Created:** [October 3, 2019, 8:47am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629 "2019-10-03T08:47:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 3, 2019, 8:47am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/1 "2019-10-03T08:47:31Z")

</div>

Hello Flowable Team,

I’ve deployed an application in CF with bpmn. Now I’m adding/reducing the number of instances of the application based on the load on it, but the issue is, with new application instance, there is a new flowable-engine getting created. So the process instance which was created by engine1 is not recognized by engine2.

But according to my scenario, I need only one flowable-engine for any number of application instances. Is it possible somehow, following are the ways which I can think of,

1. One separate application with flowable bpmn which can be consumed by other applications instances
2. any configuration which can limit the flowable-engine to 1 regardless of how many instances of an application I have (if there is something available like this)

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [October 3, 2019, 3:05pm UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/2 "2019-10-03T15:05:38Z")

</div>

> [@aashi](#):
>
> So the process instance which was created by engine1 is not recognized by engine2.

Multiple instances of the engines pointing at the same data source should have a shared knowledge of process instances. Are you using different datasources for flowable in each instance of your microservice?

> [@aashi](#):
>
> 1. One separate application with flowable bpmn which can be consumed by other applications instances

If you don’t need the engine to scale along with other aspects of the microservices, you can separate them and use the REST interface to interact with the engine. I would still recommend having at least two instances for high availability.

> [@aashi](#):
>
> 1. any configuration which can limit the flowable-engine to 1 regardless of how many instances of an application I have (if there is something available like this)

I don’t think this is possible, the standard way to do that with microservices is to separate logic that does not need to scale at the same time into different services.

Will

---

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 4, 2019, 4:25am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/3 "2019-10-04T04:25:35Z")

</div>

Hello @wwitt,

I’m using the same datasource and in this case, according to you all the flowable-engines should point to a shared knowledge to get the information about process instance.

In my scenario,

1. I’ve one call to create the process instance
2. The second call starts that process instance by id and proceed

But I found that another instance of the application(where the new instance of flowable-engine also got created) was unable to recognize the process instance id, even though the datasource is same. This is the way =\> [https://www.flowable.org/docs/userguide/index.html#springSpringBoot](https://www.flowable.org/docs/userguide/index.html#springSpringBoot) I’ve used to create the process engine(using beans).

What could be the possible reason?

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [October 4, 2019, 12:34pm UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/4 "2019-10-04T12:34:27Z")

</div>

I see two possibilities:

1. There’s a misconfiguration that is causing you to believe they are pointed at the same database but you aren’t actually
2. The process has either not hit a wait state so that the database transaction can finish or the process has already finished (possibly due to an error).

Some questions:

- What database are you using? In memory databases like H2 are not shared between instances and cane cause behavior like this.
- If you just used the starter did you perform any custom configuration or initialization of the process engine? If so, can you share it?

Will

---

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 5, 2019, 8:25am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/5 "2019-10-05T08:25:02Z")

</div>

Hello @wwitt

Answer to your questions,

- I’m using postgres db which I believe should be shared between the instances and not cause the problem

- Here’s the class for flowable configuration which i’ve created

public class FlowableEngineConfiguration {

```
private final Logger logger = LoggerFactory.getLogger(FlowableEngineConfiguration.class);

@Autowired
public DataSource dataSource;

@Autowired
CASPostgresDbProvider casPostgresDbProvider;

@Autowired
CASDbService casDbService;

private void init() {
    casDbService.updateAdminTenant();
}

@Bean(name = "processEngineConfiguration")
public ProcessEngineConfigurationImpl processEngineConfiguration(){
    init();
    javax.sql.DataSource ds = (javax.sql.DataSource) dataSource;
    SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
    processEngineConfiguration.setDatabaseSchema(casPostgresDbProvider.SCHEMA_NAME);
    processEngineConfiguration.setDataSource(ds);
    processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    processEngineConfiguration.setTransactionManager(annotationDrivenTransactionManager());
    logger.info("processEngineConfiguration bean created");
    return processEngineConfiguration;
}

@Bean(name = "ProcessEngine")
public ProcessEngine processEngine(){
    try{
        logger.info("ProcessEngine bean created");
        return processEngineConfiguration().buildProcessEngine();
    }catch(Exception e){
        throw new RuntimeException(e);
    }
}

@PostConstruct
public void deployDefinedProcess(){
    repositoryService().createDeployment().name("myprocess")
            .addClasspathResource("/processes/myprocess.bpmn20.xml").deploy();
}

@Bean(name = "transactionManager")
public PlatformTransactionManager annotationDrivenTransactionManager(){
    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
    javax.sql.DataSource ds = (javax.sql.DataSource) dataSource;
    transactionManager.setDataSource(ds);
    logger.info("transactionManager bean created");
    return transactionManager;
}

@Bean
public RepositoryService repositoryService(){
    return processEngine().getRepositoryService();
}

```

}

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [October 5, 2019, 11:55pm UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/6 "2019-10-05T23:55:36Z")

</div>

I’m assuming that you are you’re binding the database service and allowing the app to pick up the auto-configured credentials. I know I’ve had some trouble getting the app to pick up the connection information. Can you verify you have the correct spring cloud dependencies?

```auto
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-spring-service-connector</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-cloudfoundry-connector</artifactId>
        </dependency>

```

---

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 7, 2019, 4:44am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/7 "2019-10-07T04:44:25Z")

</div>

Hello @wwitt

Yes, you’re right. There is a postgres db instance which I’ve binded with my application.

And, I’ve added “spring-cloud-cloudfoundry-connector” in my pom but not the other one. How would these dependencies would help?

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [October 7, 2019, 7:36am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/8 "2019-10-07T07:36:34Z")

</div>

`spring-cloud-spring-service-connector` may not be strictly required it looks like its dependencies are in `spring-cloud-cloudfoundry-connector`. They are the method that the bound VCAP\_SERVICES provided to the app by CF get turned into datasources. My theory is this:

- Looking for a process by process id is simply a call to the database
- If one instance of the service can see the process but the other cannot, they must not be looking at the same database
- I have personally had issues getting Spring Boot applications detecting and using CF’s bound datasources if I did not use the correct dependencies.

---

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 7, 2019, 8:54am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/9 "2019-10-07T08:54:10Z")

</div>

Hello @wwitt

In that case should look the datasource which is getting created, whether it’s the same or not?

Few questions which I have:

1. But is it possible that while creating multiple instances of an application, new datasource would be created which is then used for the creation of flowable engine?
2. Are the configurations right for flowable engine, is there any chance the configurations which I’ve made can cause any issues later?

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [October 7, 2019, 9:02am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/10 "2019-10-07T09:02:08Z")

</div>

Looking back at your configuration, this line seems like it might be suspect:

```auto
processEngineConfiguration.setDatabaseSchema(casPostgresDbProvider.SCHEMA_NAME);

```

What does `CASPostgresDbProvider` do? is it possible that different instances are getting different schemas?

---

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 7, 2019, 9:54am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/11 "2019-10-07T09:54:24Z")

</div>

SCHEMA\_NAME is just a final string where datasource name is defined. And, casPostgresDbProvider is an autowired object of class where SCHEMA\_NAME is defined.

---

<div class="post-metadata">

**Author:** ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)\
**Post date:** [October 9, 2019, 5:32am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/12 "2019-10-09T05:32:13Z")

</div>

Hello @wwitt

I learnt that when a new instance of an application gets created in cloud foundry, new data source is also created but it points to the same database.

So, if I’ll try to picture the whole scenario,

multiple application instances ==\> multiple datasources ==\> multiple flowable-engines ==\> one database

ultimately we have only one database which should not cause any problem right?

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [October 15, 2019, 7:55am UTC](https://forum.flowable.org/t/multiple-instances-cf-applications-create-multiple-instances-of-flowable-engine-as-well/4629/13 "2019-10-15T07:55:43Z")

</div>

> [@aashi](#):
>
> ultimately we have only one database which should not cause any problem right?

That shouldn’t be a problem, as long as the schema gets set as a first thing in the connection.
