 All right So a couple things before I get started first. I just want to thank everybody for coming out. This is definitely the Biggest Crowd I've ever seen for a web assembly talk. You are all here for web assembly, right? It's not you're okay Just making sure you're not in the wrong room Let's see second I apologize if the reflection off my head is uncomfortable for some of you the The lights here are pretty intense wasn't counting on that All right, so My name is Kevin Hoffman the CTO and co-founder of Cosmonic, which is a web assembly pass Created the web web assembly open source project called wasm cloud wrote a couple of books and I'm very easily nerd sniped all you have to do is say One or two distributed systems buzzwords and I'll wake up a week later with a thousand open browser tabs so my goal for this session is to hopefully make it so that you will want to leave and go and start playing with this stuff and Explore it so that's that's the goal So Basically going to go through some layers at the base layer. I'm going to talk about what web assembly is So actually I need to pause before that I Checked that you're all in the right room, but how many of you have used web assembly? That is insane. Okay How many of you are sick of hearing about web assembly? Couple in the back I see you So Another goal is to hopefully try and convince you that all of the hype around web assembly isn't just hype and that There's actually some meat on this So after I go through web assembly, we'll talk about what wasm cloud that I'll talk about how You can build all sorts of things on top of wasm cloud and the thing that I'm going to talk about today is event sourcing And then hopefully I'll be able to get to the demos fairly quickly so we can get to qa I can I'm going to skim through this fairly quickly web assembly is an open standard and The usual buzzwords are that it's safe and secure. It's fast and efficient polyglot and portable Wasm cloud is how many of you have heard of wasm cloud? Okay, that's also insane right Wasm cloud is an open source runtime that sits on top of web assembly and adds What amounts to an orchestration layer in an application runtime? It gives you Secure access to capabilities and I'll talk about what capabilities are in a minute It's horizontally and vertically scalable but the thing that I think is most important about wasm cloud is that it Moves the decision about the size and shape of your application from design and compile time to Something that you can just adjust at runtime You should be able to take your monolith that runs on your laptop turn a knob and spread it out across Global distribution without having to recompile your code. Not sure why these are all animated My skills with slides are Fantastic, all right, so the basic primitive when you're building applications with wasm cloud is what's called an actor They are inspired by the actor model and the goal is to build your business logic in these units of these web assembly modules that are Freestanding and Tiny and portable and scalable and secure And I've got a red asterisk next to components because at the moment the web assembly Component model is still fairly volatile. So while we have support for this right now The developer experience isn't quite where I'd want it to be That's stabilizing soon as the standards firm up But the short version is Write your business logic compile it to a web assembly module and we call that an actor capabilities are a separation of The purpose of your code from how your code executes So if I want to write code that talks to a key value store I My code should not have to care about how it communicates with that key value store or even what key value store it is All I want to do is get and set Data and that's it so this decouples the libraries from business logic and We cryptographically sign them. So the actors that are running in wasm cloud Have an explicit grant of privileges. So in addition to the web assembly sandbox and all of the other security you get Wasm cloud will prevent any web assembly module from talking to a capability that it's not supposed to Wasm cloud also comes with what we call a lattice. It's essentially the web assembly version of a cluster It's a flat topology with no discovery required. So Every one of the actors that you've deployed Regardless of where you deployed it or how you deployed it is Accessible on this cluster and you can simply communicate it with it and it just works a lot of that is enabled by Nats, which is another CNCF project Does anybody heard of Nats? Okay Definitely in the right room All right, so Let's do some demos So the first thing I want to show is This which is a dashboard that wasm cloud provides. This is I'm essentially looking at a Wasm cloud host and you can see I've got a couple of actors in here My list of capability providers. I've got a web server event sourcing which I'm going to show in a minute and also Redis and These actors are linked to these providers through configuration that's all that's set up down here and I don't want to Go through all the low-level details But one thing that I think is important to point out here is That the actors don't own the the abilities so when I'm building a microservice and go and You know it has a restful API and it talks to a sequel database when I build that It owns my choice of client for the database and it owns The web server and it owns how the web server starts what port number it picks all of that stuff is in my application and I own it whether I like it or not What wasm cloud does is make it so that the infrastructure owns the abilities and Your code just works against the abstractions so it's kind of hard to tell from here, but the echo actor and The KV counter actor are both using the same web server ability. They just have different configurations The KV counter actor and the bank account projector are both connected to a Redis key value store But three different configurations so if let's say I have a logging ability and There's a giant vulnerability in the log Application or in the log library Instead of having to take every single team that has that dependency Forced them to stop what they're doing and make them put the patch fix into their release cycle I can just change the the ability at runtime and none of the actors know about it And I only have to change it once So I could look I could literally swap this Redis Provider out for Cassandra and none of the actors would know nor would they miss a message so the first actor is the echo actor and In in typical fashion, I'm just going to demo some Jason here and This is I'm sorry. I haven't been able to figure out how to zoom in on the new browser, but Basically, I'm just running I'm accessing my actor and if I take a look at the code for this This is the entire thing. Everything else is just you know headers and things like that this This actor is a web assembly module that is That declares that it talks to a web server It takes a web request as input and returns an HTTP response as output. There's nothing else here You know, there's no port number. There's no TLS termination. There's no certificates All of the stuff that my code should not care about is missing from this So the next one that's also running in this web in this post is This thing called the key value counter and the key value counter is similar to the echo actor except It's receiving a web request incrementing a value in a key value store and then returning that data and If I look at that one you'll see it's got a little bit of restful API here and then When it increments the counter, that's it Sorry, I'm having some track pad issues I just call it increment on my abstraction and then the runtime takes care of the rest. So when I call increment Here it could be in the middle of a unit test in an acceptance test on my laptop using a memory store or Like I'm doing now. It's in Redis and Let me see if I can Just to show that Yeah, there's my cube counter. So it's for the typing. All right, so that's Just wanted to show you that there's nothing up my short sleeves. So we've got the counter and we've got an echo and All of this is rigged up through a wasm cloud host and you get one of these just by typing wash up The wash is the command line tool for wasm cloud. So let me see if I can get back here so So with wasm cloud you saw that we can build Fully functional applications micro services functions as a service Monoliths fully distributed systems all just using simple web assembly modules and They can deploy to anywhere from anywhere and One of the really powerful things about wasm cloud isn't that it is and just an end goal for building applications It's that you can build Your own capabilities So we saw that web server is a capability and key value store is a capability There's things like message brokers and SQL databases and I even wrote a telnet one because that's just how nerdy I am and Event sourcing is actually a capability that we added to Wasm cloud so Who here has heard of or used event sourcing Keep your hand up if it was a horrible painful experience Yep That's as expected So the key pieces of event sourcing is that reality is event sourced Everything that happens in the world has already happened. It's in the past and We take that same concept and apply it to an application And say that the state of the our application is derived as a fold Or you know just some function across the stream of events Event sourcing is the strict and opinionated version of Some other buzzwords that you've probably heard like event driven CQRS and so on there's a There's a level of rigor and discipline Jump between just having a reactive app or an event driven app to being event sourced And what that usually means is there are rules that you shouldn't break that everyone breaks Event sourcing or event sourced apps are built out of a bunch of primitive Lego blocks that you stitch together to form your app. There are aggregates projectors process managers The terminology gets a little muddy when we talk about IO I refer to them as gateways which are made up of notifiers and injectors and Concordance is the name of the open source event sourcing capability provider that cosmetic created So why do we actually care about event sourcing? Especially when it comes to distributed systems one thing that we always want is a single source of immutable truth having built applications that have caught fire and production many times one problem that we typically running run into is Not only do we have multiple sources of truth in that in production, but we have multiple conflicting sources of truth and That usually ends up producing a bad experience for the people trying to use your app Another thing that's sort of a different mindset between the quote-unquote regular application and an event sourced one is that failures are actually modeled as events rather than things that we suppress inside a tri-catch block They're designed for evolutionary architectures One of the phrases you may have seen on some blog posts is that event sourcing is all about choreography whereas the traditional model of microservices is about orchestration and Finally and probably one of the more important ones is that with event sourcing Not only do you have the state of your application, but you have how that state came to be and why it is what it is and That helps for a number of reasons, but a lot of times it's just there to make to make auditing and compliance rules happy but In the demo I'll show some of the other reasons why having those is important So those of you who kept your hands up when I asked if your event sourcing attempts had been horrible dumps or fires a Lot of times when people build an outsourced applications They fail and I've been in this boat before where I've blamed event sourcing for the failure So when we do event sourced applications, we have to do a little bit more up-front work It requires more design We have to model the flows through the system rather than just the data that we read and write a Lot of times for very small applications event sourcing is way too much. It's overkill and it ends up Taking too much time to maintain so people throw it out and like I said There is a pretty big penalty for doing it wrong you can get all the way to production and have your event sourced system fail in completely unexpected yet horrible ways and Another one is that event sourcing is just not the default way people build applications. So usually you have to have teams ramp up on how to build it and You know how to follow the right patterns So first primitive Lego block that I mentioned is an aggregate aggregates in an event sourced system they take commands and Convert them into events. So in other words a Command will ask the system to do something and when the aggregate validates the command it emits an event saying this this actually occurred aggregates have their own state and part of the one of the many reasons Where we fail is? aggregates are purely functional. They must not have side effects and they cannot do work and Probably the number one failure I see with event sourced apps is aggregates that commit side effects projectors are designed to build the read model for your application in an event sourced app You know rather than the consumer of your app making a query and your code doing some kind of a join on a database With an event sourced system you can generally anticipate What data your customers are going to need and what shape that's going to take? So rather than building that ad hoc when they query an event sourced system will build that when the data changes So every time an event comes through Projector will take that event and create a read model and I'll show some of that in in the demo You can choose whatever you want to do for storage Because these projectors are also Wasm cloud components you have access to all the capabilities that Regular actors do so you can use key value stores SQL database. There's Access to blob stores and so on You can regenerate your projections on demand This is another thing that kind of scares people is that you can completely blow away all of your application state and No harm done you just run through the events again and regenerate your app state and that's actually I don't have enough time to demo that but that's how you actually migrate schemas Projectors are stateless with an asterisk in that the projector doesn't maintain state all it does is build the read model Which is external state? Process managers some of you may have heard the term saga before process managers essentially the strict opinionated event sourced version of a saga and their job is essentially the opposite of an aggregate they take Events and convert them into commands so They monitor when things Take place and then if something else needs to happen as a result the process manager kicks that off through a command and the reason that I've got the dominoes here is that typically what you see in production for Any large event sourced application is one command may go through and then any number of process managers Will kick off and you'll just see a massive stream pun intended of Events that happen as a result and I'll show some of this in the demo, but It's a little scary because people Aren't used to having things happen unattended that way gateways I'm not sure if gateway is an official term or if that's just what I call them But you need to have IO somehow in an event sourced system if your aggregates can't do work your projectors can't do work the and your process managers can't have state then you need Dedicated primitives that are designed to Deal with IO as a side effect in a way that doesn't actually pollute your event stream and that's a whole It's a whole separate time. It could be a whole separate talk. So the sample that I'm going to walk through is Well event sourcing is a little hard to do in hello world because it's inherently more complex than that So one of the simpler apps that you can do an event sourcing is banking. So we have an account aggregate and Like I said, they take commands So you'll see commands like create account deposit funds reserve release and so on The aggregate then emits The past tense version of those commands now there isn't always a one-to-one correlation, but It's it's pretty common. So we get account created funds deposited things like that The domain doesn't really matter too much It's just a domain. It's simple enough for me to be able to demo some of this and Then the process manager in response to a number of events will kick off more commands Which could then produce more events and so on hence the domino analogy Is anybody familiar with cloud events? All right, so cloud events there's a booth for them out there It's a CNCF project that defines a standard envelope for event data and so Concordance uses that so Part of the problem with a number of event sourced systems is the events themselves aren't You can't reflect over them. They're not introspectable. So by having them as simple JSON payloads It's easy for both humans and machines to read them the big The important point bit here is you can see the type of the event which is used for event dispatch and so this is a simple command handler in the aggregate and Similar to the pattern that we saw with the web server that takes a request and returns a response This function withdraw funds takes a command and returns a list of events So it takes the withdrawal funds command and Returns a funds withdrawn event and there's some business logic in here to make sure that I can't withdraw beyond my available balance, but What's missing here? And that's a good thing is I don't see Any information about how these messages are dispatched. I don't I'm not explicitly publishing events I'm not publishing commands. I'm not communicating with a state store All of that is taken care of for me by the concordance capability provider So that I can write simple unit testable functions that take predictable input and produce a predictable output The same goes for applying events to an aggregate When you apply an event you the event goes into the aggregate and it uses that to mutate its own internal state so here we take the funds withdrawn event and Couldn't be simpler we subtract the event amount from the current balance and that's it There's this thing doesn't know about read models doesn't care about them Doesn't have any code to talk to Kafka or event buses or anything else it's just a function that we can test and Has anybody familiar with wit and the component model? All right one or two hands this I mentioned that this is where dragons are because This is super early and very volatile right now the both the wit spec and the support for component model in wasm time is Changing rapidly, but the reason why I wanted to show this slide is That in the near impending future We'll be able to define your entire event sourced model in terms of Hopefully that doesn't mean I'm running late on time, but you'll be able to define your model in terms of this simple interface contract and Code generation will take care of everything for you All right So I showed at the bottom you've got web assembly runtimes Wasm time whammer there's probably a half a dozen fairly common web assembly runtimes That's gray because we don't care That's just something that's taken care of for us wasm cloud is the Distributed computing framework that sits on top of web assembly Yeah, I must be running late Concordance sits on top of that and the code that you write is just on top of that so Let's see if I can get through the actual demo here All right, let me just show you what I'm gonna do here So this is gonna send four commands Into the event sourcing system. I'm gonna create an account gonna make two deposits and then make one withdrawal and What we should see on the other end of this is for permanently persisted events Plus some projected state so assuming the demo gods are with me So that was super fast. That's intentional Kind of why we built wasm cloud the these go through command dispatch and if I View the event stream and now you see why I wanted to use cloud events so that I can do stuff like this you'll see that I've got an account created events funds deposited funds deposited and funds withdrawn and if I go into redis and If I can actually type So I've got a read model where I can query my current balance Which is $60 and then I Can pull the ledger the entire ledger history out as a read model as well so This essentially makes it seem this is building a read model so that I can have my Application consumers just get the data without any computation cost. It's a big O of one cost Sorry, I had to run through that So key takeaways here We should be writing features not plumbing if you find yourself writing plumbing There there is a better way Web assembly is the enabling technology that'll get you there But like docker and kubernetes before it web assembly is not the end goal It's the tool you want to use to get where you're going You should try out building distributed applications on wasm cloud Wasm cloud has a bunch of connectors including one the kubernetes that lets you talk to your legacy applications and You can build event-sourced applications on top of wasm cloud via concordance and Here we go all right, so Hopefully I have enough time for questions. I don't see the I'm out of time sign so Let's see if we can do some Q&A here