REST API: Node vs Rust

Sean Wragg
Feb 7, 2017 · 4 min read

With all the hype surrounding Rust, I’ve decided to take a closer look. So I spent about an hour or so looking over the Rust Docs and admittingly, it looks like a really fun language.

However, I wanted to see how it’d stack up against my current favorite web layer Node.js using the Restify framework. To do this, I’ve decided to use Rocket as my Rust web framework. I did notice Iron and several other Rust web frameworks but, I really liked the simplicity of the Rocket interface. I think nickel would have been my next choice.

Below we have a snippet for Rocket and another for Restify.

Rust (via Rocket)

It’s also worth pointing out that Rocket relies on a ROCKET_ENV environment variable which can be found under the Environment section of the docs (thanks @SergioB!) and can be set to either development, staging or production. It's important to set this to production otherwise Rocket will run in development mode by default regardless of using the --release flag in cargo.

rustc 1.17.0-nightly (ea7a6486a 2017-02-04)  
cargo-0.18.0-nightly (d710222 2017-02-04)

Node (via Restify)

node v6.9.5
npm 3.10.30

Developer Environment

There’s a lot of parallels to draw upon right out of the box. It didn’t feel overly complicated like getting Java (via JAX-RS) up and running the first time.

After painlessly installing the necessary components, I was able to jump right into code without issue. This is one of my favorite things about Javascript — so I’m happy this type of quick engagement has been replicated.

I think this results in a tie in initial setup. Node may have the edge though with the larger community.

Route Interface

Perhaps, one of the best features is the static typing as used for route params. If the type doesn’t match, the request is forwarded to the next matching route or a 404 is served.

Now with Restify, we can supply some regex for dynamic route validation but, while convenient, this truly is an eye-sore and can become difficult to maintain. And obviously, this does not enforce type casting upon req.params (as they're all treated as strings).

I think Rust (via Rocket) has the upper hand here.

Memory Consumption

Running Rust (Rocket), idle @ < 1MB
Running Node (restify), idle @ 19MB

With Restify at 19MB and Rocket just over 1MB, if I were to guess, I’d assume Rust would win here in the long run.

Requests per Second

wrk -d1m http://localhost:8080/

The results however, were staggering to say the least for both test suites!

Restify was able to reply steadily at nearly 8,000 RPS. Rocket however, was able to churn out a fierce 72,000 RPS!!

I think Rust (and Rocket) wins this category

wrk Benchmark Raw Results

Original AB Benchmark Raw Results

Originally published at on February 7, 2017.


Code, Comics, and Fhqwhgads!

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store