In modern .NET applications, background processing plays a crucial role in handling tasks that don't need to be executed immediately, such as sending emails, processing large datasets, or scheduling recurring jobs. A library I like to use to manage background tasks in .NET is Hangfire, thanks to its simplicity, flexibility, and wide range of storage options.
As these background tasks can be scheduled in the future, some kind of storage needs to be configured where Hangfire keeps all the information related to background job processing. Out of the box multiple storage systems are supported, one of them being SQL Server.
Although using SQL Server can be a convenient option to use as the main storage for your Hangfire, it comes with one big disadvantage:
- Polling is used to fetch new jobs.
This has 2 consequences:
- It increases the load on your SQL server instance
- The time to pickup a new job and execute it is signifcantly longer(here is a comparison with Redis from the documentation):
If it is ok to have some additional delay, you can configure a slower QueuePolInterval(the default is TimeSpan.Zero
for Hangfire 1.7 or newer):
More information
Hangfire – Background jobs and workers for .NET and .NET Core