Menu

Hangfire Alternative in .NET: Why I Replaced It With BackgroundService and Channel
📰

Hangfire Alternative in .NET: Why I Replaced It With BackgroundService and Channel

DEV Community: backend·Kausar Raza·24 days ago
#eDiVWZZn
Long article (2624 words) — no AI summary yet.
Reading 0:00
15s threshold

The first version of this site was an ASP.NET Core MVC app with Hangfire wired in: a dashboard at /hangfire , five recurring jobs, ten places in the code that called BackgroundJob.Enqueue , and a second SQL Server database just to hold Hangfire's job tables. When I rewrote the backend as a separate Web API, I didn't bring Hangfire with me. The API that serves this page runs two BackgroundService classes fed by System.Threading.Channels , and one WHERE clause does the work of the every-minute job.

This isn't a "Hangfire is bad" post. Hangfire is a good library. It's a post about checking which jobs actually needed it, because for this site the answer was none of them.

The short version: Use Hangfire (or Quartz.NET) when a job must survive a restart, retry on its own, or be visible on a dashboard. If the work is in-process, short-lived and fine to lose on a crash, a BackgroundService with a bounded Channel is built into .NET, needs no extra database, and is about 60 lines.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.