Hexagonal or Functional Core?
Thomas PIERRAIN
@tpierrain
Bruno BOUCARD
@brunoboucard
First: our business
Suggesting seats in Theaters
“I want to find 3 seats
for show Z”
Suggesting seats in Theaters
“I want to find 3 seats
for show Z”
SEATS SUGGESTIONS API
Suggesting seats in Theaters
AUDITORIUM SEATING
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
Suggesting seats in Theaters
AUDITORIUM SEATING
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
Suggesting seats in Theaters
AUDITORIUM SEATING
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
Suggesting seats in Theaters
AUDITORIUM SEATING
API
SEATS AVAILABILITY
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
“I also need to know
which seats are
already reserved for
show Z”
Suggesting seats in Theaters
AUDITORIUM SEATING
API
SEATS AVAILABILITY
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
“I also need to know
which seats are
already reserved for
show Z”
Suggesting seats in Theaters
AUDITORIUM SEATING
API
SEATS AVAILABILITY
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
“I also need to know
which seats are
already reserved for
show Z”
OUR CORE DOMAIN
Suggesting seats in Theaters
AUDITORIUM SEATING
API
SEATS AVAILABILITY
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
“I also need to know
which seats are
already reserved for
show Z”
Suggesting seats in Theaters
AUDITORIUM SEATING
API
SEATS AVAILABILITY
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
“I also need to know
which seats are
already reserved for
show Z”
“Ok. You can have seats
A1, A2, A3 in pricing tier 1,
C4, C5, C6 in pricing tier 2
…”
Suggesting seats in Theaters
AUDITORIUM SEATING
API
SEATS AVAILABILITY
API
“I want to find 3 seats
for show Z” “I need the
auditorium seating
of show Z”
SEATS SUGGESTIONS API
“I also need to know
which seats are
already reserved for
show Z”
“Ok. You can have seats
A1, A2, A3 in pricing tier 1,
C4, C5, C6 in pricing tier 2
…”
Suggesting seats in Theaters
API architecture
(2 options)
Source: http://coder.efelti.com/2018/02/introduction-of-functional-programming.html
Hexagonal in motion
Functional core in motion
From Hexagonal to Functional core
(live coding)
Suggesting seats in Theaters
More Functional?
https://blog.ploeh.dk/2018/03/26/the-maybe-functor/
Makes decisions
Imperative Shell acts upon those decisions
Functional Core - Theater
How to cope with multiple
I/Os in sequence?
Make decisions
Acts upon those decisions
Functional Core – Train reservation
Feature Hexagonal
Architecture
Functional
Architecture
Separate Infra from Business Yes Yes
Business Code without side effect
Business Decision are in Business part
Offers good ability to test
Technical concerns never leak from domain
Hexagonal or Functional Core?
Feature Hexagonal
Architecture
Functional
Architecture
Separate Infra from Business Yes Yes
Business Code without side effect No* Yes
Business Decision are in Business part
Offers good ability to test
Technical concerns never leak from domain
* By its requirements Functional Architecture is more extreme (code without mutation) and therefore
more addressable with functional language.
The hexagonal architecture is more favorable to the OOP
Hexagonal or Functional Core?
Feature Hexagonal
Architecture
Functional
Architecture
Separate Infra from Business Yes Yes
Business Code without side effect No* Yes
Business Decision are in Business part Yes Yes
Offers good ability to test
Technical concerns never leak from domain
Hexagonal or Functional Core?
* By its requirements Functional Architecture is more extreme (code without mutation) and therefore
more addressable with functional language.
The hexagonal architecture is more favorable to the OOP
Feature Hexagonal
Architecture
Functional
Architecture
Separate Infra from Business Yes Yes
Business Code without side effect No* Yes
Business Decision are in Business part Yes Yes
Offers good ability to test Yes Yes
Technical concerns never leak from domain
Hexagonal or Functional Core?
* By its requirements Functional Architecture is more extreme (code without mutation) and therefore
more addressable with functional language.
The hexagonal architecture is more favorable to the OOP
Feature Hexagonal
Architecture
Functional
Architecture
Separate Infra from Business Yes Yes
Business Code without side effect No* Yes
Business Decision are in Business part Yes Yes
Offers good ability to test Yes Yes
Technical concerns never leak from domain No Yes
Hexagonal or Functional Core?
* By its requirements Functional Architecture is more extreme (code without mutation) and therefore
more addressable with functional language.
The hexagonal architecture is more favorable to the OOP
Some references
The Maybe functor - Mark Seemann
https://blog.ploeh.dk/2018/03/26/the-maybe-functor/
Functional architecture: a definition - Mark Seemann
https://blog.ploeh.dk/2018/11/19/functional-architecture-a-definition/
https://thinkbeforecoding.com/post/2018/01/25/functional-core
Functional Core - Jérémie Chassaing
https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell
Functional Core, Imperative Shell – Gary Bernhardt
Thank you!

