I’m currently working on building a Go application following the Clean Architecture principles, and I’ve encountered a dilemma regarding the integration of Temporal into my architecture. Temporal seems to straddle multiple layers, and I’m unsure about the best approach to incorporate it effectively.
At first glance, it appears that Temporal should reside within the Delivery layer (Transport, Infrastructure, or Adapters), as it facilitates the execution of core business logic. However, Temporal also plays a crucial role in ensuring the safe execution of workflows, which is more aligned with the business logic itself. For instance, I can execute private workflows within Temporal, which are not intended for export to other services and do not utilize Protocol Buffers. These workflows can be triggered from various sources such as HTTP, Kafka, or gRPC, indicating a connection to the Delivery layer.
On the other hand, Temporal becomes necessary when exporting business logic to other services using Protocol Buffers, suggesting a closer association with the business logic layer. I’m struggling to determine the optimal organization of code and business logic in this scenario. Could anyone provide guidance on how to structure the code and interfaces to effectively integrate Temporal into a Clean Architecture for a Go application? As an example, I’ve attempted to define interfaces as follows:
type Temporal interface {
PublicWorkflow(ctx workflow.Context, request *temporal.Request) (*pbtemporal.Response, error)
}
type UseCase interface {
PrivateWorkflow(ctx workflow.Context, entity *entity.Entity) (*entity.Entity, error)
}
If I want to use PrivateWorkflow with Kafka, for instance, I’m uncertain whether to implement a temporalClient within Kafka (which may not be ideal) or create an adapter within UseCases. However, the latter approach could potentially violate the principle of keeping UseCases independent of delivery mechanisms.
Any insights or examples demonstrating the best practices for integrating Temporal workflows into a Clean Architecture for Go would be greatly appreciated.
Thank you!