# Specify read/write transaction before query execution in spring data neo4j

**URL:** <https://community.neo4j.com/t/specify-read-write-transaction-before-query-execution-in-spring-data-neo4j/33185>\
**Category:** Neo4j Graph Platform\
**Created:** [February 4, 2021, 6:06am UTC](https://community.neo4j.com/t/specify-read-write-transaction-before-query-execution-in-spring-data-neo4j/33185 "2021-02-04T06:06:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajeevprasanna](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rajeevprasanna/32/14868_2.png) [@rajeevprasanna](https://community.neo4j.com/u/rajeevprasanna)\
**Post date:** [February 4, 2021, 6:06am UTC](https://community.neo4j.com/t/specify-read-write-transaction-before-query-execution-in-spring-data-neo4j/33185/1 "2021-02-04T06:06:15Z")

</div>

Hi,  
I am using org.springframework.boot:spring-boot-starter-data-neo4j to connect with graph db.

I am looking for a way to specify read/write for a transaction so that write queries are routes to leader instance and reads are for other instances. This helps to reduce load on leader instance which in turn improve database performance.

_ **How can we specify in code?** _

**Here is my transaction manager with driver instantiation**

```auto
@Configuration
    @EnableTransactionManagement
    class Neo4jConfig(
        @Value("\${spring.neo4j.uri}")
        val neo4jDBUri: String,

        @Value("\${spring.neo4j.authentication.username}")
        val neo4jDbUserName: String,

        @Value("\${spring.neo4j.authentication.password}")
        val neo4jDbUserPassword: String
    ) : AbstractNeo4jConfig() {

        @Bean
        override fun driver(): Driver {
            val config: Config = Config.builder()
                .withMaxTransactionRetryTime(60, TimeUnit.SECONDS)
                .withLeakedSessionsLogging()
                .withRoutingTablePurgeDelay(1, TimeUnit.SECONDS)
                .withConnectionAcquisitionTimeout(2 * 60, TimeUnit.SECONDS)
                .withConnectionLivenessCheckTimeout(2 * 60, TimeUnit.SECONDS)
                .withDriverMetrics()
                .withMaxConnectionLifetime(5, TimeUnit.MINUTES)
                .withMaxConnectionPoolSize(10)
                .build()

            return GraphDatabase
                .driver(neo4jDBUri, AuthTokens.basic(neo4jDbUserName, neo4jDbUserPassword), config)
        }
    }

    // Refer: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4.0-M2-Release-Notes#neo4j-1
    @Bean(ReactiveNeo4jRepositoryConfigurationExtension.DEFAULT_TRANSACTION_MANAGER_BEAN_NAME)
    fun reactiveTransactionManager(
        driver: Driver,
        databaseNameProvider: ReactiveDatabaseSelectionProvider
    ): ReactiveTransactionManager = ReactiveNeo4jTransactionManager(driver, databaseNameProvider)

    // Refer: https://hantsy.medium.com/data-auditing-with-spring-data-neo4j-11d6461146ff
    @Configuration(proxyBeanMethods = false)
    @EnableReactiveNeo4jAuditing
    internal class DataConfig {
        @Bean
        fun reactiveAuditorAware(): ReactiveAuditorAware<String> = ReactiveAuditorAware { Mono.just("Audit enabled") }
    }

```

**query part is like this:**

```auto
class CloudFilesDao(val client: ReactiveNeo4jClient) {
suspend fun addEvent(){
val query = "merge ****"
client
.query(query)
.run()
}
}

```
