Search code examples
neo4jspring-data-neo4jneo4j-ogmspring-data-neo4j-5

Spring Data Neo4j 5 and the application startup time


In my Spring Data Neo4j 5 project I have the following Neo4j Java configuration:

@Bean
public org.neo4j.ogm.config.Configuration configuration() {

    // @formatter:off
    return new org.neo4j.ogm.config.Configuration.Builder()
            .autoIndex("assert")
            .credentials(username, password)
            .uri(serverDatabaseUri)
            .build();
    // @formatter:on

}

Right now with a data growth inside of my Neo4j database I experienced a significant slowdown during my application startup.

I think one of the possible reasons for this issue can be the following property:

autoIndex("assert")

How to check it and if I'm right - how to improve the application startup time without losing the functionality provided by autoIndex("assert")?


Solution

  • It’s very likely that you are right, as the creation and validation of indexes will take an amount of time proportional to the size of your data; in other words, the more data you have the longer it takes for indexes to be created or validated each time the application starts up.

    Index creation is a convenient feature of SDN. That said, given that the addition or removal of indexes is a fairly infrequent event, typically happening only when you add or remove a domain entity or are starting from an empty database, another option is to remove the @Index annotations and to create a Cypher script that creates or removes the indexes and only execute the Cypher script as needed. This approach allows the application to start as quickly as possible with the tradeoff of having to manually execute a script when needed, which most find to be a reasonable balance.