WebAssembly with Go: Taking Web Apps to the Next Leve
Emily Thompson
Published on December 21, 2023
You might’ve noticed the increasing chatter around WebAssembly (WASM) in the dev community. Its potential is vast, and we’ve found it invaluable in enhancing our open source project!
Hi everyone, I’m part of the team behind Permify, an open-source infra that helps developers to create and manage granular permissions throughout their applications.
In this article, I’ll demonstrate why and how we integrated WebAssembly (WASM) into our Playground and gained benefits from its collaboration with Golang.
What does this playground do? Well, without diving too deep, its a interactive module of Permify which used for creating and testing authorization models.
Throughout this post, I’ll be sharing:
- A brief explanation of WASM and the benefits of using it with Go.
- A peek into what spurred our choice to integrate WASM in Permify.
- WASM Implementation, including
- Quick Warm Up: WASM Implementation with Go
- Deeper Dive: Permify’s WASM Code Breakdown
- Frontend: Steps to Embed Go WASM in a React Application
Understanding WebAssembly
WebAssembly (Wasm) has established itself as a pivotal technology, enabling quick and efficient code execution in web browsers and forming a robust bridge between web applications and the high-performance typically associated with native applications.
1. Unveiling WebAssembly:
Wasm acts as a low-level virtual machine, executing a compact binary code that’s translated from high-level languages.
Primary Advantages:
- Universal Browser Support: Thanks to its support from all major browsers, Wasm delivers consistent performance across diverse platforms.
- Near-Native Performance: Intentionally designed to execute binary code at a speed akin to native applications, Wasm enhances the responsiveness of web applications considerably.
In our open-source project, Permify, we strategically incorporated Go (also known as Golang) into its foundational core, selecting it for its widely recognized static typing, concurrency handling, and performance optimization. When the development journey led us to craft the Permify Playground, WebAssembly stepped into the spotlight as a crucial element.
2. Blending Go & WebAssembly:
- Characteristics of Go: Celebrated for its optimal performance and concurrency handling capabilities, Go has carved a sturdy standing within the developer community.
- Synergy with WebAssembly: The translation of Go code into WebAssembly enables developers to effectively utilize Go’s robust performance and concurrency management directly within the browser, propelling the creation of powerful, efficient, and scalable web applications.
Our journey isn’t just about melding Go and WebAssembly. Moving forward, we’ll unearth why Wasm was pinpointed as the technology of choice for the Permify Playground development and what significant benefits were reaped from this decision.
Why WebAssembly?
The inception of the Permify Playground brought with it a key question: How to showcase our capabilities without being entwined in the complexities and maintenance woes of traditional server architectures? WebAssembly appeared as a shining answer. Adopting this binary instruction format allowed us to:
- Execute In-Browser: Permify’s playground could operate straight within the browser, sidestepping server maintenance overheads and repetitive API calls, and notably, making ongoing maintenance a breeze in comparison to older server-based approaches.
- Achieve Peak Performance: Employing WebAssembly ensures that our Go application operates with a level of performance that competes with native applications, enhancing user interactions and bolstering response times.
Harvesting Technical Benefits and Gathering User Feedback
Utilizing WebAssembly in our Permify Playground led us down a path of discernible technical advantages and an embrace from the community:
- Swift Execution: By side-stepping server interactions and deploying WebAssembly in-browser, we’ve been able to deliver ultra-fast response times.
- Uncomplicated User Interface: Centralizing our playground in the browser, we’ve dispelled complexities associated with multi-tool workflows, delivering a clean and straightforward user experience.
- Community Validation: The affirming feedback and positive reception from the developer community stand as validation of our technological choices and implementations.
Join us in the following sections as we delve deeper into the technicalities, feedback, and learnings from our adventure, providing a thorough exploration of our endeavours with WebAssembly.