 All right. Hello everyone. Welcome to delivering back-ends like front-ends with WebAssembly My name is Brooks Townsend. I'm a lead software engineer at Cosmonic And I've been a CNCF wasm cloud maintainer since 2019 even before it was called wasm cloud So I've been doing web assembly stuff on the back end for quite a few years now Serial open-source contributor. I love working with web assembly Especially anything that has to do with rust and I'm a demo enthusiast Of course as you'll get to see today So taking a look at what we're going to talk about I want to go a little bit in the back end of like what is a CDN like why people use them at all Transfer that knowledge into network optimization for back-end applications Diagrams do some demos do some more demos looks more diagrams all like all that good good stuff Try not to bore you too much in the post lunch hour And then really get into like what is all of this really good for and where are we going to go next with some kind of technology like this? So to start I found this really awesome blog to define What is a content delivery network which I trust cloudflare with this kind of stuff at its core? A CDN is a network of servers linked together with the goal of delivering content as quickly cheaply Reliably and securely as possible in this blog It talks about how a CDN is a distributed network of edge nodes That's caching static front-end content as close to the user as possible But it does specifically call out that this isn't a replacement for web hosting in general You still have to have some server somewhere that your assets are coming from that you're running your back end Ultimately the data for your application has to live somewhere Now why do people use CDNs? First of all, they want their application to be quick and they don't want to spend a lot of money on egress costs These are two of the biggest things that people use CDNs for and if you haven't used them explicitly on your own You can compile your static assets and then package them in a CDN and essentially what it looks like Sorry for all the people who want to see the memes. There's more. There's more I promise this is kind of like a high-level architecture diagram of what happens when you're using a CDN You've got your back end somewhere. Well, we'll call it like u.s. West Where it's you know, you go your node.js your rust whatever your your back end and the hosting platform for your application is running in some central place when a user makes a request to your Website whatever application you have then say they're in Europe That's gonna take a decent bit even just for the static assets of your application to transfer all the way from your server In the u.s. Over to Europe, you know, it's not gonna be anything huge It'll probably be less than a second or two, but with the CDN They these platforms will offer these little edge nodes that you'll essentially pull through that place And then the static assets for anyone else say you're in Europe who makes a request to your website We'll then pull from the edge node itself Really minimizing the amount of data and the distance that it has to travel on a network and that makes things load faster And it makes things cheaper. You're not paying for egress costs from the cloud like where your server is and that's great Like from a front-end perspective like that's Perfect. My users are happier. They app developers spending less money and it kind of begs the question the the very Nuance question like why can't I just distribute my back end everywhere? Like what if I could just run the actual hosting part of my server on all of these different edge nodes and like What if I could cash that close to the user and I'll need to care about like the deployment target There's just a little static file like whatever. I don't need to know what platform. It's going on So can we do this with back-end compute? Nope Thanks, everyone. I'm happy to answer any questions. I got like 30 minutes left. So a little time. Oh, thank you Thank you. All right, seriously the the answer is of course that it's way more complicated than that Deploying back ends we have so many different if you look at all the talks here at kube-con We're talking about a platform to for deploying container-based services like there's whole conferences for this stuff. It's hard It's complicated and if it was easy, of course, everybody would be doing it And the reality is that you can deploy your application to a bunch of different geolocated servers and Design it specifically so that it's close to a couple of different users And so the request hits that edge node instead of a central cluster and all of that But this probably means that you're not using Kubernetes and you probably built your application to be like this from the beginning Which involves a ton of complexity and the specific call out here around Kubernetes is Running different clusters of Kubernetes in different regions different clouds across a disparate number of edge nodes That could be added or removed at any time is At least prohibitively expensive if not impossible to do let me know if you've done something like this with Kubernetes But I want to take a little bit of a step back and talk about why I'm even here talking to you today The the goal like what I work on on my day-to-day and why I've been working on cause monitor on Wasm cloud for so long is I want to be able to optimize these applications from a networking perspective To reduce the amount of data and the distance that it has to travel on a network So many different applications that we have and of course There's always exceptions are bounded by the amount of time that it takes for packets to go from point A to point B You know from the user to the server you can you know You can argue about it like whether or not a go or rust back in could serve a hundred thousand requests on a local Hostin point you know but at the end of the day the vast majority of the time that it takes for an application to Give you a response to your request It's just the time that it takes to get from that point And so what I want for back ends and what I want to continue this talk with is I want to be able to take my back end like any Platform agnostic front-end static asset and deploy it everywhere and get that type of network optimization So the two main domains that I want to focus on for this talk There's infinitely more but just to simplify it are the kind of hobby application something that I write in my free time It's providing a fun little web application Or something for my business. That's not necessarily Performance critical the key point is that it's not necessary. It doesn't need to be distributed for the use case of the application I just want to distribute it so that it can be close to the user and that it can be optimized that way the other domain is the They very vaguely calling it the industry application But this is something that has hard requirements for heterogeneous environments where it's really difficult to deploy an application like this with Kubernetes and so people end up needing to design it From the ground up running it on their own like really managing this manually And it doesn't fit in a cloud native ecosystem when I really think that it could and it should and to do this I'm going to use wasm cloud Wasm cloud is a CNCF sandbox, but hopefully soon to be incubating we put in that application Just a few weeks ago as application runtime in the CNCF Which is a web assembly orchestrator with declarative deployments It's just a single binary so you can run it on Linux Mac and Windows. We package it in a container We publish a helm chart And really the the core goal of the platform is for developers to be able to focus on writing their application Their business logic the thing that they actually want to write and not worry about all these platforms specific Essentially implementation details or things that just take down your productivity and drain What you really enjoy doing which is like just coding you writing your application So we try to abstract things as part of the platform as much as possible And that includes an application capability model So instead of working with direct SDKs for things like HTTP servers Key value stores message brokers databases distributed logging all that stuff Those are all abstract interfaces that you can fill in the implementation at runtime We also use the CNCF project gnats for all of our networking and RPC Under the hood. It's actually transparent to the user But what this means is that I can run my application all on my machine Or I could run it in a multicloud multi-region environment All of those application components can talk to each other the exact same as if they're running on the same local machine And that includes load balancing Automatic failover in terms of in case of an outage a really nice abstraction for people who are writing applications get down to your business logic and then everything else is taken care of as part of the platform And I say like I said wasm cloud. I've been working on it since about 2019 But it is a cloud native technology. We use OCI for distributing all of our artifacts You can just push web assembly to OCI repositories. I don't know if you knew that it's pretty cool We use the open application model for our declarative manifest, which is an open standard Cloud events for all of our events that we publish in the system and we support open telemetry tracing So this is this is all really just to say that this integrates really really well into a cloud native context We're not trying to reinvent the wheel with what we're doing Except with this one little thing called web assembly our unit of compute in wasm cloud is not a container We don't execute containers Wasm cloud actually would best fit running inside of a container as far as the platform But this web assembly thing how many of you show of hands have heard of web assembly before just keep them up for a second That's wild this number keeps getting okay, so I talked about web assembly at cube con in 2019 in San Diego I don't know how many of you went to that one. That was my first conference I was talking about this and I think the number of people at that conference who had heard of web assembly was like Three and two of them were me and my colleague who were there talking about it So it's pretty cool to see that how many people have actually Built and run something at least hello world style on web assembly on the back end Or fun and whatever it doesn't matter cool So web assembly if you haven't heard of it or haven't run it I'll kind of go through a high level of the technology. It's an open standard developed by the w3c They say it's the fourth language of the web Which it really is it's supported in all major browsers And it can also because it doesn't depend on a specific platform or architecture run very well on the back end It's essentially a portable compilation target So a language that has a web assembly Compilation support things like rust go see Dotnet JavaScript Python Ruby like it the the language list continues to grow and grow instead of compiling to a native binary You compile to web assembly and again execute on a web assembly runtime the web assembly runtime is essentially like a virtual machine it features a Essentially denied by default sandbox security model So everything is denied from the beginning you have to ask for All the capabilities like if you're gonna read a file you have to ask the host run time You're allowed to do it if you're gonna make a network request you have to ask if you're allowed to do it It's a great and actually as an application developer not a pain model to work with it runs a near native speed and Really the thing that you need to take away from this is that it's just a different unit of compute and we're using web assembly to Essentially make the developers life better It's really nice because it is just a static asset to compile to this compilation target You can distribute it and you don't have to worry about what platform you're gonna run it on Now let's start with the hobby application I cannot for the life of me find this gift So if you know about it, please tell me it was on reddit at some point like a three-minute gift of A Seinfeld clip that was you know like when they put the fake subtitles over it And that's like what they're saying is saying like I need my fruit jokes application to be deploying to all these different Kubernetes edge nodes it needs to serve a request in under three milliseconds It's like Kramer you're running a fruit jokes application. It's gonna be fine. So that's what I built It's a nice little hobby application and to look at the architecture of this in terms of a wasm cloud application I mentioned that we abstract away the capability driven application capability model And so it's a little it's a little blown up here But the actual fruit jokes component here is my web assembly component I wrote it in rust and it's just in pure business logic So the HTTP server and the key value store that I'm using to store and access my fruit jokes in the end Or something that I get to pick at runtime, which is really nice I'm just working with an abstraction and I don't need to worry about the actual implementation that's not compiled into my application and With this we're running all these application components in a wasm cloud runtime And if we wanted to distribute this application, you know, my goal thinking about this You know kind of like a CDN is there are people who are gonna want to access and laugh at and enjoy Fruit jokes all over the globe at all times and I want people to do that as fast as possible Because the wasm cloud runtime it can run on a variety of different targets And it doesn't have to run in a specific environment We can distribute that across a bunch of different edge nodes and that's all kind of interconnected with NAS We're gonna do that using a project that is part of the wasm cloud organization called wadam. I love this logo It's pretty cool. It's the wasm cloud application deployment manager. All you really need to know for this talk I won't I won't do a deep dive here, but there was a talk on Monday at the web assembly The web assembly co-located event all about our engineering effort on this but all you need to know really is that we're using YAML like everything else and you can pull the Aptual application component out of an OCI registry and then use this concept of a daemon scalar Which is like a Kubernetes daemon set to essentially distribute this piece this application component across every available Node in your wasm cloud network, which is all connected with NAS So let's take a look at it real quick I'm gonna start by showing you the available pieces of compute in my wasm cloud network And that just means that they're connected together with a NAS server I have one node. I have one VM that's running in Azure in south-central US. I have one that's running in Actually on my local MacBook here in the conference and then I have one that's running in AWS Which is in the US East to region. So I've added a couple of different, you know, essentially Region-based or location-based nodes to run this application on and if you take a look at each one You can see that it's running this fruit jokes actor or this web assembly component So let's take a look at what it looks like if I generate a fruit joke here Let's do a cool one. Why did the apple stop in the middle of the road? Because it ran out of juice. I heard one chuckle and like 14 groans. So I'm gonna do another one Some of these I've actually looked at and they're like, they're not that great What fruit is never alone? a pair Okay, slightly more chuckle to grown ratio. So I'm gonna call myself. I'm gonna stop on the head there, right? So this is this is like a you know, it's something done that you would whip up for fun It's a hobby application and the whole idea here is that web assembly being a platforming Gnostic target I get to distribute it this around as many different edge nodes as possible Us being here in the conference like this node That's running on my local machine is accessible publicly But being able to route to this means that people who are accessing this website from this conference are getting the fastest Load time is possible because I've got this edge node running right here and that's kind of the the the great application of like running a Running this back-end type app like a CDN Here at at this conference So you may be thinking to yourself like yeah, that was cool. That was a little demo app Right, and it kind of seems like something that could be surged served by any one of these cloud providers that offer like a CDN Probably has something like an edge functions or or a phas where you write this little stateless Serverless function that can serve you a fruit joke and then you call it a day like they deal with distributing it around They've got the whole edge node or whatever. So can you just do that? Yep You probably should too. This is really cool to kind of architect with web assembly and do with this From the developer perspective it really the the the point or being able to do this with this type of application You kind of can with like this serverless edge function type of thing But it doesn't really work for something that's highly distributed or actually has the requirements of running Across these different nodes and not just kind of replicated across as many nodes as possible And so I want to talk about I want to focus on the rest of the talk on this idea of an industry application Taking the jump with any technology from like a little demo, you know, your hello world to a real-world use case everything gets Exponentially more complicated as you do that. And so I made this inventory management application I came up with some hard requirements, right? These these things that you may need to do for a real inventory application that aren't really easy to do when you're architecting in like a Modern cloud native way depending on what you do Here's the requirements there needs to be a central server maybe in the cloud maybe running somewhere For administration, right? The the whole thing here and I did a nice little Photoshop here We're gonna be working on Managing the inventory for this paper company So there's a bunch of different branches that are running across the United States or maybe Europe or whatever But there's a central server for corporate for to be able to know the inventory of all of the different Branches so they want to know what's going on, but we're actually going to be doing deployments on premises in the office location So there's going to be a server in the office that you're going to be running this application on Really hard requirement the branches need to be able to operate even if the central network is offline If you're running a paper company and you're getting calls for orders And you're getting shipments and from the loading dock that needs to operate even if your Wi-Fi is having a bad day And you're not able to connect to the corporate network New branches need to be able to add it to the system be added to the system at any time And they need to be able to close at any time, you know limitless paper in a paperless world and things happen So looking at the looking at how we're going to do this This is where wasm cloud really starts to shine this distributed kind of complex Requirement use case the ability to distribute across these different nodes and have everything seamlessly talked to each other Is if it's on one machine really lets us create an architecture for this complicated set of Requirements So this is the full architecture for this application, and I'm going to go through it piece by piece so in terms of the The the central server for administration the corporate dashboard some company executive This is you know kind of the high-level application diagram Some company executives going to hit some internal HTTP server with a website, and they're going to want to say hey How is all my how are all my branches doing give me a rundown on your inventory? And then we can persist that in a highly replicated data store like Nats Jetstream, right? So we have our kind of I think it's actually pretty fair to deploy something like that in the cloud and then we have our individual Branches and that application deployment the the piece of application that we need to deploy everywhere is a central management for you know essentially a branch manager to Process incoming shipments incoming orders for different types of items and then store them in a database that's co-located at the actual branch itself and Because we're using Nats. This is actually an aspect that we kind of get for free with Nats All of the traffic here that's running on the branch will stay local as long as the Interested party is is local so everything can continue to operate locally here as the the branch manager can work So even if you lose connection to a central cluster you can still process those things Now another key requirement was that you know we may start with one branch But we're gonna add more and more over time, you know paper businesses booming We're opening new branches and so all we need to do is spin up another branch Wasm cloud runtime and then we can deploy everything onto that and again We're gonna do that with the concept of a daemon scaler like a daemon set So anytime a new branch pops up in our system. We're gonna deploy the entire Branched part of the application there and then we're gonna be ready to go So let's go ahead and take a look at what that looks like. I didn't actually deploy this one yet So let's go ahead and do that now so I've got my Munder-difflin application here if we wanted to actually look at the YAML Sorry, if this is gonna make your eyes bleed you can do JSON if you want to right everybody likes alternatives We've got all of our different components laid out here Using the daemon scaler and all of the relationships and configuration and things like that So if we deploy this application and we go to take a look at our infrastructure that we have running We can now see that our Branch that's it's it's running in azure You know I'm doing in the cloud because I don't have access to like a real paper thing is now running our branch manager as well as our fruit jokes and An HTTP server our redis database our Nats messaging for for Passing messaging back and forth messages back and forth things like that Now if we look at the actual branch Where's my keyboard? If we look at the actual application So we'll take it how this is all Let's take a look at how this is all kind of distributed Give me a second We can take a look at the corporate dashboard and see what we kind of have currently in our system So you can see by both of the applications that I created today That I'm very proud of my front-end ability to make something rotate and CSS everything's gonna rotate Don't worry about it. The way that this works is we can you know I'm the person at corporate I can request a rundown of the pieces of our inventory And then I can query that from the essentially central cluster So I've got one branch running in Austin and one running in McCormick that one is running on my local machine So the way that this works if I wanted to act as the branch manager That branch is running but located on my laptop So I can get some shipments of paper say 30 pieces of paper You know another 35 pieces of paper things like that I can request a rundown and I can query the inventory and you can see that from the corporate perspective I've now gotten my 65 pieces of paper. So this is working as expected Now let's take a look at one of the other hard requirements is that branches need to be added need to be able to be added at any time So I'm gonna steal this real quick and I'm gonna go Directly SSHed into a nice little GCP GCP instance here and we're gonna launch this as our next branch And so this is just a single command we use the wasm cloud CLI to launch a NATS server and a Wasm cloud runtime on this branch and if you take a look things are happening very quickly if we take a look at our Available infrastructure here. We now have this run time. That's running in GCP in US West And it is running on an x86 architecture like calling all this out But the cool thing is that you never needed to worry about the architecture or the deployment target anyways You can see that that's automatically loaded up all of our application components because of the declarative application They're saying hey spread it across all available branches and then now on this machine I can do things like receive shipments of paper or we can even This cloud things work Can I really not go back on this? Okay, I'm gonna handcraft this one to be fun We can get a nice little order where the item type is paper and the quantity is 10 Sweet so we got 70 paper into our inventory and then we remove 10 We take a look at the corporate dashboard We can request a rundown and query and we can see that the Seattle branch has now popped up with 60 pieces of paper whoa, so we've been able to You know essentially validate the requirement to be able to add branches at any time Now the really important thing here is that you saw me with my local machine be able to process Inventory queries a key requirement is that this needed to be able to work without a network connection to the central cluster So if I go ahead and turn off my Wi-Fi on my laptop I'm gonna bring this up for later Now I'm not connected to the central cluster at all anymore So this branch has effectively gone offline You can imagine they're having some kind of outage or they put the router on top of the microwave and they you know Whatever something happened at the branch the the Wi-Fi is no longer working But the people who are down in the warehouse are still getting shipments of paper and it still needs to work We need to add be able to add that to our inventory everything needs to be able to process offline Now I'm doing I'll do kind of a larger amount so that the amount is obvious Eventually they're gonna be able to resolve that issue We're gonna be able to turn the Wi-Fi back on the central the central corporate cluster is going to Understand that we've gone offline for a small period of time and then and come back up So you saw everything working locally when we get back to the actual inventory You can see that if we just try to query it the corporate dashboard the the corporate database hasn't caught up all the way But we can make a request to our Different or you can make a request back to this thing that's running on the local machine And we'll give it a second to fully like register interest again It hasn't actually fully reconnected yet. We'll give it a second with all the Wi-Fi I'm actually running off of my hotspot. So I wonder if that's messing with everything here Okay, there we go Let's see we're working at the McCormick branch unless that number was already was that already included on the thing Hmm. I guess the demo gods aren't with us today. That is unfortunate Well here. We'll give it a minute. I'll give you a little bit of the the post-amble and then we'll come back here And see what's going on So let's go ahead and move forward and talk about what is all of this good for like running with web assembly Running with wasm cloud what like what scenarios is great for it's really great for distributed data locations like running in these different edge nodes These different individual branches the heterogeneous environments that can be added to or moved at any time Any application that's network constrained like the vast majority of the time to process is the network request and Anything that you are interested in doing multi region or multi cloud deployments This is completely platform of Ender agnostic. So it's a really great application for spreading across multiple regions or clouds Things that don't necessarily work as well in wasm cloud You know things that have perfect support for but with web assembly on these little single component applications The web front-ends kind of like our fruit jokes. It works fine But can be better elsewhere and then for web assembly itself. It's an abstraction of a CPU You know, it's running with an instruction set. That's not OS or architecture specific So if you're doing Linux specific things like things that you're like you're inspecting syscalls to come out of a system You probably aren't gonna want to run it with an abstraction layer. It doesn't really make sense in terms of the the benefit of the technology And what does this all really mean? When you're running web assembly, you can run your applications anywhere platform and OS agnostic And when you run wasm cloud you can orchestrate those web assembly applications and that allows them to all talk to each other the same No matter how they're distributed across different clouds and edges even your local laptop Now what's next? I think I can improve this demo a little bit I think the we could use a management UI instead of curling in the terminal But it's always nice to you know, bring that back to reality We can move through jokes to the front end What I really love to see for this is deploying wasm on the device I would love to run this platforming nostic target in the browser like the technology can And I'd like to have kind of a more data first class caching solution So, you know, I'm clicking in the UI to kind of get updates on the system But I like to do that in a more and more first-class way You know what I'm kind of upset that this still let me check this out. There we go There it is. We got our got our nice little update. I knew that that knew that that would come through. Thank you so much Gotta be patient Gotta be patient So I love to you know, we got a couple minutes here But I really just want to leave these up on the on the screen I would love it if you were interested in the things today if you want to pop in our community slack If you have any questions, I'll answer some here and you can find me after the talk But that's where all the maintainers hang out. We like to have a good time We run weekly community meetings on Wednesday at 1 p.m. Eastern and then all of our code all the things that you saw here The capabilities are in our open source repo in github The whole wasm cloud organization including like the deployment manager and all that is there So it looks like I do have a couple more minutes. So any questions In your demo, I think you said in the branch you're running Redis. Like what is what is Redis running on? Like how does that work? Yeah, yeah, I'm running. So the the specific piece of the application Here so the the branch the the Redis that I'm running there There is an actual Redis server that's running just like on the virtual machine there like on gcp for example and this component here on the right side the Redis is the Implementation of the key value capability. So when I in my application, I have a couple gets and set ads and things But that's an abstract contract You'll notice actually on the the corporate dashboard. It uses the same abstraction to interact with NATS It's just at runtime. I get to pick what data store to use And so that Redis that's running on the branch is kind of like a connector to that to that database Other questions All right. Well, thank you. Thank you all so much I'm gonna be hanging out for a little bit after the talk and then eventually probably move into the hallway track But I really appreciate you coming out and listening to me do some some dumb fruit jokes and some cool demos today