Posts

Showing posts with the label Blocking

Mastering Long-Running Tasks in ASP.NET Core Without Blocking Requests

Image
  Long-running tasks in ASP.NET Core like generating reports, processing files, or calling slow third-party services shouldn’t run inside controller actions. Keeping an HTTP request open while you do heavy work causes real problems: Timeouts (clients, reverse proxies, load balancers) Lower throughput (requests occupy resources longer) Unreliable execution (deployments/restarts kill in-flight work) Retry amplification (timeouts trigger retries → more load → more timeouts) A better pattern is simple: Accept the request quickly Enqueue the work Return 202 Accepted with a job ID Process the work in the background Let the client check status (or receive a webhook callback) What counts as a “long-running task” in ASP.NET Core A “long-running task” is any work that’s long enough to risk timeouts, tie up resources, or get interrupted by restarts. Common examples: Bulk email sending PDF/Excel report generation File post-processing (virus scan, thumbnails, transcodes) Video/image processing ...