This document provides an overview of background processing and introduces Hangfire as a framework for managing background jobs. It discusses what background processing is and why it is commonly needed as products and SaaS applications evolve. While there are several options for background job frameworks in .NET, the document focuses on Hangfire, outlining its key features like persistence, scaling, monitoring, and extensions. These features make Hangfire a reliable and transparent solution for background processing.
2. WHAT IS BACKGROUND PROCESSING
• Long running tasks that doesn't require user interaction;
• Reliable; Resilient; Transparent; Persistant;
• Sometimes can be really complex;
• Examples:
• Invoices generation at the end of month;
• Monthly/weekly reporting;
• Regular mailings;
• KPIs processing.
3. AS THE PRODUCT EVOLVES,
PROCESSING GROWS
• Reallycommon, and even more in SaaS;
• Jobs require monitoring.
If you keep adding more jobs, after some
time, you’ll run into a scenario that it can’t be
manuallymonitoredanymore;
4. BACKGROUND JOBS FRAMEWORKS
HARD TO CHOOSE ONE
• https://github.com/fluentscheduler/FluentScheduler (1.6k stars)
• https://github.com/HangfireIO/Hangfire (4.7k stars)
• https://github.com/brthor/Gofer.NET (0.2k stars)
• https://github.com/jamesmh/coravel (0.7k stars)
• https://github.com/leosperry/Chroniton (0.15k stars)
• https://github.com/quartznet/quartznet/ (3.2k stars)
• We are not going to jump inside
each one, nor to discuss the
pros/cons of all background job
schedulers.
• or the newest .NET Core IHostedService.
• or maybe you can use Sql Server Agent
to make API requests and forget
everything that I’ve said so far.
7. FEATURES
• Easyto setup;
• Persistent storage - Sql Server, Postgre, MongoDb or Redis (reduce latency to minimum);
• Scale as you grow: Single process, Separated Services/Servers or Web Farm;
• Multiple queues; Degree of parallelism;
• Support for cancellation tokens;
• All included: Automatic retries, exceptions, application shutdowns or even unexpected process
terminations
• There are dozens of extensions available on Github (some of them are really useful);
• IoC Containers (https://www.hangfire.io/extensions.html#ioc-containers)
8. ... AND IS OPEN-SOURCE
BUT THERE’S A PAID VERSION