Event-driven design patterns to enhance existing applications using Azure Functions - BRK3041
All. Right good, afternoon everyone. Good. Afternoon everyone, thank. You, thank you know. We're its presentation, the theme of the or demos is coffee so, I understand. It's afternoon, third. Day of build really. Excited to be here thank you all for, being here tons of announcement, exciting, things. And. What. We want to do here. Today is talk a little bit you all be hearing about survey less and as your functions, it's, my third build every build we, see more and more momentum and more and more users on server less application, event-driven applications. As your functions, but. We still also see a lot of a lot of companies a lot of you a lot of developers, they're starting, their journey and they. Don't know where to start they have applications, that are already built and, they're. You want to use service, they. Don't know exactly. Sure how so, we want to talk about this imagine. You already, have your applications, anyone, extend it further you, want to add functions, you want to serve less to extend your scenarios that's, probably the best way to start and what we recommend, we don't go recommending but, we write all your code make everything functions, as much as I love functions, we, want you to achieve more, innovation. On your code so. So. Here's the plan of what what, we're. Going to show you today, so we're going to talk about what scenario, that the we're gonna build throughout the talk so. We're going to keep extending, it so that is gonna introduce you to to it. After. That just, to level set we're going to do a brief overview on some of the concepts, that's going to be important, for you to understand, what happens later on and, then we're gonna extend that app and it's four different ways you see there, and. At the end we're gonna leave. You with some stuff you can take away so you can implement, some of these scenarios yourselves, and. Before. We go too far so you know you know why you should listen to us but I'm, I'm, gonna p.m. team lead, the PM team for functions. That. Is well we're both on the same team. Particularly. What, I look at these days is how. Do we bring functions, to more places how, we give more hosting models and more options for you to code it functions. In. Special, a lot of the enterprise scenarios I spend my time on and. For me is also interesting I joined sort. Of the agile world with Microsoft, for a long time but as you're about. Six, years ago and I joined apps service when. Would come to conferences, like build all the conferences and a lot of people they. Believe pass will become a reality the reality it is today so, I feel like we're in functions, of service and service on that same journey it's still somewhat younger, and there's still some, adoption happening, but but. I'm super excited to see where that's gonna take and how that's revolutionizing the industry so. That's. Me. Hi. I'm Corey, I'm also part of the PM team for Azure functions, I've, been in this space platform. As a service, and later functions, as a service since 2012. And one fun fact I was the program manager, for the first iteration of our service, offer so the launch of their consumption plan and.
Just Doing, an HTTP, trigger and if. I want to import into a, I am all. I have to do is go. And select AP. I am management. Option. Here so you, can see it in the portal and. This. Is embedded. In the experience, so you don't have to break your flow I'm going, to select the, AP, I am instance, that I want to import to and I'm. Going to enable application, insights because this will give you really, interesting, observatory. Capabilities. And now, in terms of API API, entry points we're going to create one for, each of the HTTP. Methods that's supported, by the function, and. Optionally. I, may. Even go, and select a, product. So. Now I kicked off my workflow, to import. My functions, into API, m, and. I will get a message when this is completed, which you can see right here, see. If I can zoom in. So. Now I can, even go in test it out right here in this portal. And. I. Have. A. Test, app that. I can select and. All. I have to do is add a parameter, so. Let's. Say Bill 2019. And. I'm going to make a call and you can see the result, right here. And. It says. Hello. Don't 2019. There. We go and, what. Else can you do that might be really interesting, to have right here in this concept, another, thing that you can do is you can download the. API, definition this, is just a click away it's really as easy as that and. Then. Another feature, that can, be really really useful is. The, observability. Please notice so, as I connect API am I also want to see what, happens, across all the different endpoints that. I'm interacting, with, so, there's, this real interesting, feature the, application. Map that, is going to allow me to explore the cause that I'm making, and not, only that, but. It's going to allow me to have. Really, easy. Diagnostic. Capabilities. So in this case I'm purposely. Generating. An exception, that we'll use throughout the session and if. I want to go and diagnose, that I have the ability right here to say hey I want to see details, and not. Only do I want to see details, but, why don't you point me to the exact exception. And. Hey. We can actually go do exactly that this is the demo exception. So. Um this, is the power of creating. Your unified API surface, with, very little effort. That. The. Demo the diary, did to investigate. The failure some. People take it for granted as, you do more micro services and distributed, apps for. You to find where the bug is in your code between your API layer multiple, services that you're using all disconnected, roni async, it's a real tough task so just, bringing them all together and be able to either. Give you a graphical interface or, a query language that you can go through the logs to find your errors is super, powerful in something that I haven't, seen other, products do so. Okay. All, right. Okay. So, so. Now that's so extended, we extended with wait API am created, a single facade. Single, surface, for. All that functionality didn't, exist on, our coffee shop for. Which dari and I have been hired for the day to be developers, for okay, so. This. This. Application. And it's common, as you have a presence on the cloud typically. Have tons of other resources, as well your application, if it's complex, it's not a server less it can be all sorts of other components, or deploy to Azure so. What we see more and more is as, you as you add resource to Azure you. Need to have a way specially on caesarian hundreds, of them each, resources. A lifecycle of its own you're, going to deploy your resources and. Again they could be VMs. They can be storage, sequel, you name it but, you deploy them then. You go to that lifecycle, you have to secure that endpoints, according to your rules you're gonna have to do your disaster recovery or, backup to a different region you, need to monitor to react when things go wrong then. You might need to apply different configurations. Or policy, that's required by your organization. So that's, a very common like it's that it's been changing a little bit if some of you work as ITES, or you're. An SRE the. Role has been changing a little bit because now we have to monitor all these cloud resources, and, you.
Multiple. Publishers. Or remote post subscribers, to that that can react to it so allows you to connect anything. To anything else so you can have the computer functions, for. Any, resource you want and trigger from you, can have as your monitors the one I showed so, alerts could trigger your application, logic, apps can call into functions as well or, you can have your DevOps. Pipeline actually call into functions so tons. Of different ways you. Can implement your automation. So, one that I just want to show here, is the problem. The most common one people ask is to start and stop their VMs because it cuts down costs, or because, they don't want those VMs running all, the time so. Here is example, two how to start a VM and this is as simple as it. Gets and gets even simpler, because we implemented, this functionality, called manage dependencies, so a lot of the azure a stick things that will you'd need to bring with your code we, already pre-loaded for, you on our deployed. Functions. Runtime that runs PowerShell, so. In the authentication, as well so you see that this is not authenticated, with Azure or it's, bringing any other dependencies, all, you have to do is this piece of code and this would run and start your VM similarly. You could do a stop VM, as, well, so have, those two examples again they're on the service, library from looking. To them when. You get back home or on the airplane and. Yeah, now we're going to continue the third third accessibility. Scenario, so. With the third extensibility, scenario. We're going to talk about, workflow. Orchestration, with durable functions, and. I. Would. Like you to keep in mind this is an advanced, feature for, writing long-running orchestration. It, can help help you solve a range, of, complex, and stateful, coding problems in the surveillance phase. Durable. Functions, is implemented. As. A, natural functions it's extension, and this built, on the, open-source, durable, task framework, and. What. That means it's. Durable. Functions, just like the rest of functions. It's. Open source and it, also has a surveillance, model of hosting, where you pay only for what you use. The. Durable, functions is actually, not that different from other functions, except, for three, very specific concepts. The. Concepts, are one. Of them Orchestrator. And the, orchestrator. Describes. How actions, are executed, and the, order, in which they are executed. The. Second. One is the activity functions. And the, activity, functions, just represent, the unit of work and. This. Is where the, actions, that we request, are implemented. The, client, functions, they, create, new, instances, of, an orchestration. So. These are just the three concepts that are specific, here the. Orchestrator. Is, the. One that stores. Execution. State and then, replace, that state, - basically. We. Establish. That your ability, every. Single, time. And. Just. Looking. At the concepts, here so. We have an. Example of, the client function, here and the, first thing that we have is an Orchestrator, client, binding, and that. Is the one that can, start, and stop the. Orchestrator, instances, and then, it can get. Instant. Status and send event notifications. And. Here. You can see the transition to the orchestrator, function, so, if we look at what that looks like this, is our Orchestrator right here and then. The orchestrator, is the one that calls the activity, functions. So. Just. To give you an idea of how, this actually happens, in practice. We. Can look at, the. Workflow. That, we use for, a, in. Example, registration and the. First thing that we do is we, have the client, who.
Is, Waking. Up the, orchestrator, by placing. An item, on under, control, queue. So. That has, the effect of waking, up the orchestrator, who notice there's work to do and it, goes and that replace, the state to establish where, we are and we notice that we haven't actually completed. That work so. At this point. The. Orchestrator, can place an item on a work item queue and. It's. Asked, to await, so, it can now go to sleep, and. The. Activity. Function can pick up the. Item from the work item queue and, it. Can execute, what we asked it to execute, it, places. An item, under control queue to let the workers traitor there's something to look at and then. The orchestrator, will, go it, will replay, the state noticed, Agnes now we have a result, and return. So. Going back to, icon, toaster coffee shop we. Also. Extended. Our app will. Be ability, to do. Order approvals. So let's say I'm the barista, and I need to order more coffee because, haters. Build and there's so many people in town and so. I need, to request, approval. For. My. Coffee and so, we implemented that with the durable, work flow pattern, and. Just. Going to illustrate, that. Let's. Go back to our little application, here. And. The. Way that I'm going to. Place. The approval. Request is by, saying I want to order, a certain coffee blend, and then. I'm, going to submit. A request. Which. Shows up as a text, message and, I'm sure you all can see yet, we're. All close enough and that, text, message is going to be the one that, allows me to approve. The order so I'll do it right here and. I. Prove, to all of you she really proved that it was not yes, and we really banked on the fact that you can see the phone screen from there but, you know what you can see is that, we have a change of status here. So. If we zoom in you can see that we did change the status and this now shows approved. So. How did we do it I want. To give. You an opportunity to have a look at the client code first so, we had a client app, page, that, showed you how, we are requesting, the approval, and, all. That, is it's basically calling. Into. This. URL, for the orchestrator, here it's, actually. Abstracted. It, or today, Jordao. Task framework, underneath, but. This. Is what it looks like from the client perspective. Now. Just, to go to the other side of the client experience and, then we'll move back to the back end of durable, functions, the, other side of the client experience that you just witnessed here, is how do I send the approval, and this. Again is a call from the client app and the, way that I, implement. That is by raising an. Event so, this, is. The. Code right here to raise the SMS, challenge response event. Switching. Back to the backend. Here. We have the orchestrator, code so. I will. Point out that, as we are, in this context, we. Have the ability, to, call. The. Activity function, right here and this is the one where we send the phone number and we request for the. SMS, to be sent and, for. This particular, demo we. Set. A timeout. Of 90. Seconds, but. The. Good. Thing to know is that this, is not constrained. 90. Seconds, is just an example timeout, the power of, the, durable, functions. Is that you can really have a long-running. Operations. As you need and. Then. The. Other thing I would like to point out is that. Here. The. Orchestrator. Will actually, go to sleep while it's waiting for an async operation, to be completed, so that addresses, some of the questions, in terms, of hey do I get charged for everything, and, you only get charged when this is running. And. Just. A little. Note on how a state is stored so we store that in a. Table. Storage. So I'm. Just, one showing. You an, example, that we won't go through but it proves that the different stages of execution, are. Going. Through. So. Back to the site. Just. Do I like what. The reason the approval workflow is interesting, is because the the time that it would take for a human to react that's not, predictable but, we, do know your functions reruns for over ten minutes of regular functions will shut it down right so. So, this type of pattern, which. Is just not possible with just regular functions, you'd be limited to those ten minutes unless you deploy functions is dedicated, but you found that serverless way to do so you, need something like durable, so so that's that's why. Durable is important in this scenario so. For, this particular, session we only show you the human interaction, pattern with durable functions. However. There. Are a lot of other patterns that, you can implement and these are a few of the other examples.
You, Can do, functions. Changing, where, you, take the output of a function and use it as the input to another function, you. Can also. Do the. Fan-in and fan-out pattern. Where, you can use, an event to. Paralyze. Execution, into a bunch of functions and the power of this particular, pattern is that you can do aggregation, at the end and, then. The, the, API. Pattern. With async. HTTP. API is this is something where you may have a long-running, execution. And you may want to let a. Client, out here, know what's going on and this is actually how our later example was implemented, as well we have a way to, go inquiry, established, through the HTTP. 202 pattern and. Then. Monitoring. On an external endpoint, with the another one and. We, have a session, coming up right after that, is really focused. And a deep dive on terrible functions. And. It's going, to go into the new features for stateful, entities as well so. I would totally recommend that if you have the time. There. Are a few, gotchas with. This. Workflow, so the orchestrator, has a couple, of requirements. The. First one is that your controller code must be deterministic. Because. Every operation, has to have the same result, it. Will be executed. Once and then we will replay, the same result, so. What. You don't want to do is don't use random numbers don't generate, goo it don't. Do IO directly. In the orchestrator. The. Other one is, don't. Write infinite, loops because, what happens, is we, have an increasingly, long history, that we need to relate through and that, means that your execution, time might increase as well. So. Going back to, the life section. Of our presentation and I love that durable functions, things I think it's still we. Love. Talking about it because opens, up so many possibilities just. A little detail - oh like like. When you do a task, and you can wait and you can do when all it's just so so powerful like so, if, you haven't tried try it out now. Less. We, won't extend scenarios with with, machine learning how, many work with ml some way or another. So. A few of you so it's good because I have a just. A few. Context. Here's just a few slides to see, what why, ml and why why you should care and how you can implement it so so. Typical. Process. Of machine learning, is. Divided, into model, trainee and model deployment, so. In very basics, typically. What you you have is a large. Data set in a raw format, that. You want to turn that the model you want to learn from those examples but. This data set to have dirty data is gonna be incomplete not going to be in a standard format, so you need to pre-process that data this, is a iterative, process, until you get the data in the state you need remove, duplicates, and so on so forth once you have that the right way you're. Gonna pick the tons of different algorithms, in ml like what is a regression, I bathe you. Name it and you can pick. The right algorithm. For the job you're trying to achieve if it's if, it's something related to images, you might want to pick neural networks is really to text you might have pick something different so you, pick the right algorithm, once. You pick that you typically reserved, some of the data set to be your golden set to evaluate that model you're going to get a precision recall number, back to, decide which model fits. Your needs in terms of what's, your criteria for it to go to production once you find that model, you actually deploy, it and using your application a lot, of your developers, you're probably on the further end of it is where. You typically live, which is on the application world. So. So. Now the. Way the way this is typically done is you have a data scientist, and here's the one. Responsible. For model, training a lot, of his day job is on the data set and cleaning up finding it right data and. Then just, like I showed the algorithm, that you want to use and then, how often do they need to retrain, to account for new examples, there's happening, on a particular, scenario the. App developer, typically. Is left with the job of hey, the model does exist, how, do I put this in production like what is what is the right model do I need to use a VM do and you'd use a pass service. How, all you a load this up in memory do I break it down separate. Do a processing. Parallel, that process linearly, how. Do i scale in case this model is something that's going to have, thousands. Of events, at the same time how you're prepared to handle such load and when things fail how do i monitor it so.
If You could think if you're noticing a pattern and all these questions what solves all these questions is this service, really, helps with all of these questions so once you apply service. Or function as a service now. You, can take advantage of all those things I talked before about service, and then, have. This thing ready to scale but, let me show how that works actually functions, so, when you train a model typically. Get an asset out of it typically the mod is in a binary format. And. You have a script that script knows how to use that model, very. Commonly is going to be Python, what's gonna be that scoring script and. On your Python code you might have some dependencies, it's gonna bring some libraries, helper, libraries, or some other libraries that you might want to use once. You have all that you can deploy it as a functions also. Something we didn't, have before we start with. Pythons. On public preview, and. Let's. Say your functions, in HTTP, trigger function you, have your input data using, HTTP trigger to use that model so so. That's typically, how it works but I want to actually show, you so so. Yeah I didn't add it to the main app this. Was done by our research. And innovation, team so it's a little different because ml, we're, trying to find a fun scenario, it's a little silly so bear with me, I know, all. Of you have this question how to order enough coffee for your development teams so we thought this was super relevant to this ah yes. So. And there is again. The point the presentation, is not as much model-train II. Don't. Intend, to turn your own data scientists, in in a talk but so. There's a bunch of data sets already ready for you iago has one of those so. You, found this fascinating data, set that do. Analyze it's amazing how much time people spend on this how. Much how, much programmers, drink coffee and they analyze the patterns they. Were able to map coding, hours to the amount of cup, cups. Of coffee per, day what time of the day they drink it what, type of coffee etc so, you. Can in this this gives you so many possibilities but, ok so. What we did with, with all of this we created. One. One, app here, and this is the front end that goes in a given github, repository. Looks. Like at the amount of commits. Assume. A given number of hours per commit and then, we estimate how much how many more cups, of coffee you need to keep your team running for next two days again. Super. Useful I'll share the code because I know you need it but. So. But but let's show the code now out of the fun part like that's the part that that does matter how do how, do you leverage those things on as your functions right, so.
Access. Resources, on a V net and you, could do that communication. Both ways but, some, other times you also want your code that process, that data to, be fully isolated no, HTTP. Endpoint exposed. So, for, that you can have for isolation by using the app service environment, and run your functions app service environment, so, ton. Of different, options again, none, of these limitations, are particular, to Python our ml it's just functions in general we, always like to say try. Service, that, should be a great way to subs 90%, cases but it's some of the other cases you will need one of these options at the bottom that, to give you power to overcome, some of these limits. That you might face. So. If you take aways for this session. The. First one we. Have a lot of announcements. Around Asha functions. Either. A builder and proximity to build and, we know that you get so much information so, just. Go. Look at the Asha blog and, you'll find a lot of our. Announcements. With these. Verses for further learning and, links. To our dogs and everything that you need to get started that. Includes. A broad range of announcements. From, running. Functions, and kubernetes, with, serverless scale to. New. Development. Language improvements, and announcement. So the. Announcement of powershell core and then, improvements, for our, deck a dotnet support, with dependency, injection, improvements. For a darknet lang non dotnet, language experience, with extension, bundles, and then. Going. Into developer, experience with improved agile devops. Support. And a. Bunch of others that, you can definitely go, and. Look. At as, part of our build announcements. The. Other thing that I wanted. To make sure we, mention here, is that. Getting. Started is really easy, if you don't want, to write your own code you can get started with samples, that are available in the surveillance community, library, and also. You. Can contribute, to that and you, can make, sure that the world gets to benefit, from your code if. You submit it as a sample. Just. To recap. What, we learned today we. Have a few design patterns, that we covered and. Those, winds cover. Creating. Unified, API services. Surfaces. Event-driven. Automation. The. Long-running. Orchestration. And machine. Learning with, Azure functions, but these are just examples we. Know that you have business logic that's already in production and, you, don't need to rewrite that you can always extend it and leverage existing assets. And, really. Enhance their value with serverless technologies. Also. We. Know that surveillance. Like a writer said is. Appropriate. For maybe the majority of cases but, there will be cases where you need to use something else so, don't be afraid to break the server this class and create, composed, solutions, they really work. If. You, want to get started there, are a lot of resources, to get started with Azure functions, and assured comm, functions, and also. You. Can go, to our, github repos, you, got, introduced, to them in terms of coffee cups but, they're real and, they. Really. Allow, you to participate in our community, whether is just a signal, an issue and, tell us we need to fix something whether. They're. Participating. In the discussion, or whether. You want to submit PRS. To improve our product, any, and all of those are always welcome. Yeah. And we're pretty we're pretty active on I think, we're pretty active like on Twitter too from the reach out to us also, realize. We have time in the end I know some of these announcements, we didn't we. Didn't cover some, of them at all so if you have questions on any of them di. Integration. With DevOps, any. Of the stuff you've seen there we're, happy to answer either here or online later or at the booth as, well. There. Are few more things coming in and, a few more things coming, we. Have a couple more sessions that are coming up this afternoon, so we wanted to make sure you're aware and, then. The, recordings. For the other sessions, that are covering surrealist concepts. We. Wanted to say thank you so much we know you have a large. Choice and a lot of options and you chose to learn the best herbalist, in this session so thank you and. We. Always, appreciate, feedback and, we, appreciate. That a lot of resources, that you can use to continue your learning. Thank. You everyone.