Hexagonal architecture vs Functional core / Imperative shell

  • 1.
    Hexagonal or FunctionalCore? Thomas PIERRAIN @tpierrain Bruno BOUCARD @brunoboucard
  • 2.
  • 3.
    Suggesting seats inTheaters “I want to find 3 seats for show Z”
  • 4.
    Suggesting seats inTheaters “I want to find 3 seats for show Z” SEATS SUGGESTIONS API
  • 5.
    Suggesting seats inTheaters AUDITORIUM SEATING API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API
  • 6.
    Suggesting seats inTheaters AUDITORIUM SEATING API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API
  • 7.
    Suggesting seats inTheaters AUDITORIUM SEATING API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API
  • 8.
    Suggesting seats inTheaters AUDITORIUM SEATING API SEATS AVAILABILITY API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API “I also need to know which seats are already reserved for show Z”
  • 9.
    Suggesting seats inTheaters AUDITORIUM SEATING API SEATS AVAILABILITY API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API “I also need to know which seats are already reserved for show Z”
  • 10.
    Suggesting seats inTheaters AUDITORIUM SEATING API SEATS AVAILABILITY API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API “I also need to know which seats are already reserved for show Z” OUR CORE DOMAIN
  • 11.
    Suggesting seats inTheaters AUDITORIUM SEATING API SEATS AVAILABILITY API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API “I also need to know which seats are already reserved for show Z”
  • 12.
    Suggesting seats inTheaters AUDITORIUM SEATING API SEATS AVAILABILITY API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API “I also need to know which seats are already reserved for show Z” “Ok. You can have seats A1, A2, A3 in pricing tier 1, C4, C5, C6 in pricing tier 2 …”
  • 13.
    Suggesting seats inTheaters AUDITORIUM SEATING API SEATS AVAILABILITY API “I want to find 3 seats for show Z” “I need the auditorium seating of show Z” SEATS SUGGESTIONS API “I also need to know which seats are already reserved for show Z” “Ok. You can have seats A1, A2, A3 in pricing tier 1, C4, C5, C6 in pricing tier 2 …”
  • 14.
  • 15.
  • 17.
  • 19.
  • 27.
  • 34.
    From Hexagonal toFunctional core (live coding)
  • 35.
  • 36.
  • 37.
  • 38.
    Makes decisions Imperative Shellacts upon those decisions Functional Core - Theater
  • 39.
    How to copewith multiple I/Os in sequence?
  • 41.
    Make decisions Acts uponthose decisions Functional Core – Train reservation
  • 42.
    Feature Hexagonal Architecture Functional Architecture Separate Infrafrom Business Yes Yes Business Code without side effect Business Decision are in Business part Offers good ability to test Technical concerns never leak from domain Hexagonal or Functional Core?
  • 43.
    Feature Hexagonal Architecture Functional Architecture Separate Infrafrom Business Yes Yes Business Code without side effect No* Yes Business Decision are in Business part Offers good ability to test Technical concerns never leak from domain * By its requirements Functional Architecture is more extreme (code without mutation) and therefore more addressable with functional language. The hexagonal architecture is more favorable to the OOP Hexagonal or Functional Core?
  • 44.
    Feature Hexagonal Architecture Functional Architecture Separate Infrafrom Business Yes Yes Business Code without side effect No* Yes Business Decision are in Business part Yes Yes Offers good ability to test Technical concerns never leak from domain Hexagonal or Functional Core? * By its requirements Functional Architecture is more extreme (code without mutation) and therefore more addressable with functional language. The hexagonal architecture is more favorable to the OOP
  • 45.
    Feature Hexagonal Architecture Functional Architecture Separate Infrafrom Business Yes Yes Business Code without side effect No* Yes Business Decision are in Business part Yes Yes Offers good ability to test Yes Yes Technical concerns never leak from domain Hexagonal or Functional Core? * By its requirements Functional Architecture is more extreme (code without mutation) and therefore more addressable with functional language. The hexagonal architecture is more favorable to the OOP
  • 46.
    Feature Hexagonal Architecture Functional Architecture Separate Infrafrom Business Yes Yes Business Code without side effect No* Yes Business Decision are in Business part Yes Yes Offers good ability to test Yes Yes Technical concerns never leak from domain No Yes Hexagonal or Functional Core? * By its requirements Functional Architecture is more extreme (code without mutation) and therefore more addressable with functional language. The hexagonal architecture is more favorable to the OOP
  • 47.
    Some references The Maybefunctor - Mark Seemann https://blog.ploeh.dk/2018/03/26/the-maybe-functor/ Functional architecture: a definition - Mark Seemann https://blog.ploeh.dk/2018/11/19/functional-architecture-a-definition/ https://thinkbeforecoding.com/post/2018/01/25/functional-core Functional Core - Jérémie Chassaing https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell Functional Core, Imperative Shell – Gary Bernhardt
  • 48.