4

Using WebAssembly For Production Applications Now (It’s Easier Than You Think!)

 1 year ago
source link: https://devm.io/javascript/webassemby-production-apps
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using WebAssembly For Production Applications Now (It’s Easier Than You Think!)

WebAssembly (Wasm) isn’t just a demo technology, it’s capable of what we expect from production applications today. This article will cover the strengths of Wasm using wasmCloud (the CNCF sandbox application runtime) across bare metal, VMs, edge devices and more.

We did a demo on this subject at Scale 20x in Pasadena recently - take a look below and follow along with our demo.

6.29.00 https://www.youtube.com/watch?v=qL6X7iM_M2Q

Wasm...huh...what is it good for? Quite a lot, actually!

Firstly, for those that are new to server-side WebAssembly (Wasm), the term ‘WebAssembly’ is a bit misleading as it’s neither web-specific nor does it require knowledge of an assembly language. Wasm itself has an undeserved reputation for leaving real-world applications just out of reach and it has come a long way in the server-side ecosystem. It’s small, secure-by-default, fast, polyglot, completely open and highly portable. In an increasingly distributed world, this is what we want all modern applications to be.

We’re starting to become familiar with Wasm as a platform-agnostic bytecode that produces tiny binaries that run at near-native speed. The benefit of a platform-agnostic technology is that it works just as well outside of containers as it does inside containers, so it can be used for completely greenfield projects or integrate right alongside current container-based projects. It’s also great in compute-constrained places on edge devices.

Note: When we say “Wasm Bad” here, we mostly mean “Wasm not quite good at yet.” Most of these criticisms are due to the fact that Wasm has been a developing server-side technology for only a few years, and we are continually updating this list as the rough edges are smoothed out. Noting these should give you an idea of what applications may not be right for Wasm.

Wasm Good Wasm Bad
Server-side compute - microservices & functions Networking remains a challenge
Runtime optimization Evolving quickly, breaking changes often
The edge (constrained devices) Slower than native code
Plugins Toolchains still needed - no lift and shift yet
Library Not right for some domains:
Browser - performance-tuned apps
- nginx, Redis, mySQL

Why wasmCloud?

For developers wanting to get started with WebAssembly to build applications, wasmCloud is a CNCF sandbox application runtime built for low-boilerplate, secure, highly distributed applications using Wasm. Just like JavaScript, developers don’t break out raw HTML/CSS/JS for large projects, and instead choose a higher level application framework like React/Vue; server-side developers looking to try Wasm will want to avoid the lower level primitives of engines, importing and exporting numeric functions, memory management, etc. wasmCloud, like any application framework, makes opinionated choices and provides SDKs to simplify development and create applications that are smaller, more portable, and secure by default.

wasmCloud is a great way to get started with Wasm, and looking forward the interfaces used to work with cloud-native capabilities will be integrated with WebAssembly standards.

What makes an application “production ready”?

We hear the phrase “production ready” describing aspects of a technology that make it stable, resilient, scalable, etc. Typically these inspire developers to build applications and functionality with that technology knowing that it can run in a cloud environment and not fall over when faced with actual user traffic. This means running in a high-availability architecture over multiple availability zones or regions, scale to handle a massive amount of requests without crashing, and provide comprehensive failover mechanisms in the inevitable case of an outage. This is exactly where wasmCloud brings Wasm to production, and in the talk I show how you can take advantage of this from a simple microservice to a complex application.

At Cosmonic, we built our event-sourced backend using wasmCloud actors, and make use of plenty of production capabilities like Hashicorp Vault, NATS messaging, and SQL-DB Postgres. We also scale multiple copies of each service on different machines, just in case there’s an outage or failure in our cloud. You can see more about this in a talk I did with Taylor last KubeCon: Who Knew Dogfood Could Taste This Good? A WebAssembly In Production Story.

Run a simple microservice from cloud to edge

In our first demo, we start with a simple microservice. In this case, we showed one of our favorite wasmCloud examples, KV Counter, which is a tiny microservice that simply receives HTTP requests and updates a counter with persistent data. Looking at the application running in Cosmonic, we can see the single KV Counter Wasm module, an HTTP server and Redis key-value store, all running locally on my laptop in the conference hall.

Fig. 1

If I hit the localhost endpoint, I can actually see this nice little fun UI, increment the counter, and I get the new number (along with some fireworks!🎆)

Fig. 2

The great thing is I don’t need to choose an implementation of a database or worry about how to receive this HTTP request. With wasmCloud, my application doesn’t contain any of that boilerplate and can be handled by the capability or runtime. Take a look at the code to see for yourself.

What does it look like to get this application running in a production-style environment? Firstly, we have to hit this WebAssembly module from a publicly accessible endpoint. We can drag another link from the HTTP server to the Cosmonic hosted HTTP server which creates a public DNS endpoint.

Fig. 3

We then create a wormhole (or ingress point) into this application to make it live. So far, so cool but, as you’ll see in the demo, running on a laptop isn’t the most extensible example of this running in the wild.

This is where it gets interesting. What if we could run this application in multiple environments? In wasmCloud, I can copy my application multiple times to run in different places. In this instance, we can see it running on an ARM Linux device, we can then decouple the application from the Redis server and connect it to a public cloud.

Fig. 4

I was just able to take this little app, running on my local machine with all local assets, and flexibly swap it to run in a cloud environment. No reprogramming, no refactoring - the same application, running anywhere. This is why we call Wasm with wasmCloud a production-ready technology, because not only can it handle real production use cases, it can do so in a way that’s cheaper, more flexible, and easier to work with than many cloud-native technologies today.

The next stage, then, is to create true interoperability between platforms - we don't want a walled garden. This is the work currently being done by the W3C and the Bytecode Alliance, to forge industry-wide standards for beyond-browser Wasm. Click into the demo at 6.58.00 to hear Taylor’s download on the status of the Component Model and read Bailey’s excellent article on InfoWorld on the community effort involved in finalizing WASI (server-side) Wasm standards.

Getting Started

Ready to dive in?

  • Join the Bytecode Alliance, a community of developers and engineers who share ideas, learn and get hands-on with WebAssembly. Connect on Zulip here.
  • Check out wasmCloud, the popular CNCF project, and run through the getting started guide. This will let you get hands-on with WebAssembly.
  • Join the wasmCloud Community call each week at 1pm ET on YouTube, Twitter, and LinkedIn.
  • Sign up for Cosmonic and run through the Quickstart. Cosmonic is a PaaS built on wasmCloud which provides a host of managed services for your Wasm deployments and is free to all developers.
  • Get in touch with me on Discord.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK