Shimul Chowdhury

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.

Flask Falcon Actix-web Rocket NestJS
Total Requests 11,222 14,802 95,333 1,02,441 30,913
Req/Sec 186.74 246.32 1586.27 1704.35 514.38
Total Read 6.84MB 10.46MB 105.95MB 162.43MB 8.82MB
Transfer/sec 116.53KB 178.21KB 1.76MB 1.24MB 150.21KB
Request Timeout 10,496 1955 3729 4184 4676

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.

programmingbenchmarkingflaskfalconactix-webrocketnestjspythonjsrust