Performance: Event-driven architecture
MEDIUM IMPACT
This affects how quickly the application responds to user actions and external events, impacting interaction responsiveness and server load.
from fastapi import FastAPI, BackgroundTasks app = FastAPI() @app.post('/process') async def process_data(data: dict, background_tasks: BackgroundTasks): background_tasks.add_task(long_running_task, data) return {'status': 'processing started'} def long_running_task(data): import time time.sleep(5) # Simulates background work # Save results or notify user asynchronously
from fastapi import FastAPI app = FastAPI() @app.post('/process') async def process_data(data: dict): # Blocking call result = long_running_task(data) return {'result': result} def long_running_task(data): import time time.sleep(5) # Simulates blocking operation return 'done'
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking synchronous task in request handler | N/A | N/A | N/A | [X] Bad |
| Background task with FastAPI BackgroundTasks | N/A | N/A | N/A | [OK] Good |