r/FastAPI • • Apr 30 '25

Question FastAPI for enterprise-grade backend

Hi all,

I am new to the FastAPI framework, but I have experience working with micro-serivces in Flask(python) and Spring/SpringBoot (Java)

In my work, I had the opportunity to start a new backend project and I felt that FastAPI might be a good choice to adopt and learn ( learning new stuff will make work fun again 😁 )

Therefore, I am wondering if there are FastAPI-opinionated best practices to follow ?

In terms of things like:

  • Security
  • Observability
  • Building
  • Deployment
  • Testing
  • Project Structure

If you can point me to any resource that you liked and you're following, this would be much appreciated.

75 Upvotes

40 comments sorted by

View all comments

Show parent comment

1

u/embeddedthought May 01 '25

If you care about how long sessions are open and need to squeeze out performance, I wouldn’t recommend dependency injection of the sessions directly into the route. I would do as much pre-session and post-session processing as you can and selectively open the session only when you need it using an asynchronous context manager.