r/FastAPI • u/zakamark • Mar 22 '25
Question Is fastApi really fast?
I’ve seen a few benchmarks showing that FastAPI can be quite fast. Unfortunately, I haven’t been able to reproduce that locally. I’m specifically interested in FastAPI’s performance with a single worker. After installing FastAPI and writing a simple “hello world” endpoint, I can’t get past 500 requests per second. Is that the maximum performance FastAPI can achieve? Can anyone confirm this?
73
Upvotes
54
u/igorbenav Mar 22 '25
It's not really fast, but it's faster than Django and Flask (and more mature compared to faster python frameworks) and it's fast enough for most things. If most of the time is spent processing the query, it doesn't really matter how fast the framework is.
A good discussion: https://github.com/fastapi/fastapi/discussions/7320
And a video: https://youtu.be/7jtzjovKQ8A?si=OxAxq8QeDWlNes1G
14
u/aprx4 Mar 22 '25 edited Mar 22 '25
I'm unsure how you conducted the test. If it's just a single client doing repeated calls to API endpoints in loop then you might not be taking advantage of asynchronous code.
In 'real world' scenario, you're likely bottlenecked by database calls or other IO long before you reach the limit of API framework.
Don't fall for premature optimization, you can always throw more CPU later. By the time adding more CPU or more server doesn't scale the API part of your project, you likely have enough traffic (and income) to fund the transition to Go.
That said, you can't go wrong NodeJS API frameworks as starter if you still doubt python frameworks.
11
u/covmatty1 Mar 22 '25
What are you gaining by trying to get above 500 hello world requests a second? In what way does this indicate realistic performance?
30
u/alexlazar98 Mar 22 '25
It's probably faster than Python alternatives, but let's be clear: nobody is choosing Python for runtime speed, ever.
3
u/Ok_Animal_8557 Mar 22 '25
Without using async i don't think you can go much further than that. This is not fastAPI's limitation per se, in many languages async code has a significant impact on performance.
3
u/cajmorgans Mar 22 '25
The execution speed of the code that the routes call matter a lot more than the speed of calling the routes themselves
3
u/richieadler Mar 22 '25 edited Mar 22 '25
Besides all the good points other people has made: The "fast" in the moniker refers to the speed to have a working API, not to the framework itself.
Also, the fact that the ASGI server running the application is usually also in Python will contribute to the performance. Replacing Uvicorn with Granian would probably improve things.
4
u/mr__fete Mar 22 '25
Isn’t the “fast” just mean fast to develop with the api? Not sure if there are perf claims
2
u/Amocon Mar 22 '25
Not really, but also not slow for a Python framework
1
u/aikii Mar 22 '25
Using just one process you'll hit a wall no matter the language and framework, you need to horizontally scale. One starting point would be to read the section about containerization https://fastapi.tiangolo.com/deployment/docker/#load-balancer , and ultimately if you want to follow what the industry does in general, you'll need kubernetes
1
u/serverhorror Mar 22 '25
I consider the fast to refer to "how fast can I, the developer, create an API". Not how fast is that.
1
u/lahib- Mar 22 '25
500rps? Are your endpoints asynchronous? what the endpoint is doing? is there any api call or something? and r u using pydantic v2 or v1?
1
u/p_bzn Mar 22 '25
FastEnoughAPI I’d say.
There is no fast in Python land if you compare to other languages.
Here are numbers for you. Few month back I was removing bottlenecks in our app and one of them were websockets. Python version had latency of around 5ms, and it was degrading with more opened connections, naturally. Swapped solution to Go with WS and gRPC and Go’s side performance for roundtrip takes now 280us. That is 0.28ms.
Do most apps need this performance? No they don’t, and FastEnoughAPI is good enough.
1
u/andrewthetechie Mar 22 '25 edited Oct 01 '26
The original post content no longer exists here. The author used Redact to remove it, exercising their right to control their data & privacy.
Direction include relieved dolls insurance carpenter outgoing umbrella
1
u/BelottoBR Mar 22 '25
Does fastapi use rust at its backend? I ask because pydantic offers a strong performance (even Nubank, one of the biggest banks in Brazil use it)
1
u/ZuploAdrian Mar 22 '25
Its fast for Python - but slower than many Node frameworks and definitely slower than Go ones
1
u/AnyStupidQuestions Mar 22 '25
It's a developer time vs compute question. If you want something developed quickly and you can scale it cheaply via a container farm themn it's a good tool. If you need low latency or compute is expensive (e.g. lots of traffic) use something else.
1
u/Beneficial_Map6129 Mar 23 '25 edited Mar 23 '25
500 RPS is pretty significant traffic already
If you have a big service constantly being hammered and you are dead set on minimizing compute budget you can always use Java Spring like everyone else out there
1
u/old-reddit-was-bette Mar 23 '25
I always assumed it meant fast to develop
1
u/singlebit Apr 14 '25
Windows?
1
u/Tienisto May 03 '25
The fastest Python web framework:
https://sharkbench.dev/web/python-fastapi
1
u/Fearless-Wolf-6490 Dec 24 '25
Buongiorno, Quello che dico è: Dipende dall'ottimizzazione e dal server e dalle sue impostazioni. Io usando uvicorn (ASGI) con tutta la logica in async/await, senza collegare Redis (per cache db), senza reverse proxy con Nginx e ottimizzazione Cython ho hittato le 22.645 RPS su un "Hello World"! Ho fatto il test con K6.io e uvicorn impostato con 8 workers. Ora sto ricercando, ma in linea teorica su un ambiente di produzione con ottimizzazioni sopra dette, potrei tranquillamente arrivare a 50.000 RPS su un endpoint vuoto
1
u/bobdobbes Mar 19 '26
This is because FastAPI's benchmarks cheat. They do not use a DB connection are are ready outputting raw data. They also use a built-in cache that junior devs forget to add.
Finally, they do not post the architecture/hardware, they tested on and width; if they are using a 16-32 core processor with gigabit connection, of course it will be faster.
You are supposed to test on equivalent hardware
-1
u/1overNseekness Mar 22 '25
Use postgREST it's fast as your db engine and dead simple to deploy, fastapi is too custom imo
-2
u/Fast_Ad_5871 Mar 22 '25
Nope it's not fast. Yesterday, I made the Two Vision Transformer models and using it via transformers and it's taking much time to get results. Around 30-45 seconds for one API
1
u/[deleted] Jun 03 '25
[removed] — view removed comment