[Live coding] Beyond the hexagonal architecture: Functional Core & ...

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good evening everyone and welcome at this another virtual ddd and with me today is christina from the organization and um hello and today in the meetup we'll be talking about beyond the hexagonal architecture functional core and more with bruno and thomas my friends from ddd france and bdd front right so happy you'll be here they'll give you a presentation for about with some live coding for about an hour and 15 minutes but please do type in the chats youtube or zoom if you have questions on zoom use the q a function and on youtube that pose your questions afterwards we'll do the live q a so welcome thank you thank you for the invitation and it's all up to you now okay okay let me try to push some uh slides here just for me to ask can you see the slides and still all together yes okay yeah okay cool uh hello everybody um [Music] beyond hexagonal architecture um the idea of this talk came out one night in paris more than three years ago it was at the dddfr meetup night and i had the chance to live code with alistar copeburn in order to explain what hexagonal architecture was and how to implement it at the end of the event while we were drinking beers jeremy chasan and clement budo were asking alistair whether or not he was aware of functional core impartial patterns the description was very interesting and i was saying to my inner self that could be another interesting talk three year after we are here with bruno to discuss and to compare both patterns but first thing first let's present ourselves my name is tomar i'm building software since more than 20 years now i'm spending my time coding and creating efficient and happy dev teams providing value with external programming and domain driven design and two doing some strategic dd consulting architecture and training to other customers besides that i'm an organizer of dvd french meetup since five years now dgf hello thank you my name is brenda buca hello everyone i'm very glad to be here thank you kenny to invite me with thomas on my side i have 30 yeah 30 years of it experience i've been iggy coach for 80 years and i'm also organizer of the bdd paris meetup however i showed that today in first a quick reminder of what hexagonal architecture is then the presentation of what the functional core is then we will start from the code base in hexagonal architecture and we will transform together into functional core imperative show we will finish by comparing this pattern with hexagonal architecture yeah actually below since i was also recently involved in discussions on twitter about what is and what isn't hexagonal architecture i'd really like to end up our session with a question for you all of them all of you the ddd audience and it might help us also to break guys for our final q a session with all of you bye okay for today yeah i i wait for your slide is it okay yeah it's okay now today the domain will be theater actually not the reservation not the booking but suggestion of the best possible seat for someone that would like to attend a show with a group of people called party parties a group of two four five per person yeah something that should ring a bell to kenny since we had uh created a ddd training all together using that topic so no new thing okay let's take an example uh it starts with a request coming from a customer that's saying to our website i want to happen to show z and we are three what's it can you suggest to us the suggestion api in yellow so what what do we need to do the job we have to ask all the backend information such as shows such as show z matching a specific auditorium setting auditor upsetting is a topology of seattle for and yeah and yes uh our api is making some api calls towards upstream systems and led by other teams other companies here we have the case with the auditorium sitting api so we are owner and developers of the yellow api citations and we need some external backend like auditory imaging api well when we receiving our request the auditorium seating api is returning the auditorium topology procedures show in other words a list of rows seat seats corridor pricing categories for every seat etc this external auditorium seating api is not aware of which seats are free and which is already reasonable all right so our api in yellow must ask another backend what are the available seats for this showcase so this one's its availability you're right and this second call to another backend the seat availability api which only return a list of seats name okay now we have both the auditorium layout and for every seat whether or not they are available meaning not reserved or reserved our appear in yellow can do its job job which is to find the best possible seats for this customer request all right so the question yeah the core domain of our subjection rpi is really to suggest it we don't want the reservation neither booking the booking part will be done afterwards by other systems by other api to provide the best seat we have rules business rules such as yes such as do not separate parties of people and find them adjacency please whenever possible try to locate them in the center of the row and also something like try to suggest them expensive seats first please because we have various pricing categories and if you can do some business with it well indeed right so we do our secret sauce to find and suggest the best possible seat for a show here frame in a yellow in a small diagram we return our values rejection and some of them are made for pricing tier one the most expensive generally in the first row some are made for pricing tier two less expensive seats at starts that are so you got it all right our website will then suggest those options to the customer and starting with the best and most expensive rows again yesterday that's all we need to know about the demand for today okay um but cool thanks for this explanation bruno but tonight we'll focus on the architectural style okay and we have to have a look and to compare two options first option hexagonal architecture this one will allow us to keep our domain code here in yellow properly split and isolate it from what we call the infrastructure code located at the borders like we have the adapters therefore future code is the one containing all the technical frameworks ios data stores databases etc so we have one inside hexagon in yellow or domain code two outside the hexagon at the borders all the infrastructure code needed to make it work with all the adapters all right and to go in and to go out we are using ports which are interfaces and parts of the domain and adapters that belongs to the infrastructure side and at runtime that will allow us to enter and to exit this uh this hexagon this will be possible thanks to the dependency inversion principle uh what gerald zaros wisely called one day configurable dependencies like like plugins okay so yeah yeah before the dive in the second option we need to focus one sec on the specific thing about functional programming we won't explain what functional programming is we are not exactly a specialist but we will focus on what pure function is a peer function is a function that will always return the same output every time you pass the same input this is possible if you don't have any side effect made by your function no change of the global set nothing a procedure that looks like a function will return an output like a function but it will not always return the same value with the same input because it modify share variable or global state yeah so the procedure that looks like the function but which isn't on the right is therefore non-deterministic and it's what we call impure functions non-pure functions okay so this being said we know the second option after exagger is functional core and imperative shell pattern okay in that option we consider we will consider two things first one pure function locate in what we call the functional core in yellow here number two non-pure function io side effect that will be located in that we call an imperative shell interactive shell is where we will chain all our function called as a pure or non pure function to support our use case an operative shell is like a function script orchestrating pure and non-per function call the yellow part the function functional core will never do side effects never call an external api never call a database pure function of functional core are fed from outside meaning from the shell thus the partition may first fetch data to external backend database etc okay let's see the difference now on between those two options but while we are in action okay first what happens with the hexagonal architecture here is our hexagon in yellow what you can see outside the gun but within the infrastructure code boundaries are is the left side adapter the seed suggestion controller in light right left side adapters are kind of front doors for our external users to ask questions to our component to our api to send queries command requests etc here our main fondo will be an asp.net web controller because our example will be in c-sharp for the upcoming minutes so our front react website whatever the front-end part will send us a http get request something like on a situation resource to query a string suggestion for show zid and party of three person for instance on a question this request is under that our web controller level which is also our left side adapter in purple and this web controller adapter will do something every left side adapters do meaning first adapt from the afra data model here in json or http question two domain types and data structure domain data structure two to call the domain code the hexagon using a left-side port method here the left-side part is i request you questions and the method will be make suggestions on that on that interface okay and third adapt back the answer coming from the domain here it will be a suggestions made plural data type to do something that will fit the corresponding infrastructure layer in other words an http response with http code a content and center star this is the overall process but let's come into the uh new step now the web controller is called the max suggestion method of the hexagon uh and the name of the hexagon the domain name of the hexagon is a seat allocator actually uh in order to suggest the base seats our seat allocator has to work with an auditorium sitting in other words the theater topology for this show but also the list of seats that are already reserved for it so before being able to work and to do anything within our hexagon the seat allocator from the domain will first ask some information to the outside world here two external apis on the right auditorium seating api and seats availability api the one that bono talked earlier then the hexagon can do its jobs which is to find and suggest the best possible combination of seats for this show and this number of people and finally returning the result which is something like okay you can have those three things in pressing tier one those three seats in pricing tf2 and and the star let's sum up a request is coming from the website on the left handed by a web controller which will act like us with left side adapter this left celebrator is calling the dragon through high request foundation ports belonging to our domain and implemented the seat allocator type site allocator type from our domain will need first to get an up-to-date auditorium setting and it will ask through a right-side port name i provide up-to-date auditory seating this is the name of the of the port and implemented by your right side port in dark purple okay this one will fetch a little layout in one hand and the list of all the other seats in the in second time and we'll melt them uh for every seat we will have the information whether or not the city is already observed then our business logic can work and do the job finding the best seats and our left side adapter will get the answer from the domain from the c telegrapher and we'll wrap it into http response and forward it into our client so it will adapt before returning importance in our case we have decided to have only one right side adapter acting like a kind of anti-corruption layer we picked that option because we do not want our domain code making the suggestion to be impacted by organizational changes from the outside the fact that we need first to get an auditorium layout and then to combine it with a list of already resources got elsewhere it's an implementation details from our seat situation perspective it's an organizational details that has nothing to do with the very specific domain of finding the best seats from an auditorium setting worst it's an implementation detail imposed by external organizations and partners hence the need for an acl here are suggested by by dd for instance and in our case we implement this acl at the auditorium seating adapter level at the right side adapter level but that's just one option another option may be to create and put this code into a dedicated api outside these components outside this api let's say for if there are many people needing this merging capability this adaptation service yes okay let's do a dedicated component but in our case since we are the only one interested in that adaptation in that merging hence we have decided to put it into our icl into the right side adapters um so domain driven design helped us somewhere to somehow to protect our domain code from other ubuntu context other external domain models and breaking changes this trade-off is important because this is not an orthodox implementation of alister hexagonal architecture which focus more on the technological technological story aspect of things and not on the various domains and various contexts like we do in ddd in an orthodox version of alistar's view one should have used two right side adapters instead but this is where i disagree and we will see that afterwards at the end of our of our session okay uh sorry to for this time but no but it's important for the end zone i understand i understand we discussed a lot before can you now illustrate the dynamic involving with functional core and imperative synthesis yes i do so um let's imagine uh the very same request coming from our website and http get query asking for suggestions as your previous example it's a web controller level it's at a web control level that the http request will be unleaded this one will act as the imperative shell for our situation use case but contrary to your hexagonal architecture situation our interactive shell will first fetch all that i need by next suggestion per function in our functional core so you get you get all the data first and then you call the car absolutely also your alternative shell has everything to call the next suggestion per function it will call it as a parameter three person for instance and up to date auditorium sitting corresponding to the show z like earth okay next location pure function of functional core will do the job and return suggestions made to the imperative shell and then the web controller will adapt this result to an http response and send it to the client okay to sum up number one the http request is received by our web controller the two the corresponding quick question of the web controller will be our imperative shell it will first do some side effect by calling non-perfunction asking for instance up to that auditorium setting trade the imperative shell will then call a pure function belonging to our functional core the mac suggestion function this pure function won't do any side effect only per functional domain logic in order to make situation and finally the imperative shell will return the result as an http response that will be sent back to the original caller the website everything that happened in the functional course stays in the functional car sometimes absolutely okay uh okay we we talked a lot so far so let's show some code with you and there we will migrate hexagonal architecture api into a pure functional core and positive shell style let me just uh stop sharing this like this sharing another screen oops any windows okay screen one screen to you okay can you see my code my visual studio code yeah i see okay uh is it readable the size of the font and anything like that yeah yeah that's really cool okay um okay we have what do we have we have a solution visual solution here because we will code in c sharp for the seed suggestions api all right this solution has many projects the first project is the seed suggestion dot api this is a classical hp.net api like spring boot stream in java or something like that just for for the api http calls and and web controllers and anything like that then we have the certification domain which contains all the domain logic the seats the row the seat allocator the system availability show id it's not all our value types or aggregates or and we also have in that within the domain logically the port the left side part i request suggestions which is only one method which is please make suggestions providing a show id and a party requested and returning a promise of suggestion made and the right side adapter the one in front of the acl i would say as a get auditorium sitting just a show id and i will get an auditorium setting which contains everything that i will need to to work so this is the right sideboard then what do we have we have the infrastructure code here uh with some adapters uh so here we only have the right side adapters because as previously said the left side adapters are the web controller that i already have in the in the in the api project and last but not least we have the tests uh some acceptance tests integration tests unit tests and anything like that and um this is a maybe before uh i can just hit the debug button for us to to to launch the the solution the solution will pop up three swaggers because we have also the external apis fake on local so we will launch our api the sit suggestions but also the two other external back-ends so it takes some times but it should be there in a second situation api see preservation api which provides a list of all the other seats so sit suggestion i can use it maybe show seven a list of six and here the answer i don't know if you can you can see it but expecting the show with id seven and party requested of six people uh i have can do i have no suggestion to made on for the first tier pricing category but i have two suggestions made for the second passing category and two seconds for the third pricing category the cheaper and and mix is another thing we won't describe but i have three suggestions of six seats uh every time okay so this is how it works i will do this and we will um have a look at the code um we can start by the test uh maybe okay one comment can you zoom in a bit more people on youtube is it is it better a hard time consuming it's okay but i think on uh like this yeah i think that would be better okay we'll see the feedback in the chat later thanks uh you're welcome um so uh we are writing acceptance test a lot much more than unit tests this is another topic but this is an example of what we call outside in pyramid uh tdd style so basically we uh situations controller should basically we are testing the whole hexagon meaning the hexagon with all the adapter code all but the io we we won't uh do some kind of networks and anything like that so in order for our tests in order to be to be really fast so in that case we just pick a show id uh and here you can see the the description of uh one auditorium layout the third auditorium a tiny little because we have only two rows first rows in front of the stage and second one as you can see with parenthesis it's already reserved seats okay so this test is saying suggestion controller should suggest one seat one auditorium contains one available seat only and the only availability can you remind us the number in parenthesis is a category yes if you can if you see one or two it's a pricing category one or passing category two uh that's it for the for the for the representation okay so um expecting having that auditorium laid out i'm building my left side adapter because as you can remember when you build the hexagon an architecture your main entry point will be a left side adapter here the web controller and and the web controller the less adapter will interact with your hexagon etc so we have a builder here hexagonal builder with auditorium defined for show this one the one and and some json files and please build a hexagon with adapters but without ios and the builder will return a left side adapter or controller which has a method get suggestions for and here we are we get suggestions made we extract the value uh from the http response and then we check on the uh i'm assuming that i have one property for five passing category first plastic category and only one suggestion which is a3 that's it here okay we have many tests for that with empty uh anti auditorium cities other one uh we have lots of tests about like this but as they are with the power of seminars they are pretty much looks like the same okay only domain and and variables stuff so if you are looking at the web controller so uh maybe maybe situation controller here which is our left side editor as you can remember as every left side of the player you have uh one method here for the http gate method so let's say you you call it like this and the correct stream is is extracted from asp.net framework we are very in the adapters including the code that i didn't code but that i'm using like asp.net first step for every adapter is to translate from the left side is to translate from the infrastructure code to the domain so here we have strings and hints and we get some kind of value types of show ids and party requested so it's the first adaptation then we can call the domain here our hexagon hexagon the name is for the sake of clarity and for our talk and we we used to to use more domain-driven uh names for hexagon but uh we called the max suggestions methods and we get a suggestion that we wrap into a http uh response asp.net sctp okay 200 so that's it for the menu's edge and if we look at the code of the hexagonal architecture so this is the left side part i request suggestions on the left asking questions and if we look at the implementation here we have the c telecato what we call the hexagon and pretty much it actually it delegates a lot of the business logic to other types like auditorium seating and roles that's it so we you may have the impression that there is no not a lot of code but everything is behind the scene behind those functions and anything like that so that's it for the for the overall uh architecture one question before we move on the code will be available in github someone on youtube yeah after the talk absolutely well tomorrow or tomorrow if we make some uh i don't know execution is too too long if you have to spend check or whatever i don't know but yeah yeah tomorrow tomorrow it will be uh yeah thanks you're welcome so the idea here is uh how to translate a hexagonal architecture into a functional core uh as we said earlier we don't want to have ios right you don't uh and here we can see that yeah and it's easy to see yeah i i can't really uh hear you below but uh sorry do you wanna help me yeah it's okay okay okay i just said that uh because uh in shop we have an await when a function is calling io there is only one discord and so here here um we will see that after if you want but you can trust me everything is pure here everything is full of value objects and closure of operations and things like that without a state mutation and anything and stuff like that but here we have a an io first thing first the hexagon take the the data on the right so what we need is to get all the i o and to push it uh to the color so instead of doing that call here we will push it into the color so easy i will introduce a parameter from that line auditorium sitting and here instead of doing the call i will just ask the color of this function to to to call the io before and to call me with the the end result which is the auditorium setting for the time setting is really part of our domain okay i changed that maybe i i will change the signature uh i will change the signature here because i i get rid of the i o i think oh wait i will i will return a pure domain object here i don't need to return a promise of suggestions i will just return a suggestion as soon as i have everything to work with i i don't need to be a sync in that case um okay i can remove the async here and uh it's okay uh here's the hexagon we will we will break the exam so let's get rid of it and the left spot is not needed anymore and what can i do i can also translate transform into a mac static to make this function a real static plan and i can make the class static plus sita locator and say okay you have a private field auditor instinct provider i don't need it anymore i will get rid of it just right now and i have one error here which is the the constructor the constructor was used by the hexagonal builder for our test we will check that and fix that in a second so here uh i've got everything private static it's not the hexagon is the actual core just for the sake of clarity okay now i just push the responsibility of fetching the data outside of myself as a functional core now i need to fix maybe what i've just broken in other words from the color perspective and what is the color of the hexagon [Music] french the controller yes it's a web controller so let's go to the web controller sorry for the accent uh situation controller here which is the one calling the hexagon that used to call it as you can see since i break every rules i i i transform this into a function i will get rid of the await method i don't need it hexagon is not does not exist anymore so i will call it the seat seed suggestion sit locator now uh it's my functional core and here i can remove the hexagon there is no more hexagon in that in that code and maybe this is the call to the right side adapter i will introduce a variable here to push it outside just for the sake of clarity here and let's say a non-pure function code okay call the domain it will be a pure function and i need to introduce a field for that because as a web controller i need to fetch the world on the right side of me so i need to to have a kind of a auditorium so i provide the auditorium sitting right side port so here and what can i do i can get rid of the hexagon there is no hexagon anymore okay that's the parameter sorry even the parameter you can get rid of the parameters yes i will introduce yeah okay the constructor parameter yes if a web controller or left side needed to talk to there is a to to make the job done now you don't need anymore because i can write it here we are in the imperative shell land this callback this asp.net callback act like the imperative chain for this use case so it will do some annotation called non-pure function calls appear functions and and wrap okay so i don't need hexagon anymore so i will change the constructor because now i'm expecting to have an auditorium stick provider injected that i will store into a private filter and mcfield read only yeah i i don't understand why i literally think i don't know maybe there is a bug with a chapter [Music] now why is it real it's a audit of sitting does not exist in the current context i don't know it's it's it's a field that i just let me test [Music] fix a pixel code because it doesn't compile yet yes but i wanted to just to fix that rename too i don't know see there is a link but it says okay exists in the current context okay let's see that maybe just after uh yeah i'm not supposed to have this but auditorium sitting okay let's let's continue and we'll see that just after so i have other build device can you declare a seat allocator here it's uh since i break i destroy the hexagon uh every uh reference to this dragon will will hurt so i get rid of that and i'm currently in the hexagon builder so it's where i will build these are going with adapters but without io now the left side adapter the web controller does not need the hexagon anymore but you will need the right side adapter okay so let's put that here like this okay i have other errors yes a return left side adapter [Music] yes it should it should be okay okay let me check uh build uh it's strange okay i need to uh to change to change the type yeah it's really strange yeah uh yesterday and it wasn't like this so it's uh it's demo uh i don't understand why okay this one is correct it's uh here yeah i said we destroyed the hexagon the uh um the uh configuration the startup of your of your of the api does not need to register me to register on hexagon anymore into the ioc.net controller let me build again okay so it's building so far okay it's okay i don't know why uh we just studio it's really buggy 6r where the the code is is building let me try to go to the test a determining should uh no not should uh suggestion should here if i change something let's say 12 here it should be red just check that my okay it's okay it's red the test is failing so i'll get back so okay i don't know why a sharper is a hurting like this with uh but the code is working maybe i can run it uh just to check on in real time in iteration mode hand integration tests and made innovation tests but what you can see before that it's okay our web controller is not using a hexagonal anymore it's just uh is now an imperative shell for our use case doing a pure non-pure function called pure function calls uh and uh and and that's it no more like they're gonna last lecture and if i have a look at that it should be working just because i'm stubborn uh six seats maybe yeah it's working okay so uh that's it for the uh transformation uh let me maybe i will push that for you you know yeah yeah yeah because i think we can make more functional maybe more functional yeah yeah so below okay tell me [Music] i should have created a branch maybe oh yeah let's let's see data let's see that after i push okay i push and it's on the main uh i didn't it's on the menu you don't you just just pull the main and we will fix that for the for the for the code for the audience for tomorrow okay i was kind of um yeah this all these red squizzles and okay okay so um [Music] i can stop sharing so maybe um i share the screen so you were talking about doing more functional style what do you do mark i have to share my screen first wait a minute i leave you alone yeah thank you so just what we just did was to transform a diagonal into a functional code can you see my screen in our case it was not not yet in our case it was kind of easy because we had only one io or one only one io we didn't have a kind of chain of fires a chain of uh of steps so you maybe you want to to talk about uh come on you've seen it you see there you are okay okay okay i can tell yeah you see maximum it's a good good sign because i i would like to talk about it uh just before i modify the code so um maximum produce a blog post about a maybe functor to bring a functional test in object oriented world why do that in language like c-sharp java the reference reference type can be null and leading a lot of is called but the reality is worst because developer forget to check a new value with the road time exception as a result maybe class allowed to contain a value or not you can see no value with value they make glass allow to project something and offers the capability to get back uh the value after processing something if the process is failing we can provide a full back value to get a result a result a valid result give me by my default one okay that's it and uh the the the maybe the class is as a capability to be compared uh also okay so uh this is the way we can improve oop the development with this kind of cloud because this class is written in seashore but we can participate in java javascript so it's not a problem of language so i i would like to show you uh the blog post the original blog post um you want uh okay maybe it's like an option it's the same it's the same thing with different i can't i can't hear you really well i'm not sure if i'm not the only one no same here so yeah his connection is uh breaking up yeah i know i see i'm sorry uh but by that but it's difficult to monetize that for me okay so let's just take over the slides okay okay i okay it's not improving quickly yeah absolutely unfortunately yeah well that's uh that's how it is now right luckily you're luckily your load balanced absolutely let me resume my slideshow i stopped the sharing yeah yeah so i will try to find where we were and maybe you will be able to to comment slideshow from the current slide sorry i had to to find the good slide uh live continue okay now okay i can share the screen on my own and sorry okay it took oh yeah that's that's how it goes it's live yeah yeah we can cut it out also later in the end so uh you should be able to see the the more functional screen here yeah absolutely i already showed before this one okay so let me so we you are supposed to like maybe uh option uh and at the end to um to show so absolutely absolutely so um this one is um is beef yeah it is a function is a calling um the modification of negation you you can see uh we rename uh it with try next suggestion because it's returning uh maybe and because in this case it's very simple there is no other function to call to process correctly so we immediately get value fall back you notice we pass the fallback from the imperative shell so the try make suggestion don't provide um the suggestion not available it provides an empty maybe so imperative shall act on this decision and make the decision to put the value itself into the suggestions local variable okay okay uh how to cope with multiple uh in some other cases you have to have kind of pipelines yeah yeah yeah so uh scott washing of functional programming model we call rope because he defined two track a green track where every function is going forward correctly validate update db sound mix on email and the error track where we chain all error function so this this model is is really um aligned with the functional programming so happy passing green and everything something is messed up you you stop working and you go to the track it reminds me [Music] so maybe four years ago i don't remember we spoke a lot about uh this um this live coding about trend reservation ticket uh the goal was to optimize uh the reservation in a trend regarding coaches so um but we were talking about reservation this time like a booking booking was involved what's not only suggesting seats but also to book and to make some some reservations but the rule was about um reserving seed so um as the theater uh seed reservation were a work core domain and we depending from other services trend data to obtain trend topology booking reference to obtain the the number of the ticket and trend booking to book effectively uh the reservation pure conway's law classic thing yeah and in that case so you have more things to chain so this is the code of the reserve seats method yeah yeah exactly the same thing the code of trancha is also the value oriented no modification no side effect so we have at the beginning of the imperative shell to call the first one to call the topology of the trend we ask trail id and to obtain a new booking reference next we call the pure function to make decision but in this case we we need to book and to book we need an employer function box it will not just be for that so the ticket office service dot tri reserve it's our functional core and the travel reserve method returns an option returns a maybe yeah and since it's a maybe you can chain with the select uh and and exactly uh there is a little trick because uh our booking uh books it is an io function so we we have an await and i think it's meaning the result is wrapper in a task type and we don't want to propagate this task to our function so we need to unwrap it with another select this resolution select two projections before to get value a new uh reference failure the first select returns a premise a task of a result and and the reason why we need to unwrap it to get the value of the result absolutely then we can uh call the get value of or fall back and the fallback is uh there is a reservation failure for this trinity and we notice this example so we we we can observe the power of the maybe um tool because it it becomes easier to chain function so it's a way to obtain a new kind of functional style okay maybe we can sum up the difference between the hexagonal and the functional core you've made a you've made a slide about that yeah um we try to it's not very easy because it's not exactly the same spirit but we try to to make the exercise separate infrared from business yes and functional uh with scott because um architecture we mix in pure and in pure function actually so the separation is different so you know i put the yes in yellow and quote unquote because for me there is kind of a different question i would say for uh what interests me in hexagonal architecture is to protect my domain logic from the technical code so i used to have one project one module with pure domain only ports and and and value objects and domains and things like that and the the technological and the api calls towards the external citar is outside is another modular product in the functional style in here in c-sharp the imperative shell the the dichotomy is not domain of heart it's much more pure functions non-pure functions so the imperative shell is dealing with pure and on pure functions and the functional code is dealing only with pure functions so the split is not domain and infrastructure it's much more on the pure functionality function and in lots of cases my domain will be implemented both by pure functions and non-pure functions i'm thinking about all the orchestrating orchestrations uh domain logic you know so reason why uh yes i said yes okay but it depends um it's a way to think functional and it's because uh it's the granularity is different and yeah it's pure and pure versus domain and yeah from my point of view but that that is debatable and we'll see that maybe in just a few few minutes uh second line is business code without side effects example architecture it depends of adapter so an adapter contain io so no you're right and the fact that we kind of think await stuff within our domain is a sign of side effects absolutely second one business business part um yes yeah for the same reason difficult to to debate about that because we i we think it's too too too way to think about design different yeah offer a good ability to test yes in both cases maybe we can have uh power empowered more the functional architecture side because the code is more reasonable about we can reason more easily about the code since you don't have side effects on the pure uh function side uh it's easier maybe to test but anyway and technical concern never leaks from domain yeah for functional uh architecture there are no links i think a way to instance yeah okay no okay okay but by the way um does it make really sense to to compare them no i i think uh it's too op and functional programming is different so yes does it make sense to compare two options related to two different and completely different pyramid power diagrams i don't think so and i think neither do you know but one can observe and learn uh the adoption of one or another will stand with your context as always uh your team is using sql as a language different language but of course you will use the functional style architecture with io outside of your pure functions your team is full of juniors coding in java or c-sharp maybe more complicated to have your functions and yeah you will have to rely on value types a closure of operation and stream like that it's doable we've made it here and there on on projects but it's more complex so there is no silver bullet and as always uh yes it depends on the context and the technical social technical context you you are working with and that's good actually that's that's okay maybe uh uh last but not least yes the the title of the talk is beyond hexagonal architecture okay so yes we can use functional core in some occasions in some cases to replace hexagonal architecture with it okay but we can also talking about hexagonal architecture in itself and we have a question for you we have a question for you in the audience this style the question is does the following diagram illustrate hexagonal architecture so there's two answers maybe i'm cersei also but first answer is yes an adapter can be an acl an antique option layer i may do not want my domain to be polluted by upstream organizational changes and and models and external wounded context models so yes an adapter maybe an sel towards and against more than one external context or you can answer no i want to stick to a list of original motivation meaning the technological motivation a meaning that's uh basically one part a slash adapter per technology so uh i don't know kenny or christina if you have a kind of uh quiz or i've um i've launched a fall for the zoom people and for the chat in youtube uh just answer it please in the chat sorry or b i'll type it also in the chat there so people can see it so we will let you answer it will be interesting for the for the for the so there's already some polls in okay okay 95 percent of yes five percent of low cool i'm happy to be [Music] a little bit less 93 percent 70 percent of voting it's we'll let you uh let's 10 seconds before we uh five seconds that's one minute five seconds yep okay so the answer can you is it so the answer is 32 out of 35 say yes so 90 percent of yes that's it okay yeah 91 cool um so uh following some discussion on twitter uh my personal answer is yes and i wrote it in that blog post hexagonal or not and following some discussion if i probe youtube chat i see mostly yes popping up there as well so i see the same pattern in youtube so okay now we have a fair research right we have two control groups [Music] and zoo good thank you thank you kenny so yes we had recent discussions on twitter about that a couple of months ago and i wrote this article saying basically yes because for me executive architecture has become has become an umbrella term nowhere else especially in the domain-driven community the the fizziness of alistair original article has something in common with eric evans blue book it's so conductive to various interpretations that it edges really well and for me it's a multi-faceted pattern one may have the same need as a resistor and pick it from technological plug-in capabilities yes one may pick it for testing like steve freeman and price in their tremendous gru's book okay another one may like me pick it because it allows you to protect your domain code from the infrastructure one what i call the tactical dd facet another one may also like me pick it because it allows us not to have too many layers only two of her domain what i call the simplicity facet another one may pick to have quick feedback focusing on the domain first and seeing late decision about architecture data store or anything like that when you know better the the the domain or another one like like me or julian thompson pick it because it allows us to put some strategic ddd and multi-correction layers in in right-side adapters what i call the strategic ddd facet but whatever this pattern may be chosen for so many reasons providing so many trade-offs and options but i really think one should continue to use it beyond beyond the pure and original technological facets explained by alistar and and maybe you can have one thing sorry okay uh as rebecca with brook said uh during those discussions with alistair vonn juan garrido and matt wine patterns will transcend their initial writer's perceptions as people feed them into their own design context so basically means that if the community and the thing that we can view it like umbrella term or multifaceted pattern why not but this has to be discussed and if finally we vote no or we do not agree uh that means that ddd community will probably have to find new names or new name or new names for all these usages and i'm not worried because this is something that the ddd community is kind of expert in i mean searching the best possible names for things is something that is a kind of reflex for for most of us so that's um that's it uh maybe thank thank you for your help for your passions i don't know how many times we spend uh and maybe it's time for questions if uh we have a lot cool it is really hard to define to decide which one maybe i start with the question from lawrence how does the functional core pattern cope with conditional imperative dependencies for example maybe you need a second train if the first is full you what i understood is that you will change them into your operative shell yeah it will be a pure non-pure function pure function function function etcetera you will change all those and and based on the maybe on factor and something like that you will be able to to change then and to so i'm really not a fp uh specialist and a fp guy i like it but uh so i know there's a lot of debates um the idea for us was just to uh widen our origin uh because most of us are still working on on code base or with uh like stuff like uh op or worst procedural codes and like that so the idea for us was to just to see something else and to make an introduction of that okay then the second one is it legal to interconnect multiple hexagons through ports okay like for a modular monolith something like that uh so yes there is a way to chain hexagons and to replace some adapters instead of doing some io through the network or thing like that an adapter maybe just something that calls another method in another package uh through another left sideboard so you can you can connect plug and change they're going like this and typically this is what you do when you i'm currently speaking a big monolith in in the hospitality world where i'm working with my team and we are preparing to split this huge monolith into various exigents so yes that's right it is legal i like the legal part [Laughter] then one from the meet up would you say if you work with functional programming then utilize functional core whereas if you work with orp then utilize hexagonal yeah yeah we say that because as we try to compare the both uh the comparison is not correct because um functionality programming um as a spirit of function we as thomas said as a granularity in functional programming function and sometimes we have a pure function sometimes we have inter function so the pattern functional core imperative shell is aligned with functional programming do it in in op it can be to learn the pattern but you need you need before uh have all your op code without any side effect for your function it's quite difficult so the step may be high because indeed you have to work with value objects with closure of operations no mutations local variables etc so and since i am i i've made it only once in production with my current team we were thinking about uh one component that was um ready for that because it was not a kind of orchestrator or something like that we it was just something that doing some logics upon some inputs so in that case i i suggest them do you want to have fun and to call it in the functional core style because despite the fact that we were in charge and it and it worked but it was really for that use case pure simple and and i'm not really fan of the uh i really like to split my domain code from from from the technical code and the imperative shell has some domain logic or may have some domain logic so i'm not really a fan of that so in except in that case uh not just for qatar and stuff like that okay the next one we have to i think somehow similar from youtube have you tried with i o monarchs to have less logic inside the controller personally no but and here is one from uh peter tillman's uh somehow similar why not delegate part of the imperative sharing separate name space or module from the controller to still have the clear separation between infrastructure and domain yes it's possible it was the case for the trained uh example the imperative shell was a separate place classes but to be aligned with um hexagonal architecture where we made this decision to use the controller as a left adapter we we use this controller as imperative but to create a specific class for that i would love to have more details about that in order to chat maybe on twitter or maybe on your phone yes i would like to why not i didn't get it maybe i didn't get it right uh so why not but you should probably look at the camera because we can't see your face when you're talking okay okay okay now one about the design is in this example a distributed monolith one service calling to other services synchronously maybe they weren't ingredients this was the first question at the beginning it was about the seat api and okay okay uh if the function is pure there's no i o inside it's not necessary to use a cyclonic because this does take time except it's inside we make a very long loop etc but i i don't understand why i need to to have a synchrony in the inner function it's not necessary i think the idea was to chain value six dagon and messages among them and things like that maybe same uh i'm not sure i fully grasped the the question or the of the context or i would love to to discuss it i i think it was at the beginning as you showed the diagram then we had the core domain in the middle with yellow and two coils uh to the apis which were merged and then it has to be synchronous because you have to merge them somehow yeah yeah yeah yeah okay in that non-pure side yeah absolutely okay from uh valentin again how do you handle resource fetching that happen on the under some circumstances in the domain like if some condition happens uh fetch resources that that that was my uh main questions when i was starting playing with that that was really my main question and the what i discussed it about that with with some people very fp oriented dev and as i understood it was a you have your imperative channel orchestrating everything and and with a maybe an other frontier you go in functional car you you you you take the decision to continue or to go through another function pure function so it will be scripted in the imperative shell everything the the logic of the sync orchestration um can i i'm i am coming from.net and working in node.js for years and uh scholar in between i would say this this belongs to who decides this if i decide to fetch something then it's the wrong thing i shouldn't decide i should always fetch and decide what to do with the result but i would i have to give all the options to this resource and they can decide which if they give me something back or not depends which is the condition the condition is not to fetch i should always fetch but i should give all decision makers or options to the service to decide if i decide if it if it is dependency or optional dependency then it should be a maybe or an option and not not a condition yeah okay um where we go are there enterprise-sized case studies on this pattern i don't know which one i assume the functional core uh or it has been or has it been only been done in small proof of concept no no no there are lots of projects when you are doing stuff in scale for instance this is how you do the the stuff uh function actually uh functional corrective shell uh i think it's gary bernard that that right first but it's a functional architecture basically yeah very older and there are lots of people i know that michaelsen for instance in the infj is is doing that since years uh some friends doing haskell stuff in production also so no it's a it's surreal but even even then in ngs uh because yes it's coming more functional and it's possible to do that in gsa but i'm not aware of something like that but yeah it's not just a fancy topic for for me to play no no no it's uh it's really used by the functional community what is less real is the way we do yeah in c-sharp for instance but the idea for us was uh maybe to to give some ideas of maybe we can go outside and do other languages and have a look and compare what's what we can our mindset and you think it's a good idea scala is working scala is ideal for this because you have everything what you need yeah maybe it's too much maybe it's too much yeah it allows you to do everything what you want so i think we handle the second the next question too which development environment uh programming language frameworks support functional core imperative shall well oh a lot because uh i as as we're speaking about javascript because javascript is the new javascript it's really functional so it's possible to do in javascript and i've seen on on internet in implementation of maybe in javascript yeah but the question was much more on the functional side i assume it was from italy you don't need framework you don't need a framework to do to do functional uh no in in our c-sharp land we need something easier for us to to code with the value type something like that but that's it but it's straightforward yeah you have the same thing in um i would say op language java ruby but i would say if you see someone sending a framework for doing uh which like you can you can rush and you can run away maybe so then uh we have two cqrs questions um and i wouldn't wanted to answer answer myself so how does this relate to a sequel s event sourcing architecture sorry how does this relate to a sequel's event sourcing architecture it's october i would say yeah it doesn't we have another one how to handle functional core and imperative share with command mutations in cqrs context [Music] i don't see any links between mutation when we send mutation we said we communicate with another service we store in database for instance and secure arrests because um we store the state of um application every event so i'm not sure to understand the question actually i think uh one one good answer would be uh maybe it will be a um better next thursday not this one but the 11th we will ask jeremy chasson that will talk about one new discovery he has made recently made about the endo from tour and things like that especially applied in in even sourcing so i think that it may answer to that questions and it will probably uh a really interesting thing it's some ddfa uh i will we will send the invitation tomorrow i will open the event tomorrow uh but uh so it may answer to that question so jeremy is working since more than 10 years about functional event sourcing uh thinking a lot about it asking itself a lot of questions yeah i think it may be a jaw-breaking uh last presentation and and uh so it's it's brand new it's just breaking news since it should be thomas it should be in english or in french it would be in english it would be english so everyone is welcome for that if if you are pleased with the functional and even something you will have the answers okay um before can you end up with us here the functional core can be viewed as a simple way to inject dependencies as pure values rather than impure objects oh you actually you you you give the pure values to your to your functions yeah actually yeah no side effects everything should be ready to to work uh immutable this is the next step to functional objects that function programming you don't give values but you give functions absolutely yeah and then we have another one maybe is in thread with it how to how do you avoid the duplication of the fetch done in the controller and you have several api controller with functional core um [Music] i think the the the capability of the functor as maybe for op to uh offer the projection uh is a way to avoid duplication of the page uh because uh when we do five for instance it's a trend example we we we look for um sita in the coaches but we need to book after if we book if it succeeded but booking is part of um the domain we need to book but the booking is imperative so in this case we shame and we we need to um obtain uh obtain a mix between pure and pure but we can imagine unless we we don't have an example but we need to um at the middle of the of the chain call another rti for example i don't know um information to complete the the chain so i think the the capabilities to um obtain or stream the value in the middle of the change possible uh it's a prime of the design of of your are you you sharing your function it's not necessary to to call all uh your information before to call the person it's maybe it's a deformation or i don't know how to say it but we we wanted to just for people that are not aware of fp and things like that we just wanna to have a simple example of of it so we thought it was uh more clear to to explain that we need data before uh being able to execute pure functions so we take that very naive but now we in life we will call functions that will call functional functions and it will be a more less like i would say uh eros uh how best strategies for exception handling validation and user management and how to handle infrastructure errors exceptions oh i think you you avoid the exceptions you try to avoid exception as much as possible and you and you are using the rope the railway or your the programming uh to to chain uh your babies your your frontal and things like that this is how you you will react and this is what uh jeremy was saying to alistair it was uh the the idea of jeremy at the time was to say no i i don't really like to have exceptions within my domain code and i want the errors and see like that to be domain events or domain first-class citizens instead of being technical uh exception and so um yeah exactly you handle them you don't have a story section any anymore anywhere but you have a handling error case which is in which would be an an error event or a handheld answer and that's a true exception yeah yeah but the goal is to exception but transform it in domain error to be able to handle all these cases and not be have a accidental situation yeah absolutely this is yep okay um oh wait this is a longer question i don't know if you have time from patrick in my opinion many patterns in orp and ddd especially tactical are workarounds which are not needed when using function call functional core with fb patterns opinions yes yes absolutely [Music] within one world one paradigm you will use the tools properly adjusted and adapted for the time i'm not interested in long-range or war actually it's been so many years for me the real pain is between people the lack of communication between uh developers and and business people uh is uh hurting much more i guess about no i guess i'm experienced that's all my career much more than i'm using that language or that language for me language are kind of just the tools they are tools and what i need what i'm interested in to to find value and to help people so i don't care actually languages and it's fun among us during conferences and around coffee and to to compare stuff but for me it's not the not what i'm interested in actually okay would you one one question from the beginning of the uh of your coding or the presentation what happens when the auditorium seating api is down i think we solve this we have an error handling handle no seeds to sell today yeah and and you just answer sorry you know for you please come back later we are we are close now um could you share the tool you are using to document your tests with the images yeah it's uh image comments yeah on visual studio image comments it's a free plugin image comments with a with a nice comments yeah yeah atoma i push a code with um maybe function so if you want you can make public the repo maybe we will switch and put some tags for before and after something like that will it will be clear okay we will make it just after and then we will release the code okay easier for people to see the before and the after and uh and the last one can we say that the imperative shell has the same level as the application layer of the onion architecture the imperative shell has the same level as the application layer of the onion architecture okay um i i don't really like [Music] okay i i was speaking about graduality uh the granularity of onion of hexagon for me is the same event different about design but yeah the the granularity should be uh equivalent for a shell for me so my answer is uh i don't really understand why i do need to have a application layer for me and this is one reason why i like the dragon architecture and maybe it's a specific style of using it i like to have only two domains not two dimensions two two two zones the one for the offline and the other for the domain because for me unless you are using a shared kernel among various projects whole my domain is here to sustain and to support use cases i don't want to code any domain logic that won't be involved in the one use cases for my phone for my application that means that i i don't understand the need of finding some kind of core you know core domain uh no not the car domain and the ddd sensor i mean a core layer a cord domain layer application layer because for me application and and the method is part of the domain the use case is part of the domain should be used part of the domain and every time i've seen some layers separation like this i'm asking why did you split those two layers and i almost never have um an interesting or valid answer to that questions unless you are using a shared channel or unless you want to invest on a short channel but for me as i only experienced it share canal is almost almost a naughty pattern so so so for me i don't understand why we like to split and since i came from a world where we used to split split split split layers layers layers layers everywhere i am i'm fine i'm kind of allergic to that extra so to make things worse if you call application and you call application layer in the conversation with your business they will start thinking in terms of application as well and that's something i want to avoid because that's one big antique pattern as well in in business versus i.t thinking yes technicology technical um yeah my mindset yeah and but my answer was not about that it was about granularity granularities yes but the question was about that but not for me but for me the question was um if uh impartial where the same grammarity of other kinds of the same level not good at the same level yeah i think it's it's valid it's uh because i like if you'd like to have application layer yes necessary take take an example as we've done the code if i check was the controller in hexagonal architecture it was a controller too yes but uh for me the the in the in the hexagonal style that i'm used to practice left side adapters is just an adapter it does not have some kind of application or it's just uh um it's just adapters for me in the way i i'm calling stuff so whereas the imperative shell may call this call that is doing some kind of domain logic orchestrating uh chords and things there so yeah the gradient is is very thin uh so you you see the orchestration of the call of the of your domain yeah right i agree i say it consoles used by exhaustion i think it's uh i don't know if it's in english but in french it's a consensus by exhaustion by everyone is tired about that so you say okay okay yes yes so we have uh we used to have the discussion with bruno and it's always end like this i i think in in the days of business is the name is wrong application layers just what is the rest is this not my application it's a part of it if the application is a part of the application how very in fact is this so maybe it's only the name and now we don't have any questions anymore okay cool great then uh that was it thank you thomas bruno finally after months of nagging you this is i awesome enjoyed it i hope the rest uh enjoyed it as well i loved uh thank you thank you for sticking out coding again thank you kenny and thank you for everyone watching the live stream and everyone in the zoom thank you for participating your questions and everything we'll be back in two weeks with another meet up where sophia will be talking about transformation business model in the panemic and we have three more meetups lined up afterwards that we will publish very soon
Info
Channel: Virtual Domain-Driven Design
Views: 2,218
Rating: 5 out of 5
Keywords: Domain-driven design, meetup
Id: SAjsP2igBNk
Channel Id: undefined
Length: 97min 24sec (5844 seconds)
Published: Wed Feb 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.