📄 Page
1
M A N N I N G Danilo Chiarlone Foreword by Brendan Burns Afterword by Luke Wagner Building portable and secure multi-language apps
📄 Page
2
Source code Wasm components Composed Wasm components ml_lib.py my_apps.js ml_lib.wasm my_apps.wasm component.wasm build build Compiling a WebAssembly app Executing a WebAssembly app component.wasm Native OS Wasm runtime sandbox Filesystem Sockets Crypto WebAssembly System Interface granted Wasm is architecture independent, so this could be an x86_64, aarch64, or other machine. If this was a native executable, by default, it would be able to access any capabilities from the underlying native OS. component.wasm cannot access this capability! Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
3
Server-Side WebAssembly Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
4
Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
5
MANN I NG Shelter ISland Danilo Chiarlone Server-Side WebAssembly Building portable and secure multi-language apps Foreword by Brendan Burns Afterword by Luke Wagner Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
6
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com © 2026 Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid- free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. ∞ Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 ISBN 9781633436206 Printed in the United States of America The author and publisher have made every effort to ensure that the information in this book was correct at press time. The author and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein. Development editor: Connor O’Brien Technical editor: Adam S. Chalmers Review editor: Angelina LazukiÊ Production editor: Keri Hales Copy editor: Kari Lucke Proofreader: Katie Tennant Technical proofreader: C. Gerard Gallant Typesetter: Tamara ŠveliÊ SabljiÊ Cover designer: Marija Tudor Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
7
To my parents, Beatriz, my dear Nonna (1946–2021), Grumpy, and all my friends who supported this journey Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
8
vi brief contents Part 1 WebAssembly for architects .....................................1 1 ■ Introducing Wasm on the server 3 2 ■ Building server-side applications with Wasm modules 17 3 ■ Enhancing portability and security with Wasm components 33 4 ■ Interfacing Wasm with the underlying system 53 5 ■ From machine learning to databases: Applications of Wasm 84 Part 2 WebAssembly for developers ................................. 121 6 ■ Creating production-grade Wasm applications 123 7 ■ Introducing Wasm containers 167 8 ■ Scalability for Wasm with Kubernetes 189 9 ■ The future of Wasm 218 appendix A ■ Required tools 229 appendix B ■ Deploying the SmartCMS to Azure Kubernetes Service 233 Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
9
vii contents foreword xi preface xiii acknowledgments xv about this book xvii about the author xx about the cover illustration xxi Part 1 WebAssembly for architects .......................1 1 Introducing Wasm on the server 3 1.1 What is the server side and where does Wasm fit in? 5 1.2 The advantages of Wasm for server-side development 6 Language agnosticism 6 ■ Performance 8 ■ Hardware agnosticism 11 ■ Security 12 ■ Standards-based and vendor neutrality 12 1.3 When and where to use Wasm (and when not to) 13 1.4 How to navigate this book 15 2 Building server-side applications with Wasm modules 17 2.1 Understanding Wasm’s building blocks 18 2.2 Understanding the guest-host architecture of server-side Wasm 19 Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
10
viii contents 2.3 Creating a Wasm app using Rust 21 Creating a Rust library project 21 ■ Specifying compilation to a Wasm module 22 ■ Writing the code for our application 23 Compiling the Rust code into a Wasm module 25 ■ Executing the Wasm module with the custom host 26 ■ Reflecting on the “Hello, World” application 28 2.4 Building on Wasm’s simple types with WebAssembly Interface Types 28 2.5 Building the foundation of a smart content management system 30 3 Enhancing portability and security with Wasm components 33 3.1 Benefits of Wasm components 34 Cross-language portability 34 ■ Shared-nothing security 34 Only-what-you-need security and improved vulnerability mitigation response 37 3.2 Building a componentized “Hello, World” guest application with JavaScript 39 Setting up the project and installing the toolchain 39 Implementing the component logic 40 ■ Compiling the Wasm component 40 3.3 Building a Python host for a JavaScript-bundled Wasm component 41 Setting up the project and installing the toolchain 41 Implementing the host logic 41 ■ Running the Python host 42 3.4 Expanding the example project with Wasm components 43 Improving the WIT file for the key-value store 44 ■ Creating the SmartCMS host 45 ■ Implementing and running a guest Wasm component inside our SmartCMS host 50 4 Interfacing Wasm with the underlying system 53 4.1 The WebAssembly System Interface 55 4.2 What can you build with WASI? 61 Creating a CLI application 62 ■ Creating libraries 64 Creating HTTP proxies 65 4.3 Converting a Wasm module to a Wasm component 65 4.4 Managing component capabilities 68 4.5 Composing components together 71 Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
11
ixcontents 4.6 Expanding our example project with WASI and composability 76 5 From machine learning to databases: Applications of Wasm 84 5.1 WebAssembly Standard Interfaces 85 5.2 Machine learning with Wasm 86 Understanding ML inference 86 ■ Using wasi-nn 87 5.3 Running Wasm inside databases 97 Making Wasm UDFs 97 ■ Getting Wasm into SQL 101 Running Wasm UDFs in libSQL 103 5.4 Improving our example project with wasi-nn 105 Setting up our project 106 ■ Writing the ML Wasm component 109 ■ Updating our host to use ONNX for wasi:nn 115 Part 2 WebAssembly for developers .................. 121 6 Creating production-grade Wasm applications 123 6.1 Creating a wasmCloud “Hello, World” application 124 6.2 Adding persistent storage to our Wasm app 130 Modifying our WIT and wadm manifest 130 ■ Modifying our application and redeploying it 132 6.3 Scaling our wasmCloud application 135 6.4 Distributing our wasmCloud application 138 6.5 Another off-the-shelf host: Spin 142 Creating a Spin “Hello, World” application 142 ■ Comparing wasmCloud and Spin 146 6.6 Implementing the example project as a wasmCloud app 147 Adding persistent storage to the SmartCMS 150 ■ Adding machine learning to the SmartCMS 156 7 Introducing Wasm containers 167 7.1 Containers vs. Wasm 168 7.2 Wasm containers 170 7.3 Running a Wasm container 172 Setting up containerd and Wasm support 173 ■ Building and running the Wasm container 173 Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
12
x contents 7.4 Wasm and the OCI 175 Packaging and publishing Wasm components as OCI images 175 Inspecting Wasm component OCI images 176 ■ Pulling and running Wasm OCI images 178 7.5 wasmCloud and Wasm containers 179 7.6 Converting Linux containers to Wasm 183 Introducing container2wasm 183 ■ Installing container2wasm 184 ■ Using container2wasm 185 8 Scalability for Wasm with Kubernetes 189 8.1 Kubernetes and Wasm 190 8.2 Running Wasm in Kubernetes with SpinKube 192 Preparing the cluster for SpinKube 193 ■ Running a Wasm app in Kubernetes with SpinKube 197 ■ Scaling Wasm in Kubernetes with SpinKube 199 8.3 Running Wasm in Kubernetes with wasmCloud 205 Preparing the cluster for wasmCloud 206 ■ Running a Wasm app in Kubernetes with wasmCloud 207 8.4 Running the SmartCMS example on Kubernetes 212 Preparing the SmartCMS image and manifest 212 Preparing the Ollama dependency 214 ■ Running the app 215 9 The future of Wasm 218 9.1 SmartCMS closing remarks 219 9.2 What’s next for Wasm? 220 Confidential computing 220 ■ AI and machine learning 223 Compute at the edge 224 9.3 What’s next for WASI? 226 9.4 Staying in the loop 227 appendix A Required tools 229 appendix B Deploying the SmartCMS to Azure Kubernetes Service 233 afterword 239 index 241 Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
13
xi foreword Welcome! I’m excited to have the opportunity to introduce you to Server-Side Web- Assembly. It goes without saying that the development of web and browser technologies has had a foundational role in shaping the modern internet. Even today, as advance- ments like mobile and AI have reshaped how we think about interacting with internet services, the core technologies of the web, like HTTP and REST, are at the heart of these advancements. In this book, you will learn how WebAssembly, which started as a component on the client side for the browser, has turned into server-side technology for service development. I’m old enough to remember a time before browsers came with programming languages built in. Early in the development of the web, it became clear that adding dynamic elements to web pages was a critical part of the browser’s evolution from a static content renderer to an application platform. The development of JavaScript and HTML5 changed the browser from a static content renderer to a dynamic application platform. Over time, however, the limitations of JavaScript as a programming language became apparent. A variety of concerns, ranging from the need for other programming languages to the desire to share code between client and server, led to the develop- ment of WebAssembly (Wasm) as a foundation for multilanguage code execution in the browser. Much like the Java virtual machine bytecode or the common language runtime, Wasm is a virtual assembly language that can be used as a target for compilers. With Wasm added to browsers, developers could build dynamic web applications in languages from C to Python. At the same time as the seeds of Wasm were being sown in the browser, a separate development was occurring on the server. The V8 JavaScript runtime that powered the Chromium open source browser was taken and transformed into the Node.js platform Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
14
xii foreword for server development in JavaScript. The motivations behind the development of Node.js mirror the things that drove the development of Wasm—particularly, the desire for portability of code between client and server. Instead of developing a new assembly language for the browser, Node.js took the core JavaScript engine out of the browser and made it available on the server. JavaScript (and, more recently, TypeScript) devel- opers could use the same languages and libraries in both places. With this history in mind, the development of Wasm on the server is a similar migra- tion from client-side browsers to server-side execution. But if you examine the multilan- guage value of Wasm to the browser, you might be confused about why there was interest in Wasm on the server. After all, even without Wasm, you still can program servers in a language like C++ and then execute that same code on the browser via Wasm. The moti- vations for WebAssembly on the server actually come from two additional requirements for browser-based Wasm, particularly security sandboxes and lightweight components. It should be obvious that code running in the browser must be considered untrusted and therefore must also be isolated (or sandboxed) to protect your computer against code on the internet. Core principles in the design of Wasm, namely, linear memory and a capability-based security model, significantly improve the security profile of code running in the browser. The same value is present on the server in the context of host- ing multitenant code. Consider an application like a game that enables user-generated content to add items or other characters. This third-party code for extending the game is inherently untrusted, and thus we need to isolate it from the rest of the code in the game server. Just like in the browser, the Wasm security model is a fantastic way to imple- ment plugins for untrusted code on the server. The other value of Wasm is small, lightweight components. Because web pages and Wasm are downloaded across the network, the smaller the size of the component, the more responsive the web page and the better the user experience. This same value of small modules applies on the server side as well, especially in the context of things like function-as-a-service, where code is dynamically spun up and down in response to user requests. Wasm can provide an order of magnitude (or more) of a speed-up in terms of starting dynamic code in response to user requests when compared with traditional process execution. This also has significant benefits for server developers. I hope that this brief history of how web technologies have shaped the internet gives you context and motivation to learn how you can harness the power of Wasm in your server-side applications to power the next generation of the internet! —Brendan Burns Co-creator of Kubernetes and Corporate Vice President of Azure Cloud Native Open Source at Microsoft Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
15
xiii preface My experience with WebAssembly (Wasm) started with server-side applications rather than browser-based ones. While Wasm was initially created for web performance, I focused on its applications in cloud computing. I worked on SpiderLightning—a collection of WebAssembly Interface Types definitions that simplified application development by abstracting away environmental complexities. This work evolved into wasi-cloud-core, a set of cloud interaction interfaces that’s now part of the WASI stan- dards, where I contribute as a champion. The idea for this book emerged from one of my talks at WasmCon, where Manning editor Jonathan Gennick approached me about writing a comprehensive guide to server- side Wasm. The timing felt right—Wasm was gaining significant traction beyond the browser, but documentation and learning resources remained scarce. While AI top- ics dominate technical conferences, Wasm actually rated higher than AI in engagement at KubeCon EU 2024 in Paris, highlighting the community’s hunger for knowledge in this space. Currently, I work on Hyperlight, which, through its sister project Hyperlight-Wasm, enables Wasm adoption in public clouds like Azure by providing hardware-based iso- lation for multi-tenant workloads. This work has exposed me to different perspectives on where Wasm might fit in the server-side landscape, particularly in isolation-critical environments. What excites me most about Wasm is its promise of true portability and security without sacrificing performance. The ability to compile code from multiple languages into a secure, sandboxed format that runs consistently across different environments represents a fundamental shift in how we think about server-side development. Wasm Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
16
xiv preface enables us to break free from vendor lock-in, reduce cold start times in serverless envi- ronments, and deploy the same code from cloud to edge with confidence. This book reflects my belief that Wasm’s server-side capabilities deserve to be more accessible to developers. Throughout these pages, you’ll not only learn the technical details of working with Wasm modules and components but also gain practical experi- ence building real applications. By switching between languages like Rust, JavaScript, and Python in our examples, I hope to demonstrate Wasm’s true language-agnostic nature and help you see how it can fit into your existing development workflow. I hope this book helps make Wasm technology more approachable and encourages more developers to experiment with its capabilities. The future of server-side comput- ing is being written now, and Wasm is playing a crucial role in that story. Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
17
xv acknowledgments Writing this book has been an incredible journey that wouldn’t have been possible without the support, guidance, and patience of many people. First and foremost, I want to thank my girlfriend, Beatriz. You’ve been my rock throughout this intensive writing process, taking over household responsibilities with- out complaint, showing endless understanding when I had to work through weekends and vacations, and always believing in me even when deadlines felt impossible. Your support means everything to me. I owe immense gratitude to my editorial team at Manning. Connor O’Brien, devel- opment editor: thank you for your exceptional guidance throughout this project, your patience with my questions, and for fighting battles with publishing on delivery schedules. Your advocacy made this book possible. Adam Chalmers, technical editor: your insights and thorough reviews elevated the technical accuracy and clarity of every chapter. Your attention to detail is remarkable. Gerard Gallant: your meticulous work as technical proofreader polished every detail and ensured the code examples work flaw- lessly. Angelina Lazukić, review editor: you orchestrated the extensive review process that brought diverse perspectives to strengthen this book. To Courtney Kimball and Manning’s marketing team—especially Aira Dučić, Ana Romac, Robin Campbell, Divya Mudaliar, and Sam Wood—thank you for your invalu- able support in helping me share this book with the community through conferences and other promotional opportunities. This book benefitted enormously from the numerous reviewers who provided feedback throughout its development: Advait Patel, Beatriz Gascón Lourenco, Sergio Britos, David Justice, David Paccoud, Denis Saripov, Fahrudin Paljus, Heng Zhang, German Gonzalez-Morris, Ikko Ashimine, James Haring, Jeremy Lange, Joe Zhou, Joel Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
18
xvi acknowledgments Dice, John Guthrie, Jonathan Womack, Jorge Prendes, Juan Camilo Cifuentes, Clyde Kallahan, Liam Randall, Lîm Tsú-thuàn, Luke Wagner, Mario-Leander Reimer, Mark Fisher, Max Sadrieh, Michael Bright, Miley Fu, Mohammad Shahnawaz Akhter, Olivier Ducatteeuw, Peter Hampton, Piotr Jastrzebski, Piotr Sarna, Pradeep Saraswati, William Ko, Ronald Borman, Sander Zegveld, Shantanu Kumar, Simeon Leyzerzon, Thomas Lockney, Thorsten Hans, Tom Oeste, Vojta Tuma, Wayne Mather, William E. Wheeler, Zachary Manning, and Zbigniew Curylo. Each of you helped shape this book, catching errors, suggesting improvements, and ensuring the content serves its intended audi- ence. Your collective wisdom made this a much better resource for the WebAssembly community. I’d also like to thank the broader WebAssembly community, particularly the Byte- code Alliance team and the WebAssembly Community Group. Your work on Wasmtime, WASI specifications, and tooling provides the foundation that makes server-side Web- Assembly possible. Special thanks go to those who answered my questions on forums and GitHub issues as I worked through challenging technical details. To Jonathan Gennick, who first approached me after my WasmCon talk—thank you for seeing the potential for this book and for believing that the developer community needed a comprehensive guide to server-side WebAssembly. Finally, thank you to the entire production team at Manning who worked behind the scenes to transform my manuscript into the polished book you’re reading today. Alek- sandar Dragosavljevic facilitated my connection with this exceptional team. Keri Hales, production editor, expertly guided the book through the production process. Kari Lucke, copy editor, refined my prose and ensured consistency throughout. Katie Ten- nant, proof manager, coordinated the final quality checks that caught countless details. Tamara Švelić Sabljić, typesetter, brought the technical content to life with clean, read- able layouts. Your professionalism and dedication to quality are evident on every page. Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
19
xvii about this book Server-Side WebAssembly: Building portable and secure multi-language apps teaches you how to make use of WebAssembly (Wasm) beyond the browser to build efficient, secure, and portable server- side applications. Rather than presenting abstract concepts in isola- tion, this book takes a hands-on approach: you’ll build a complete smart content man- agement system (SmartCMS) from the ground up, with each chapter introducing new Wasm concepts through practical implementation. This approach ensures you not only understand the theory but also gain real-world experience applying Wasm’s unique capabilities for cloud computing, edge deployment, and cross-language interoperability. Who should read this book This book is for backend developers, systems architects, and DevOps engineers who want to use Wasm for server-side development. While the book primarily uses Rust for examples, readers comfortable with any modern programming language can follow along—the concepts translate across languages that compile to Wasm. You should have basic familiarity with server-side development concepts, containerization basics, and command-line tools. No prior Wasm experience is required. How this book is organized: A road map The book contains nine chapters divided into two parts. Part 1: WebAssembly for Architects (chapters 1–5) introduces Wasm from a systems perspective, covering the fundamental concepts and architecture: ¡ Chapter 1 introduces Wasm’s evolution from browser technology to server-side platform, exploring its performance characteristics, security model, and ideal use cases for serverless and edge computing. Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
📄 Page
20
xviii about this book ¡ Chapter 2 demonstrates building server-side applications with Wasm modules, diving deep into Wasm’s memory model and the guest-host architecture that enables system interaction. ¡ Chapter 3 introduces Wasm components, showing how they enhance por- tability and security through higher-level abstractions and cross-language interoperability. ¡ Chapter 4 explores interfacing Wasm with underlying systems through WASI, demonstrating capabilities management and component composition. ¡ Chapter 5 showcases advanced applications, including machine learning infer- ence with wasi-nn and database integration, highlighting Wasm’s versatility. Part 2: WebAssembly for Developers (chapters 6–9) focuses on practical development and deployment: ¡ Chapter 6 covers creating production-grade applications using standard- ized interfaces and prebuilt hosts, emphasizing best practices for real-world deployments. ¡ Chapter 7 introduces Wasm containers, demonstrating how to package and deploy Wasm workloads using familiar containerization tools. ¡ Chapter 8 explores Kubernetes integration for Wasm applications, covering orchestration, scaling, and management in cloud environments. ¡ Chapter 9 examines the future of Wasm, including emerging proposals, ecosys- tem developments, and the potential effects on cloud computing. While the book is designed to be read sequentially, with each chapter building on pre- vious concepts, experienced developers can jump to specific topics. The SmartCMS project that runs throughout the book provides hands-on experience with each con- cept as it’s introduced. About the code This book contains many examples of source code both in numbered listings and in line with normal text. In both cases, source code is formatted in a fixed-width font like this to separate it from ordinary text. In many cases, the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In some cases, even this was not enough, and listings include line-continuation markers (➥). Additionally, comments in the source code have often been removed from the list- ings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts. You can get executable snippets of code from the liveBook (online) version of this book at https://livebook.manning.com/book/server-side-webassembly. Source code for the examples in this book is available for download from the Manning web- site at https://www.manning.com/books/server-side-webassembly and from the GitHub repository at https://github.com/danbugs/serverside-wasm-book-code. The Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>