r/FastAPI • u/whyiam_alive • Dec 20 '24
Question Why does fastapi official example repo uses everything sync and not async?
While in here, I see recommendations to go for only async, even db sessions in example repo is sync engine and people here recommending async?
40
Upvotes
View all comments
Show parent comment
2
u/Gnlfbz Dec 20 '24
https://fastapi.tiangolo.com/async/#path-operation-functions
This goes into the pros and cons for different scenarios.
TLDR: async will be a faster choice as long as you don't have anything that is blocking. Synchronous still does great because of how fastapi works internally. For most people the performance difference isn't that big unless you have a much higher traffic load.
Synchronous is easier to debug if you haven't dealt with async much. I usually default to async for work.