Start here. This is the direct spoken answer to practice first.
Overview
Uses FastAPI lifespan to create and close process-owned resources around request serving.
FastAPI lifespan wraps the period when one application process serves requests. Code before yield initializes process-owned resources such as database clients, HTTP clients, or a loaded model; code after yield closes them. I attach only explicitly owned resources to application state or dependencies. Lifespan runs per worker process, so it is not a place for cluster-wide one-time work such as a database migration.