Hex Arch & Trans Concept

I’m trying to get used to hexagonal architecture and understand how to implement practical problems. I’m having difficulty understanding the level of responsibility extracted to adapters and ports.

As an example, I’m looking into storage and transaction pairs. How should transactions be implemented in hexagonal architecture? Assume we have a simple CRUD service interface inside the domain level:


We want to guarantee transactions when using these methods, e.g. delete+save in one transaction. How should this be designed and implemented according to hexagonal architecture?

Should a TransactionalOperation interface be implemented with external coordination? If so, does this interface need to know how to implement transactions with all implementations of StorageRepoInterface?

Alternatively, should explicit transaction guarantees be provided from StorageRepoInterface inside the domain level?

Where can I find more information on how to approach this problem correctly?

In hexagonal architecture, the responsibility for handling transactions should be extracted to the infrastructure layer using the ports and adapters pattern.

One way to guarantee transactions is to create a port interface for a transaction manager that can coordinate the transactions across multiple repositories. The transaction manager can implement this interface and interact with the repositories to ensure that all operations are wrapped in a transaction.

Another option is to provide explicit transaction guarantees from the repository interfaces by adding transactional annotations or similar mechanisms. This approach can be simpler but may tie the domain layer to a specific persistence technology.

To learn more about how to implement hexagonal architecture and handle transactions, you may want to explore resources such as the book “Implementing Domain-Driven Design” by Vaughn Vernon or the documentation for popular hexagonal architecture frameworks like Spring Boot.