Internative Logo

What Is Hangfire? Background Jobs and Scheduling in .NET

What Is Hangfire? Background Jobs and Scheduling in .NET

Some work should not happen while a user waits for a web page. Sending a confirmation email, generating a PDF report, resizing uploaded images or syncing records with an ERP can take seconds or minutes, and if the server restarts halfway through, the work must not simply disappear. In .NET applications, Hangfire is one of the most common answers to that problem: it moves such work into background jobs that are stored, retried and visible on a dashboard.

This article explains what Hangfire is, how it works, where it fits, where another tool is the better choice, and how it compares with the alternatives.

What is Hangfire?

Hangfire is an open-source framework for running background jobs in .NET and .NET Core applications. You hand it a method call, and Hangfire stores that call in persistent storage, picks it up on a background worker and runs it, now, later or on a schedule. It needs no separate Windows service or operating system scheduler, although it can run in one.

The project was created by Sergey Odinokov. Early 0.x versions appeared on NuGet in 2013, and Hangfire 1.0, the release that froze the public API as stable, was announced on 30 June 2014. The core library is released under the LGPL 3.0 licence and is free for commercial use; paid Pro and Ace editions add extensions on top.

How Hangfire works

Hangfire has three parts that share one storage.

The client creates jobs. A line such as BackgroundJob.Enqueue(() => emailService.SendWelcome(userId)) does not run the method. It serialises the method, its type and its arguments, and writes them to storage as a job in a queue. The web request returns immediately.

The server processes jobs. A Hangfire server, running inside the web application or in a separate worker process, fetches jobs from the queues and executes them on a pool of worker threads. Several servers can share the same storage, so processing scales by adding instances.

Storage keeps everything. Jobs, queues, states and statistics live in a database rather than in memory, which is why they survive application restarts and deployments. SQL Server storage is built in; Redis storage is part of the paid editions; community packages add PostgreSQL, MongoDB, MySQL and others.

Every job moves through states, such as Enqueued, Processing, Succeeded and Failed. If a job throws an exception, Hangfire retries it automatically, by default up to ten times with growing delays, before marking it as failed for someone to inspect.

Key features

  • Fire-and-forget jobs that run once, as soon as a worker is free.
  • Delayed jobs scheduled to run after a given time span.
  • Recurring jobs defined with cron expressions, such as a nightly report or an hourly sync.
  • Continuations that start when a parent job finishes, for simple multi-step workflows.
  • Automatic retries and a clear failed-job list, so errors are visible instead of lost.
  • A built-in dashboard that shows queues, running and failed jobs, retries and recurring schedules, and lets you trigger or delete jobs.
  • Multiple queues and servers for prioritising work or splitting it across machines.

Where Hangfire is used

  • Email and notification sending outside the request, so pages stay fast.
  • Report and document generation, such as PDFs, Excel exports and invoices.
  • Scheduled maintenance: clean-up tasks, reminders, data archiving.
  • Integrations that pull from or push to ERP, CRM and payment systems on a schedule.
  • Data processing on uploads, such as imports, image processing and validation.

When to choose Hangfire, and when not to

Choose Hangfire when:

  • You run a .NET application and need reliable background jobs without building the plumbing yourself.
  • Jobs must survive restarts and deployments, and failures must be retried and visible.
  • Operations staff need a dashboard to see what ran, what failed and what is scheduled.
  • Your storage is already SQL Server, or a supported database, and you would rather not add a message broker.

Look elsewhere when:

  • The work is a simple loop with no need for persistence or retries. The built-in BackgroundService in .NET is enough.
  • You are building an event-driven system where many services react to messages. A broker such as RabbitMQ or Apache Kafka fits that model better than a job queue.
  • Scheduling needs are complex, with calendars, misfire rules and fine-grained triggers. Quartz.NET is built around scheduling.
  • The application is not written in .NET. Hangfire is a .NET library; Node.js teams use tools such as BullMQ instead.

Two habits keep Hangfire healthy. Make jobs idempotent, because a job can run more than once if a server stops mid-execution. And pass identifiers, not large objects, as arguments, because every argument is serialised into storage.

Hangfire and its alternatives

OptionPersistenceStrengthBest fit
HangfireDatabase storageRetries, dashboard, simple APIBackground and scheduled jobs in .NET apps
Quartz.NETIn memory or databaseRich scheduling and triggersComplex schedules and calendars
.NET BackgroundServiceNone built inPart of the framework, no dependencySimple in-process loops
Message brokers (RabbitMQ, Azure Service Bus)Broker queuesDecoupled services, high throughputEvent-driven and distributed systems

The most common comparison is with Quartz.NET. Quartz is first a scheduler, with detailed triggers and calendars; Hangfire is first a background job processor, with a simpler API, automatic retries and a dashboard out of the box. For most business applications built on .NET, Hangfire covers what is needed with less code. Hangfire's default storage is Microsoft SQL Server, and teams already running Redis or MongoDB can use storage packages for those instead.

How we use Hangfire at Internative

We use Hangfire to manage background workflows and scheduled operations in .NET-based systems. Its reliability, persistence and visibility make it a solid base for asynchronous processing in production.

RiskConnect, the EHS, 5S and Kaizen field engagement platform we built for Küçükoğlu Holding, is one of our published customer stories with Hangfire in its stack, alongside .NET, MongoDB, Vue.js, Flutter, Tailwind CSS, Vite and Chart.js.

If you are building a business system that has to run reports, integrations and scheduled tasks reliably in the background, our enterprise software team can help you design that layer.

Frequently asked questions

Does Hangfire cost money?

The core Hangfire library is open source under the LGPL 3.0 licence and free, including for commercial use. Paid Pro and Ace subscriptions add extensions, such as batches and Redis storage, and private support.

What is Hangfire used for?

Hangfire runs work outside the web request in .NET applications: sending emails, generating reports, processing uploads, calling external systems and running recurring tasks on a schedule, with retries and a dashboard to monitor them.

Is Hangfire reliable?

Yes, when it is used as designed. Jobs are stored in a database, so they survive restarts, and failed jobs are retried automatically. Hangfire guarantees that a job is processed at least once, which means a job can occasionally run twice; writing jobs so that repeating them is safe makes the system dependable.

What is the difference between Hangfire and BackgroundService?

BackgroundService is a base class in .NET for long-running tasks inside the application process. It has no storage, retries, queues or dashboard. Hangfire adds all of those, so it suits jobs that must not be lost, while BackgroundService suits simple loops and listeners.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.