4 ms·
I'm pretty sure a lot of people don't understand the tradeoffs and don't really need concurrent code. There are really only a couple of use-cases where it's rea
by kissgyorgy 4y ago
I'm pretty sure a lot of people don't understand the tradeoffs and don't really need concurrent code. There are really only a couple of use-cases where it's really handy: for example an API gateway, where you only get and send HTTP requests. Other than that, I don't see how it worth the insane complexity (compared to sync code).
You can write web servers in a sync manner; Flask, Django is way better if you only need an API, choosing FastAPI for a simple REST API is a huge mistake.
- thunky 4y ago> FastAPI for a simple REST API is a huge mistake FastAPI can be sync or async, although sync will have "a small performance penalty" https://github.com/tiangolo/fastapi/issues/260#issuecomment-495945630 https://github.com/tiangolo/fastapi/issues/260#issuecomment-...
- walls 4y agoWhat kind of APIs are you writing that don’t involve db lookups or calls to other services?
- samwillis 4y agoAsyncio does not make your db calls or io faster, it does make your code more complex. The only thing async io gives you is scalability of many MANY concurrent io operations. You have to either be pushing seriously large traffic or doing a lot of long running websocket/sse/long polling type requests. The only other use case is lots of truly concurrent io within one request/response cycle. But again that is unusual, most apis have low single digit db queries that are usually dependent on one another removing any advantage of async.
- fprct 4y ago> The only other use case is lots of truly concurrent io within one request/response cycle. But again that is unusual, most apis have low single digit db queries that are usually dependent on one another removing any advantage of async. Why just "within one cycle"? What about situation where you spend 1s in single db query and are 100ms cpu bound during request handling?
- samwillis 4y agoTransitional multithreaded Python web servers handle that very well and have for decades, you shouldn't need to manually handle yealding in simple cases in your application code. The point is asyncio is to have find grade control of yealding.
- mixmastamyk 4y agoChoosing fastapi for a fast api is a mistake?
- kissgyorgy 4y agoChoosing unnecessary complexity for a simple task is a mistake. FastAPI is not faster than Django or Flask for a single request, quite the opposite.
- hdjjhhvvhga 4y agoThere are other valid reasons than speed: https://christophergs.com/python/2021/06/16/python-flask-fastapi/ https://christophergs.com/python/2021/06/16/python-flask-fas...
- lucasyvas 4y agoHow is Django less complex than FastAPI? Django was built for monolithic web applications - it does fine with REST, but your position is backward. FastAPI is purpose built for smaller APIs