Member-only story
FastAPI vs. Fastify vs. Spring Boot vs. Gin Benchmark
5 min readJan 10, 2022
In a previous article, I benchmarked FastAPI, Express.js, Flask, and Nest.js in order to verify FastAPI’s claims of being on par with Node.js. In this article, I am pitting the champion, FastAPI, against a new set of faster competitors. For each framework, I created an API endpoint that returns 100 rows of data from a PostgreSQL database. The data is returned as JSON.
The code for this benchmark can be found here:
https://github.com/travisluong/python-vs-nodejs-benchmark
Disclaimer: I am not a benchmarking expert. This was simply a random experiment I did out of curiosity. This is for entertainment purposes only.
Here are the results:
FastAPI + asyncpg + orjson + gunicorn
Running 10s test @ http://localhost:8000/orjson
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.29ms 0.93ms 10.28ms 55.43%
Req/Sec 2.19k 568.66 3.25k 60.50%
43575 requests in 10.01s, 333.28MB read
Requests/sec: 4355.30
Transfer/sec: 33.31MB
Fastify + pg
Running 10s test @ http://localhost:3000
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency…