Dare to be different: Dart on the server-side

10 Jan 2021

"haning differently" (C) Maksim Lin 2021

While Dart has been mostly focused on being a language for client development and has risen to prominence in the last few years with its adoption by Flutter, more recently Dart has seen a surge of interest for use on the server-side as well.

In this article I'd like to cover some of the new (and not so new) ways that you can use Dart for your server-side development needs and finish off with a hint of more to come.

Serverless and on the Edge

With Darts unique ability to cross-compile to Javascript, compile ahead of time to native x86/arm binary code and run its VM as a JIT, Dart has found support across a number of "cloud" providers, especially in the thriving serverless market.

GCP Functions

While previously it was possible to use the compile-to-javascript functionality and there has been documentation for quite a while on using it with AppEngine, at the end of 2020 the work done by Tony Pujals and others meant that Dart now has initial direct support for running on the Google's Functions Framework which means it can run on Google Cloud Run, App Engine and Knative environments all with Dart code running directly on a DartVM.

Dart on GCP twitter screengrab

Cloudflare

Cloudflare workers is a serverless provider, that runs your serverless code "on the edge" of their CDN. It has interesting features like "0ms cold starts", distributed K-V store and seems to have a reasonable pricing model, especially for smaller projects. Initially cloudflare workers only supported JS or languages that could compile to wasm, but more recently they announced support for multiple languages that can compile to JS including Dart.

AWS Lambda

While Lamda has been around for a while as the somewhat "original" serverless platform for JS and given Darts ability to compile to JS, in theory it's has been possible to use Dart with Lambda for some time.

Later on, with Lambda's custom runtimes, there was initially community support for running the DartVM on Lambda

But then at the beginning of 2020, AWS announced official support with their custom runtime for Dart so its now possible to use Dart running on the DartVM with Lambda.

Dart and Docker on a Diet

Apart from serverless, early work done by Paul Mundt and more recently the work by Tony Pujals on sliming down Docker Dart runtime containers means that you can run DartVM, either in JIT or even better AOT mode in very light weight Docker images either on your own hardware or using any of the many platforms that provide for running Docker containers.

But wait there's more!

Finally in a upcoming article, I will be looking in-depth at a way to structure and build your Dart server-side system in a very robust and reliable way that draws inspiration from other server-side platforms, if you decide that you don't want to or cannot use serverless providers. So please subscribe and look out for it soon.


I hope this has been of help to you and if it has or you have any other handy tips to share, please let me know in the comments below or via Twitter.