Hot Take: Dart makes a Great Server Side Language




Dart programming language | Dart


Google promotes Dart as a client-optimized language for fast apps on any platform.  This makes a ton of sense. Bootstrapping a language ecosystem is an enormous task that requires laser like focus on where the language adds the most value. Right now, that is Flutter

Sometimes, when a language finds success in one domain it can cross over to another.  One can argue that NodeJS  would never be a thing had Javascript not been adopted in the browser. 

Can Dart cross over to the server? I think it can.  

Recently I created a Cloud Run service to perform smoke tests against another REST service. Golang would be the obvious choice here: Container friendly, small native binaries and a great http library out of the box.  

Now Go is a fine language, and this is a purely subjective thing, but I find Dart much more enjoyable and productive to work with.  There are of course fewer server side libraries, but the ecosystem is growing quickly, and the standard Dart library is really well designed. I've said this before: Dart is the most fun language that I have used in a long time. It behaves like you expect it to, and the tool chain is amazing (hot reload is so sweet...)

To make a long story short, Dart did an admirable job at this task. But what really took me by surprise was the final image size of the container:  Using the "scratch" docker image, and the dart2native compiler (Dart has a VM, but it can also compile to native code), the final container weighs in at 12.9 MB, or 5.2MB compressed (as reported by gcr.io).

12.9 MB! Let that sink in for a bit. Even using Go, I think one would be hard pressed to create a smaller "cloud ready" docker image.  

I'm speculating, but I think the primary reason dart2native does so well here is tree shaking. The compiler aggressively prunes code that it knows can not be reached.  This includes your code, but also any libraries that you depend on (presumably even including the Dart standard library). This results in a very small binary that is mostly the Dart runtime.

If you want to look at Dart on server, here are some suggestions:
  • For a batteries included http server framework (REST, postgres, ORM, etc.), check out https://aqueduct.io/
  • Just need a dead simple http service? shelf and its various plugins is a great option
  • dio is really nice http request wrapper on top of the Dart http library. 

Comments

Popular posts from this blog

Introducing ds-operator, the ForgeRock Directory Services Operator for Kubernetes

Automating OpenDJ backups on Kubernetes

Deploying the ForgeRock platform on Kubernetes using Skaffold and Kustomize