Executing Background Tasks
Learn to offload long-running operations to background tasks, preventing API blocking and improving user experience.
Slow Endpoints & UX
Imagine your API needs to do something time-consuming, like sending an email or processing a large file, after a user request.
If your API waits for these tasks to finish before responding, the user experiences a slow, unresponsive application. This is called a blocking operation.
Bad user experience often leads to users abandoning your app!
Blocking vs. Non-Blocking APIs
Think of it like ordering food:
- Blocking: You order, and the waiter waits for your food to be cooked, served, and eaten before taking the next order. (Terrible service!)
- Non-Blocking: You order, the waiter takes your order to the kitchen, and immediately takes the next customer's order. Your food is prepared in the background.
We want our APIs to be non-blocking for a smooth user experience.
All lessons in this course
- Async/Await in Python Refresher
- FastAPI and Async Operations
- Executing Background Tasks
- WebSockets for Real-Time Communication