Reactive Spring with Kotlin and Pg

  • Spring WebFlux with Netty instead of Spring Web with Tomcat

  • Mono and Flux in all layers (controller, service, repo)

  • JDBC/JPA/Hibernate, Spring Data JDBC (javax.persistence) are non-reactive and hence not used for reactive approach

  • Two alternatives : 1. Spring Data R2DBC and 2. Reactive Hibernate

1. Spring Data R2DBC

  • Instead R2DBC(Reactive Relational Database Connectivity) and Spring Data R2DBC is used

  • No automatic table generation in R2DBC and less mature/ less features than JPA/Hibernate so flyway or liquibase are used for schema generation

  • Spring Data R2DBC provides ReactiveCrudRepository interface

  • is used to indicate that a given class represents a table (does not create table in db, only representation )instead of javax.persistence.Table


interface UserCredentialsRepo : ReactiveCrudRepository<UserCredentials, Int>






Limitations of Spring Data R2DBC :

  • doesn’t deal with the relationship between entities itself . We will have to find a solution and do something manually

  • no support for auto-generated id

Spring Data R2DBC aims at being conceptually easy. In order to achieve this it does NOT offer caching, lazy loading, write behind or many other features of ORM frameworks. This makes Spring Data R2DBC a simple, limited, opinionated object mapper.

Spring Data R2DBC Not fully ready for every production project .

  • Projects without high concurrency issues don’t need to use it
  • Some useful functions have not yet been realized ( For example, improving relationship management ).
    But they’re in the team roadmap , Even if a clear release date has not yet been defined .Spring The team fully understands the needs of the developers , And working on it .

For all that , in some special cases , if the development team is ready to do more manual work , what is worth considering is R2DBC performance improvements.

References :

2. Hibernate Reactive

  • Hibernate started a subproject — Hibernate Reactive for Reactive Streams support

  • Spring still did not embrace Hibernate Reactive

  • We should deal with internals of Hibernate like SessionFactory, CriteriaBuilder, etc.

  • The reactive stream is represented using a chain of Java CompletionStages or Mutiny Unis and Multis ( alternatives of Mono and Flux )

  • Hibernate Reactive uses the reactive engine Vert.x and its non-blocking SQL client libraries (not R2DBC).

References :


View Github