1

We're using a hexagonal architecture in one of our microservice. Spring Boot is the framework implementing the service.

For a use case, we need to update a database table (relational) and send a message to a Kafka topic. Quite usual. We don't want to use any CDC or Outbox Pattern, but we want to rely on the transactional manager of Spring.

However, we need some clarification about how to implement this scenario. We don't want to have any dependency on the framework in the application layer (service/use case). How can we implement transactionality? Should we use the @Transactional annotation on the controller? Should we have a single output port, for example, saveAndPublish (I don't like this solution), and put the transaction management in the implementing adapter?

I know that every use case should be transactional by design.

riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
  • What is the reason you don`t want to rely on a Transactional Outbox? Kafka is not really designed to support transactions. – Dinosaur-Guy Feb 02 '23 at 16:59
  • Well, you do have transactions in Kafka, indeed: https://www.confluent.io/blog/transactions-apache-kafka/ Anyway, we want a very easy solution, and Spring gives us all the features: https://docs.spring.io/spring-kafka/docs/current/reference/html/#ex-jdbc-sync – riccardo.cardin Feb 03 '23 at 11:09

0 Answers0