Performance Battle: Flask vs Falcon vs Actix-web vs Rocket vs Nestjs

At my current workplace, we are preparing for a new product to be developed. Till date, we have worked with Python Django, Java Spring framework. All those are great. But for this new product we want to be as efficient as possible in-terms of performance, memory & CPU usage, in order to cut operational cost. Therefore, I have been asked to analyze different frameworks & platforms to help decide our next platform.

I have chosen Flask and Falcon from python, actix-web & rocket from Rust, and nestjs from NodeJS for this benchmark.

Benchmarking Environment #

Also I don't feel that a "hello world" benchmark is not good enough. Because even though the platform is fast, it becomes slower when we add database and other external parts on it.

We had an idea of how we might build our next app. We have decided to keep an API Backend, an API Gateway and a Nginx Proxy for the API Gateway. Our API Backend will be only accessible privately via API Gateway. It's common in micro-service architecture to have an API Gateway which aggregates backend APIs. That API Gateway will be a NodeJS Server. We only want to decide which platform we will be using for API Backend.

NginX -> Api Gateway -> Api Backend

So I have set up our environment with —

And for each platform we are going to use awesome https://realworld.io/

Platforms #

Flask #

Falcon #

Realworld.io doesn't exist for Falcon. I had to find another one.

Actix-web #

Rocket #

NestJS #

Benchmark Result #

20 threads with 1000 concurrent request for 60 seconds, using https://github.com/wg/wrk.

FlaskFalconActix-webRocketNestJS
Total Requests11,22214,80295,3331,02,44130,913
Req/Sec186.74246.321586.271704.35514.38
Total Read6.84MB10.46MB105.95MB162.43MB8.82MB
Transfer/sec116.53KB178.21KB1.76MB1.24MB150.21KB
Request Timeout10,4961955372941844676

As expected Rust frameworks are way faster than others. But at my surprise Flask did pretty bad. NestJS also looks promising. We could potentially speed up more by using Fastify instead of Express.

Conclusion #

From the benchmark, it could be concluded that we are going to use Rocket or Actix-web. But the reality is, the benchmark is one of the several areas, when deciding a new platform. We need to consider how productive we are in Rust, given that little to no exposure to it before for a lot of our team members. For now, it seems NestJS might be a good choice for us, as we all know JavaScriptt and an extent of TypeScript. But if we have enough time, Rust might be a good invest for future too.