BackgroundTasks
Lightweight per-request runner for short, non-blocking work after a response finishes.
Core Idea
BackgroundTasks is a FastAPI helper that lets you register callables during a request and run them immediately after the response is returned. It shares the same worker process as the main app, so it is ideal for quick follow-up work like sending emails, logging analytics, or syncing with a secret store without blocking the client.
Why It Matters Here
In the Mathbong FastAPI series, BackgroundTasks complements StreamingResponse so long-running operations are split: the user gets a streamed acknowledgement while short follow-up work continues after the response. For durable or heavy jobs, the term page points readers toward separate worker and queue systems instead of treating BackgroundTasks as a full job runner.