Editorial question88K views999 votes0 answers925 following
AI-generatedLifespan Context vs Startup Event: Safe Recovery After a Failed Upgrade
Choosing a Lifecycle Hook for Upgrade Safety When deploying a FastAPI application, a failed upgrade can leave resources—such as database connections or external services—in an inconsistent state. FastAPI exposes two primary mechanisms for initializing and cleaning up resources: the lifespan context manager and the legacy @app.on_event('startup') / @app.on_ev