What is Spring Boot reactive programming with R2DBC?

Why Interviewers Ask This

Senior Spring Boot engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.

Answer

R2DBC (Reactive Relational Database Connectivity) is a reactive API for relational databases — enables non-blocking SQL database access, unlike traditional JDBC which blocks threads. Used with Spring WebFlux for fully reactive applications. Dependencies: spring-boot-starter-webflux + spring-boot-starter-data-r2dbc + r2dbc-postgresql (or r2dbc-mysql, r2dbc-h2). Configuration: spring.r2dbc.url=r2dbc:postgresql://localhost:5432/mydb spring.r2dbc.username=postgres spring.r2dbc.password=secret. Entity: @Table("users") public class User { @Id private Long id; private String name; private String email; }. Reactive repository: public interface UserRepository extends ReactiveCrudRepository<User, Long> { Flux<User> findByStatus(String status); Mono<User> findByEmail(String email); @Query("SELECT * FROM users WHERE age BETWEEN :min AND :max") Flux<User> findByAgeRange(@Param("min") int min, @Param("max") int max); }. Reactive service: @Service public class UserService { public Flux<User> findAll() { return userRepository.findAll(); } public Mono<User> create(CreateUserRequest req) { return userRepository.save(new User(req.name(), req.email())); } public Mono<User> findById(Long id) { return userRepository.findById(id).switchIfEmpty(Mono.error(new NotFoundException("User not found"))); } }. Transactions in reactive: @Transactional public Mono<Void> transfer(Long fromId, Long toId, BigDecimal amount) { return userRepository.findById(fromId).flatMap(from -> { from.debit(amount); return userRepository.save(from); }).flatMap(saved -> userRepository.findById(toId)).flatMap(to -> { to.credit(amount); return userRepository.save(to); }).then(); }. Limitation: R2DBC has no JPA/Hibernate support — no lazy loading, no entity relationships automatically handled.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Spring Boot answers easy to follow.