FastAPI vs. Express.js vs. Flask vs. Nest.js Benchmark

FastAPI vs. Express.js vs. Flask vs. Nest.js Benchmark

I wanted to verify FastAPI’s claims of having performance on par with Node.js. So I decided to conduct a benchmark test. For this, I used wrk, an HTTP benchmarking tool.

Tony Stark

Blog post by Tony Stark - Published at 02/04/2022

I wanted to verify FastAPI’s claims of having performance on par with Node.js. So I decided to conduct a benchmark test. For this, I used wrk, an HTTP benchmarking tool.

I also wanted to test it with a call to an endpoint that makes a call to a PostgreSQL database in order to simulate a more “realistic” scenario. In each case, I created an endpoint that returns one hundred rows of data from the database.

I tested the following combinations:

  • FastAPI + psycopg2
  • FastAPI + SQLModel
  • Flask + psycopg2 + flask run
  • Flask + psycopg2 + gunicorn
  • Express.js + pg
  • Nest.js + Prisma
  • Flask + psycopg2 + gunicorn (4 workers)
  • FastAPI + psycopg2 + gunicorn (4 workers)
  • FastAPI + SQLModel + gunicorn (4 workers)

The code for this test can be found here: https://github.com/travisluong/python-vs-nodejs-benchmark.


Enjoyed this article?

Leave a comment below!