Clean Architecture vs Hexagonal Architecture: Which One Should You Choose for Microservices?
HTML-код
- Опубликовано: 23 ноя 2024
- Is it better to use Hexagonal Architecture or Clean Architecture for microservice applications?
💎 Be a Patreon to get the source code: / gsferreira
🔗 Reddit: / clean_architecture_vs_...
🚨 KEY LINKS
🤝 Support me on Patreon (and get access to source code) here: / gsferreira
💌 Free Developer Insights: guiferreira.me...
📘 Courses: guiferreira.me...
👨🏫 Workshops: guiferreira.me...
🔗 GET IN TOUCH
LinkedIn: / gferreira
Twitter: / gsferreira
GitHub: github.com/gsf...
Get my newsletters: guiferreira.me...
Visit my blog: guiferreira.me
👋 WHO AM I
Hey! If you're new to my Channel, I'm Guilherme. Call me Gui. I'm a Minimalist Software Craftsman. What do I do here? I share tips on how to simplify your life as a Developer.
#coding #programming
Fantastic video Gui! 👌, these brief clarifications are always great to understand the basics, thanks for sharing. And I agree that, as a general rule of thumb, I like the simplicity of Hexagonal Architecture.
And I say this after having mainly applied CA in the projects I have worked so far.
Thanks Xavier! We all have been there
For non complex applications I like using Vertical Slices (used N-Tier architecture before). For more complex I moved from Clean Architecture to Clean Architecture + Vertical Slices.
From Clean Architecture I have Domain and Infrastructure layers. Application and Presentation layers I combine into Vertical Slices. Sometimes I can even combine Infrastructure layer into Vertical Slices too
So you have slices only on the application core?
The 2 are not mutually exclusive.
Yes. As I said, CA is an expansion of HA.
I've been studying Hexagonal Architecture to solve problems in my current project, and its simplicity fits well with my case.
I'm confused about organizing shared things between the projects, for example, the logging service.
To brief, I have the core and an adapter to fetch data from an outside API. So I use a service to centralize the logs.
I should log all requests and responses in the adapter and log errors that can occur in the core flow.
In this scenario, where is the best local to implement the log?
- Inside the core and exposes it to the adapter?
- Outside the core and the adapter and reference it on both projects?
- In a new adapter?
IMO for the logs you can just create a interface in the Core/Domain project and use where you want.
More logs = more costs, so try use only when is necessary
@@JoaoVictorFerreira-xx1rq But if I create only an interface the adapter will be responsible to implements the log logic. So I will should inject the log library in the adapter.
@@diegofaria8187 exactly, this design pattern is called faced, is very useful when you would like to use a library but not create a wrong dependency in all your application, so you call it by your interface
Your code needs a port to the logging service if the logging service has IO. That is the code that needs to be on an adapter. That means you can have the core using the Port (interface) and the code that sends the logs somewhere is an adapter.
Does that make sense?
If the logging service has any kind of logic, you can segregate the logic from the “writing” part. In that case, they will be in different places. One in the core, the other as an adapter