HEXAGONAL
ARCHITECTURE
Hello!
I am Ygor Castor
● Java Developer for 13 years
● Likes Functional Programming
● Works with several technologies
● Tech Lead at Abn Amro Bank N.V
● Hit me up at LinkedIn @ygorcastor
2
1 Software Engineering 101
Keep it simple, stupid
"There are two ways of constructing a software
design. One way is to make it so simple that there
“
are obviously no deficiencies. And the other way
is to make it so complicated that there are no
obvious deficiencies."
Tony Hoare
4
We all learn at university
◇ “Your software must be cohese“
◇ “Make your services decoupled”
◇ “Be future proof”
◇ “Apply SOLID principles, it’s nice!”
5
Now think about the last
software you worked at
◇ If you need to swap from SQL do NoSQL, how large will be the
impact into your domain rules?
◇ Your Product Owner now wants to have a gRPC api, how much time
will you need to implement it?
◇ You hear the words “Yeah, kafka is not working for us, we will swap
to RabbitMQ”, how many business classes do you have to change?
◇ “I sold to our consumers that we have a GraphQL interface, you
have until friday to implement it.”
6
From 1 to 10, how much your
gastritis hurts right now?
7
8
9
WHY?
10
Software is not only
code
It’s architecture It’s domain
Your architecture design should Your business domain is
allow you to swap technologies untouchable, the outside-world
without much hassle. should not interfere with it.
11
HOW?
Hexagonal Architecture!
12
What is Hexagonal
Architecture?
◇ It’s an architectural pattern.
◇ It’s based on the idea or ports and adapters
◇ Enforces a way to naturally decouple your business from
the technologies employed.
◇ Designed thinking in common object oriented languages
pitfalls.
◇ It’s first draft was released in 2005 and was proposed by
Alistair Cockburn
13
Key Concepts
Ports Adapters Application Core
Interfaces that allow the Implements a Port behavior Your baby, your child!
outside world to interact and adapt it to the outside Should be protected from
with your application core world. the evil things from
(Input Ports) and your outside, here lies your
application core interact domain and business rules.
with the outside world
(Output Ports)
14
15
How does it look like
in Java?
Interfaces, interfaces and interfaces
16
Hello SOLID and DDD!
◇ A port is an interface that defines a behavior.
◇ An adapter is a class that implement a port.
◇ Adapters does not interact directly with your application
core, only through ports.
◇ The ports granularity depends on the use case, you decide!
17
Quick code look?
18
Sample
https://github.com/YgorCastor/hexagonal-tdc2020
19
Thanks!
Any questions?
You can find me at:
◇ LinkedIn: @ygorcastor
◇ Blog: https://ycastor.me
20