Will WebAssembly Replace Your APIs and Microservices?

Will WebAssembly Replace Your APIs and Microservices?

Posted in

HTTP APIs have existed largely without change for nearly 25 years. The REST architectural style, which Roy Fielding first described in 2000, still largely defines how we think about and use APIs. Considering how much digital tools have changed in the last 25 years, some say it’s time for APIs to evolve to take advantage of today’s technology. That’s where WebAssembly comes in.

First introduced in 2015, WebAssembly was designed to allow high-performance programs to be executed client-side. Running programs on websites may be one of the primary uses for WebAssembly, but that’s far from its only application. As the Introduction to WebAssembly states, “Its main goal is to enable high performance applications on the Web, but it does not make any Web-specific assumptions or provide Web-specific features, so it can be employed in other environments as well.”

Will WebAssembly live up to its hype? Will the WebAssembly standard prove to be as disruptive as some are predicting? Could WebAssembly components replace current architectural styles for APIs and microservices? Let’s take a deeper look into this emerging technology to find out.

What Is WebAssembly?

WebAssembly, often abbreviated as Wasm, is a binary instruction format for running executable programs on virtual machines. It was originally created to circumvent the limitations of JavaScript, which was the primary language used by the internet up to that point. It was designed to be implemented on the client side, such as a web browser, making WebAssembly almost completely platform agnostic. Not only can Wasm be run on nearly any machine, including video games, smartwatches, and smart TVs, but the programs it compiles can be written in virtually any language.

Wasm is meant to be used alongside JavaScript, allowing it to be easily integrated via existing web technologies. It’s also gaining a lot of traction in emerging technologies like serverless architecture and edge computing. Considering how nicely Wasm works with existing cloud technology, it’s likely that Wasm won’t replace APIs and microservices but will rise alongside them, instead.

Let’s delve a bit deeper into the similarities and differences between the different formats for a deeper understanding of how these technologies may work together going forward.

WebAssembly vs. APIs: Similarities and Differences

Think of how an API works. Something queries something else, usually via HTTP, which delivers a payload in response. This brief, simplified definition should make the similarities between WebAssembly and APIs immediate and obvious. Wasm transmits executable programs instead of JSON files. This speaks to the other main difference between APIs and Wasm. APIs exist solely for different applications to communicate with one another. Wasm, on the other hand, is more like an application in its own right.

Now, let’s look at microservices to see how they compare to Wasm.

WebAssembly vs. Microservices: Similarities and Differences

WebAssembly has as much in common with microservices as APIs, if not more. But although they’re similar, they differ in specific key ways. Like Wasm, microservices exist to perform a particular function on a virtual machine. Using this definition, you might think of Wasm as a microservice executed on the client side.

This also illustrates one of the major differences between Wasm and microservices. Think of a microservice as a phone number that performs a particular function when dialed. Wasm is more like texting someone a copy of Adobe Acrobat, by contrast. The other main difference is that Microservices require APIs for virtually all of their functionality. Wasm can be invoked via programming languages like JavaScript, on the other hand.

Let’s finish by examining some Wasm use cases to illustrate whether the standard is likely to replace your APIs and Microservices anytime soon.

WebAssembly Use Cases

Let’s start by considering an example of APIs and WebAssembly working together. Imagine a service for processing images in real time. The user uploads their image to the service via an API. This could result in a computationally intensive load on the server. It could also result in performance issues in the instance of surges in traffic or heavy processing demands.

Instead, the API could be designed to deliver an executable binary to an endpoint, where the necessary transformations will be performed. This virtually eliminates the load on the server, making for a much smoother user experience (UX) while keeping resource consumption to a minimum.

Wasm does address some of APIs’ shortcomings, however. Wasm is designed to be as efficient as possible, allowing it to run nearly identically on every platform. This allows developers to integrate Wasm into every workflow, enabling platforms and websites to allow custom plugins. Shopify Functions is an excellent example of this principle in action. It also proves why these plugins are necessary in light of the recent Shopify data leak.

API security is a known issue, and judging from the fact that there have been over 6 billion records exposed via data breaches in 2024 alone, this isn’t going to change anytime soon. Clearly, alternatives need to be considered. WebAssembly promises to be an important part of that solution.

Microservices and Wasm are already being used together in all manner of intriguing ways. For instance, Fermyon has developed Spin, a resource for developing serverless applications and microservices with just a few lines of code. SpinKube is an open-source project that performs a similar function, deploying WebAssembly binaries on Kubernetes.

Will WebAssembly Replace APIs or Microservices?

Based on these examples and everything else we’ve seen, WebAssembly won’t be replacing APIs or microservices anytime soon. Microservices may be in greater danger, as both microservices and WebAssembly allow access to distributed executables. As things stand, there’s room for all three. WebAssembly, APIs, and microservices promise to deliver the best of all worlds.