Use BackgroundService for process-local recurring or queue-consuming work, a durable broker for reliable cross-service work, and a job scheduler when you need persisted schedules, retries, dashboards, or distributed coordination. Example: protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await foreach (var job in queue.ReadAllAsync(stoppingToken)) { using var scope = scopeFactory.CreateScope(); await scope.ServiceProvider.GetRequiredService<IJobHandler>() .HandleAsync(job, stoppingToken); } } Bound queues for backpressure, create scopes per item, make handlers idempotent, persist important jobs before acknowledging, and use exponential retry plus a dead-letter path. Do not capture request services or fire-and-forget tasks. Record attempts, duration, correlation, and final outcome.
Backbencher Developer · · 0 likes