scale.bythebay.io: Nikola Kasev, Declare, verify and execute microservices-based process flows
short problem we've got welcome everybody one of the lost talks of the conference I hope you enjoy just a little bit about me I have two kids a daughter of four and a son of seven he just turned seven and this is me baking a purchase so poorer cheese I come from the from the Netherlands and properties are like pancakes that are very you know well-known in in the Netherlands or if you once go visit Amsterdam you should definitely go get yourself some porches and this is a summer school festival or celebration and why I like baking porches for the kids is because it gives them a very like nice feeling when I bake and then I can create I can make somebody you know experience some nice emotion of you know liking liking poverty's and I recognize cooking I compare cooking with programming when I was 19 I moved to the capital city of Bulgaria to study and me and my brother we had to cook I never cook before my mom cooked always so you know you start very small with a few ingredients and then suddenly you start getting tired of the same cooking the same meal all over again right I'm sure you recognize that and the more you started adding more ingredients you start trying out new recipes and this is a bit like a programming language you start very small you read the hello world example and then starting to build a build up on this so as you have might noticed I love cooking and for the rest of my talk I will use examples from from this industry I work for a bank global financial institution ing we are present in more than 80 40 countries and we like to think of sales as a software company with a banking license which many banks they will think you guys must be crazy we're just a financial institution we'd like an old-fashioned bank we already have a microservices infrastructure and this is to tell you more about the problem that we wanted to solve and why we built that library that I will talk about so our challenge was the following we were building a new application a new business process at the bank and we had to interact with the 12 different systems and out of those systems we had to interact with 25 different interactions we had to give instructions to those micro services the most annoying of all was that we had a process that could take from 2 minutes to 6 hours that was because there were a lot of manual work also involved and we had to actually create a system or an API that would handle State for us so when you involve state in a distributed system it becomes very very annoying of how you solve it so we had to build an API and we knew that we wanted not to be afraid of changing our application code so just a show of hands how many of you guys have broken your application unexpectedly by changing code well yeah some people didn't raise their hand so I'm like whoa I need to learn from you guys how you do that we also as I said we didn't want to break the functionality and expectedly and last but not least we wanted to be able to create new functionality quickly right so in we're we're a company that has history we're not a start-up we've been operating for more than I think 200 years so we have a lot of legacy we have a lot of processes so that's the challenges well how do we turn the tide around so we ask that ourselves that question and you look no further than this guy how many of you guys recognize this chef cook chef cook this guy has also TV show I think on American TV and what he does is he helps restaurants become profitable again and what's the first thing that he does do you know he yells and he screams and he uses some not very sophisticated English language but for what I think I can recognize of what we tried to do it Angie was that this guy simplifies the menu so the first thing he does except for yelling and screaming at all the people he looks at the menu he says I just want a one page menu with with all the dishes that you're selling and you're thinking well what does that have to do with applications well let me introduce you to Baker it's an open source library that we built in Scala using all those examples from cooking where we developed a domain-specific language to describe orchestration logic so as I mentioned before the 12 systems we had to orchestrate our logic he'd spent across all those systems and we created to do many specific language for that is declarative which means that you can just specify a recipe or what the logic means it's like specifying reading a recipe on online of cooking some poverty's and it's easy to change because you write less code so I'm just introduce it to recipes it's you have interactions what we call those are all the call systems you have ingredients that's data a baker is data-driven which is very important to reason about your logic and it also deals with events events like in a kitchen when I'm baking a pizza one event could be that the oven reaches 260 degrees Celsius that's when I put the pizza in the in the oven so those events are business events that also your customers experience and know they touch with your applications and then you recognize those business events we also would like to communicate and communicate is very important for developers because we like to basically just sit behind our laptops and never talk to anybody else than people that understand code well in a large enterprise that doesn't really work very well so we are like maybe we should start talking to our business and what do they think about our logic their code when you show them Scala code they freaked out so we said well we maybe want to show them some graphical notations some visualization and maybe we'll talk to them about recipes and ingredients they will understand that so without further ado let me just show you some baking of some crepes so when I was on my own the airport in Amsterdam I tweeted this and then scaled by the bay replied with we love some crepes with cream so guess what I did on the fly back on the flight to San Francisco I prepared some code to show you how to bake crepes and then based on this you can reason and you can figure out how to make it work in your enterprise so well what's the first thing you do you look at the recipe so that's the recipe of how you're baking crepes so let me show you how it works okay I'll switch back to my development environment is it still readable for you guys at the back debugging applications in production maybe yeah it's fine all right so I've prepared a simple test so what you guys sing is some Scala code and two tests just to also help me in giving you this live coding session so the first unit test that I've built was to compile a recipe which means validate that this recipe is executable so this is basically making sure that your business process is sound and can be executed and the second is about the runtime properties of Baker the library that we've developed so you can use Baker as a design time tool to reason about your application logic but you can also use it to actually execute the flows for you so in the first one I have a compiled recipe which must not contain any validation errors so let's go and define this this recipe Oh so the crab recipe it's a recipe cooking crab sets Twitter headquarters and it will require some interactions those are the steps in the in the recipe those are the calls to microservices those are call to legacy systems to anything that you guys are interacting with I'll leave this a list of four interactions for now I'll leave it empty and I'll also introduce you to sensor events so events are like what I just well I mentioned its what what happens so when do I cook crepes which one the kids are hungry it's another event kids are hungry and then I basically say I will create the recipe it doesn't have any steps so let's see what are the steps in cooking such a lovely meal mix the first three well I forgot to mention I already defined ingredients so I did it a bit because when I was timing its idea I could I would run out of time so I defined all the ingredients for you don't have to go back to the recipe well basically when you cook crepes you need milk you need eggs some flour some butter and some cream like you guys mentioned why we like crepes with cream so I made crepes with cream so those are my ingredients this is the data that I'm capturing in my flow so now I'm talking about crepes but it's in a financial services company we're talking about transactions customers all that so this will be an interaction it it requires a name so that's a mix first three it requires a list of input ingredients so this is when what what is required in those in this interaction this will be a sequence of the first three so I need milk I need eggs and I need some flour and the last parameter is what does it give me so what do i output out of this from IntelliJ yeah I'll wait we are now turning the lights off no I'll keep going guys yeah anyways so each interaction it's each call to a system underlying system is also providing you some more data capture some mode data so in this case my the the mixture of the first three ingredients will give me some better so it will provide only an event that says better is mixed or let's say better is ready so let's define this event as well is another event and it provides me with better all right so it will give me that so let's say let's see I'll just quickly create the other one so I've mixed the first three ingredients what do I need to then do I need to fry the the crap so fry crap is an interaction and it requires the better and require some butter right you put the butter in the in the pen and then you say well the crap is ready so there's another event when you're ready with like frying the crap so this will give me the crap right and what's the last thing I forgot about the cream so then I'll just serve it right I serve the crap it's a last interaction in my in this demo so that I don't spend more time serve the crap which will require the actual crap and it will require some cream all right and it will tell me that the crap was served this is it so now what I've defined is I have defined all the three interactions I've decided I've said what require what that is required for them to be executed and what extra data they capture so by executing the flow you actually accumulate more and more knowledge and this knowledge is used for later subsequent processes in your steps in your process so let's add them but here I'll make something funny let's I will just say you know I will just serve I will fry or let mix and then I'm gonna do what's the what's what's left I'm gonna fry and let's see what happens I've got the recipe now I've said you will start cooking the recipe when the kids are hungry and you will perform those three steps I'll go back to my unit test and I will run the first unit test it's now compiling and in a moment it will run the checks if the recipe compiles boom what's going on the ingredient butter for interaction fry crap is not provided so now Baker will start visual and whit was they'll start verifying my recipe and it will see the some interactions required data require ingredients that I haven't provided of any of the sensor events so this data those ingredients are not there yet so let's go back to my events and I will define another even which will be that I have done some groceries groceries are done and it will be a sequence of all the groceries that I've done some milk eggs flour butter thank you what else cream that's it and here some other interesting stuff but I'll come back to that later why do I need that makes firing limits that's another feature that if I have time I'll explain as well so I will also say well this event it also has happened the groceries has done and now it's complaining or because I need a list of events so now I have another version of the recipe with two sensor events so once is the kids are hungry but also the groceries has done so in your typical business process in your company you will have multiple events or many events it will happen for a particular process so you can model all those well this is not what I expected so let me see if I can rerun it again okay oh it's green Wow so the recipe is now valid so that means that now now I created a recipe of creative business process that validates correctly let's see how it looks like so from the compiled recipe I can do the I can get the recipe visualization so what we're doing here is instead of in a typical environment like in the 90s in the in the previous and in the 2000s you would create some visual diagrams like UML or something like this need to generate code after that what we do is the other way around we take the application code and we generate the visualization out of it and this is how we can reason about the our application logic much more comfortably so now I will take this output and I will use an application called web gravis and I'll generate the visual representation of my logic so what happened the grey elements are the events this is the data and when the date is available at all so all the interactions that I've defined so in my recipe I have three interactions you see them all here and basically the ambition of my recipes to achieve a goal to serve the crap in in your business process it's when maybe a customer orders a product from you is the delivery of that product so the customer promise is usually one of the last things in your in your recipe but this one is like hanging and not connected right so I will if I have the groceries out directly start cooking maybe that's not the idea let's let's see if I can only start cooking I can start mixing the ingredients when the kids are hungry all right so let's let's say add an extra precondition in the recipe so in the recipe what I'm going to say is that mixing of those ingredients only will happen when the kids are hungry and if I run the unit tests again I expect that this second event will be connected okay so now it's that's a valid that's a valid recipe so when those two happen I will start cooking so I showed you so far the design time properties of Baker let me now show you if I were to actually create an API or create a useful application logic that will sense those events will give them to Baker and Baker will start executing all the logic for me so what I'm gonna do is we're gonna go into the second part of my unit test where I've prepared a few steps served this is basically expecting the the actual customer promise it's expect that the last event is there it will compile the same recipe and it will generate the process ID a process ID Maps one-on-one with a customer journey or interaction of a customer with your with your business process so the first thing I'm going to do is I'm going to create a Baker instance and what does it require it requires the compiled recipe and then it requires some implementations so this is the actual useful logic that will be executed by Baker so so far I've only defined the interfaces I've only defined the design time properties of a recipe now I'll create the actual runtime so what I'm going to do here is I'm going to create a sequence and I'll go back to my logic and I will implement those interactions so those you can implement the way you like them it could be calling API it could be microservices could be legacy systems could be putting a message on a Kafka bus it could be it could be anything so the mixing of the first three ingredients implementation will be it doesn't make sense it's a mixed first three implement and then what do I get here I can get a function that tasks gives me all the three ingredients and I provide any an event so I will say I get the milk which is a string in this case I get the X and I get the flour and then I'll just print print line it oh so that you can see what I'm mixing some milk eggs and flour and I'm also going to say that the batter is ready so I'm going to issue that that if that the event smooth smooth better so copy that so this is the implementation so this could be the data that you need to give to an underlying system and then when something from the underlying system is important for the rest of your process you give that as a payload in the event that you will issue back to Baker so this will be then the second implementation of frying this one only requires the better and the butter in butter and then I will say that the crap in this case what do I get out of this interaction is that the crap is ready so I'll say testy tasty crap and the last implementation this one I will disregard to save some time I would just say I'm serving it served and they've also raised the event okay going back to my unit test I now have the all the implementations and I'll just provide them as a list so this is where we hook up in the design time part of the recipe with the runtime logic I will do the implementation of the crap and also the serving okay and what I also need to know is I need to tell Baker to bake the recipe so for each customer I will bake a new instance so it's like a customer going to the restaurant and getting an instance of that process and I will mention to Baker that an event has happened so for this process ID kids are hungry and also for this process obviously I need to run I need to run run some errands and do the groceries so the groceries are done and here I actually provide the values so just go back for a moment to not to mess up the ingredients I'll just copy that going back to my unit test half-and-half what does it help a help I went to the supermarket yesterday and I saw half-and-half milk what does it mean oh it's cream and milk oh yeah now I now I get it half and half milk I will do some or is it called free-range free-range eggs those purchase your baking hour but with you they're made with buckwheat flour and some grass-fed butter so see I'm just putting some actual data into the into my recipe yeah I'm just a plain old cream you know that's a good remark let's see what happens now I will oh yeah and obviously when I have when the kids are hungry when I've made all the groceries all the date is available so I should I expect that this event has happened as well that I have served the crap so if it's all fine I expect that this test is green as well and that I see some print lines so I've mixed some milk bla bla bla some better I put in on the pan with some butter and at the end of that I serve the crap so with this I showed you how the design-time properties of the library allowed me to attach that with implementations around the implementations in in Baker maybe I can also show you how the runtime properties of the recipe look like so I get the visual state I can ask for the visual state of the recipe I still hear some time and I'll print that one as well just to give you a taste of what you can do when you're already running Baker in in your application it allows you very quickly to check and understand if for example you haven't shipped the product to your customer what was necessary that was not fulfilled and I can tell you when you're in a data center debugging something 18 degrees in the air conditioner it's very nice that you have some visualization to show when some customers are not getting what they're getting and what they're expecting so when events happen they're marked in green and then you see how the complete flow goes this is a very simple recipe unfortunately I cannot show you the one with the 27 or something steps that we actually run in production it gets very complex real quick when it comes to visualization so you might want to limit the visualization to only the stuff that hasn't happened so you have this is just a dot visualization and Wladimir just suggested to me before the talk that we might also use plumb tml to generate another type of visualization or this so a lot Amir thanks very much for your suggestion guess what I'm writing on the on the flight back to Amsterdam so this is one this is what I wanted to show you of how you cook some things that are good to know is that you can use Baker for short lifts and a long running flows which means that you can execute everything in memory in your API ice but you can also run long-running flows where we persist the state all ingredients we percentage persist in a cassandra key store key space sorry we take care of state so for all the developers that are using Baker at ING we have 12 teams adopting the technology and applying that we there with their business processes they don't have to worry about creating a system that takes care of state we do that for them as we are in highly regulated environment and many of the customer day must be encrypted when it's in flight and when it's at rest so we we encrypt all the data automatically for all the teams so they don't need to worry about how to do that on their own and when something breaks and or maybe you do an update of your Baker functionality we will replay all the events out of a journal so that all your processes will go to the most current state when failure occurs we like to model it you know in a way of modeling functional failure as events that come out of your interactions so you model that you figured out what the steps in your recipe if something works if something breaks in a technical way so let's say an exception of some sort then Baker will allow you it will retry automatically for you which works well if you have idempotent environment where your functionality can be called multiple times when I'm getting the same order with us we're also dealing with legacy systems making mainframe systems and let me tell you what I don't think they knew about idempotency back then so what that was one of the reasons why I set the mechs firing limit we can limit the amount of if we can say this event cannot happen more than one time or this interaction you cannot call it more than one time so that you don't make a second payment when the technical failure occurs or when messages get lost what we've discovered very well that works very well for us how many of you guys have heard of the Moscow model of sizing well it's basically when you look into a process or when you look into a user story you say well that's what we must have that's what we should have what we could have or what we would have so it's basically sizing functionality of how important it is to the business and what we're saying is that we've seen successful implementation of the Baker when you look into not one or two processes but all processes in your organization and map those to what we call our capability matrix and the capability matrix looks like this I work for a department where we're dealing with non financial transactions so let's like opening of accounts closing your account asking for credit cards and all that sort of stuff and we have many many processes and they're more or less the same yet somewhat different so here I'll show you a comparison of three processes checking account the savings account and a customer onboarding you see some of the functionality is the same but some is not so we create a baker catalog with all those interactions and then teams can combine all those interactions in different ways in their recipes so when you build the actual logic in and interaction once all teams can just reuse that which allows us to very quickly develop a new functionality so this is the URL where you can check out Baker I'm really I would be very happy for you guys to give it a go and let us know how you adopt it or how you what use cases you try to figure out and use Baker and I would like to thank you for attention and maybe if you have questions let me know [Applause] is it asynchronous or synchronous with your execute different steps that's a very good question thanks very much actually for our developers we don't want them to worry about that they're executed asynchronously so events are handled asynchronously you might also want to handle them in a synchronous way so I showed you handle event which is a nice which is a synchronous way of handling an event but you can also say I would like you to just handle the event I don't want to wait for any underlying interactions to be executed so that's on the use case what you want to do in our some of our API is we call them we split them into an interactive part where the customer is still with us on their own on the journey their feedback is important we might give functional or technical failures in this case we execute those in synchronous synchronous but if for example the customer accepts the terms and conditions and maybe in four hours we need to send a package to his address then we just handle all those events in an asynchronous way our developers they don't users of Baker they don't have to worry about that so we simplified all that for for the users oh yeah so what you saw in the beginning of my what Vlad asks is well how do I make sure that the ingredients are supplied in a lazy way so what you saw in the beginning of my my demo it was only the configuration so it was just the names of the ingredients it was not the actual data so this was the design time part that it's basically part of your logic and when events happen then you provide the actual data so I said milk but then actually when the event happened grocery was done I gave it to half half milk so that was the actual payload so telling me this is the part of this part of milk yeah basically what I what I showed you is that I joined two paths I had two events that were joined you can also execute things in parallel so for developers they don't worry about that they just give all the interactions and Baker will decide which interactions can be executed in parallel which can be which are which are necessary to be executing signals based on the data based on what's required and what's provided loops that's a very good question we actually in the financial services industry we don't really want loops we don't want now imagine your account and then we have something that loops and then it depletes your accounts well that's also one of the reasons why we apply then you will make them maybe each payment would be a single instance of your recipe we're looking into that though because we also had question from one of the things well how do we close multiple accounts and we actually told them you just get you define it as a function that gets a list of accounts that you want to close and then you just make it such that it can work with one or multiple accounts and then you just close all of them but the good question Bob thank you yeah so it's all done on the state so it's all done the decisions of the education flow are done based on the data so if all the data is available for interaction to execute then you just get then you just execute okay all bets are very good thanks very much you also wanted to know what if I would like to make some decisions in my recipe that's we have a term for that it's sieve so sieving like flour a sieve is you can think of it as a pure function that gives you an ingredient that gives you that ask some ingredients and gives you and provides you another ingredient and based on that you can precondition that on on different interactions so we use that when we capture data from our customers and we call it a customer data object maybe not the most maybe not the best name and then we would like to filter may be on the telephone number to provision some telephone related logic then the interaction will be pre conditional telephone number and with the sieve function we'll just extract in a pure functional way we would just extract that telephone number and then let the flow continue thanks very much for your course thank you [Applause]