Search code examples
databasespring-dataspring-data-neo4jspring-repositories

What is difference between Neo4jRepository and ReactiveNeo4jRepository?


I am presently building a Spring Boot backend with REST APIs, which is backed by Neo4j Database. So, while going through the official documentations of Spring Data Neo4j I have observed the usage of ReactiveNeo4jRepository and Neo4jRepository as data repositories for interacting with Database through our program.

But even going through the limited documentation many times I am unable to figure out how to distinguish among them? Kindly help me make this distinction.


Solution

  • Neo4jRepository and ReactiveNeo4jRepository are both interfaces provided by the Spring Data Neo4j project for interacting with Neo4j databases.

    Neo4jRepository is a standard repository interface for interacting with Neo4j using blocking I/O. It provides methods for basic CRUD (create, read, update, delete) operations, as well as methods for executing custom Cypher queries.

    On the other hand, ReactiveNeo4jRepository is an interface for interacting with Neo4j using non-blocking reactive I/O. It extends the Neo4jRepository interface and provides additional methods that return reactive types such as Mono and Flux from the Reactor library, instead of blocking on I/O operations.

    So, the main difference between Neo4jRepository and ReactiveNeo4jRepository is the I/O model they use. Neo4jRepository uses blocking I/O, which can lead to performance issues in high-concurrency environments. ReactiveNeo4jRepository, on the other hand, uses non-blocking I/O which can provide better scalability and throughput in such scenarios.