the future is now.

Nov 23, 2021

a web application without infrastructure

(VGAN generated picture by Erfurt Latrine Disaster @ErfurtLatrine)

I recently had to ship a small interactive tool that for some reasons should not be deployed on a server. R Shiny or any pythonical alternative would have been a neat option, but the installation process, especially for non-technical user would have been a burden (think software updates).

How about docker running locally ? well, before Windows provided the WSL2 option, it was to say the least an interesting experience to learn more about your resistance to pain.

I then gave a try to golang, and found its tooling excellent : setting up the VSCode plugin was a breeze, no time wasted to setup the debugger, the linter etc… And cherry on the cake, for a compiled language, it’s compilation time is excellent (a few seconds for a small project). One other interesting aspect of golang is that its creator Rob Pike designed golang from the start with concurrency in mind. As a result, writing so-called goroutines (multiples processes running at the same time) in go is quite easy and readable.

And, last but not least, golang provides a Webassembly compiler, that let you convert your golang code into a webassembly file. What does this means ? For people old enough to remember the time before Instagram, there was google Earth, a similar program used to stalk your neighbour’s life. Google Earth at that time was a desktop application, requiring user to first download and install it to be able to use it.

Source : Twitter (a popular microblogging application)

Nowadays, if you open your browser and open the new google earth version, you get the same function, but this time the whole rendering calculation is done within your browser, thanks to webassembly. You can even run a jupyter notebook in your browser with a webassembly version of python !

Coming back to my local application, i then pretrained a XGB classifier in python, and exported the fitted model as a file. Then, i used a golang package to read this model and compute prediction given a user input. The corresponding golang code was finally compiled into a Webassembly file.

I ended then using an ultralight http server written in golang (less than 7MB), serving a web page with a Webassembly file running the pretrained XGBoost Classifier.

Oh, forgot to mention that golang can very easily generate binary files (e.g. .exe file for Windows), making the delivery of this local application pretty straightforward.

The future is now.

References