0

I am building a fastapi project following a controller, manager and repo layers. My db connection and session is initialized and injected into each controller on the first request. It means my each controller is going to have only one session for all the endpoints in it. Is it the good way of doing it?

The other way of doing it is to make a new session for each request and fastapi dependency management will gracefully close the session on completion of request.

Actually, I was tired of using Depends() in each path function, so injecting the session once in the controller looks better. But I don't know will it work better in case of concurrent requests?

2
  • This question is similar to: Postgres scalability - What is the impact of connection pooling?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Sep 14 at 13:53
  • Connection pooling is usually recommended, connection objects are not thread safe. Commented Sep 14 at 13:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.