Files
spring-data-demo/r2dbc

r2dbc

Companion code for the ankurm.com post Reactive Data Access with Spring Data R2DBC: CRUD, Transactions and When to Choose It.

Spring Boot 4.1.2, JDK 25, Spring Data R2DBC, r2dbc-postgresql 1.1.3.RELEASE, PostgreSQL 17 (Testcontainers 2.0.5).

What is in here

  • Customer, PurchaseOrder, Account: plain records, one row each. No relationship mapping.
  • CustomerRepository: ReactiveCrudRepository, derived queries, @Query, @Modifying.
  • CustomerOrderService: three ways to load customers with orders (1+N, two queries, one JOIN with DatabaseClient).
  • AccountService: @Transactional and TransactionalOperator, with rollback on error.
  • schema.sql: run by Spring Boot through the R2DBC connection at startup.
  • Tests use StepVerifier and write the transcripts in output/.

Run

cd r2dbc
./scripts/run-all.sh      # needs Docker; regenerates output/*.txt

output/07-throughput-indicative.txt is an indicative JDBC vs R2DBC run on a shared 2-vCPU sandbox. Treat it as a harness, not a result: run it on your own hardware.