.NET › Generic Host

How does the Generic Host support hosting multiple independent hosted services with different failure isolation needs?

Advanced

Answer

Since each IHostedService/BackgroundService runs its own independent ExecuteAsync loop concurrently after startup, a failure in one (an unhandled exception, depending on BackgroundServiceExceptionBehavior configuration) doesn't necessarily crash unrelated hosted services running in the same host -- though by default an unhandled exception can still bring down the entire host in some configurations, so services with genuinely independent failure domains and criticality levels are sometimes better deployed as entirely separate processes/containers rather than combined into one host, trading operational simplicity (one deployable) against blast-radius isolation (one process's crash doesn't affect unrelated work).
// Two very different criticality services in the same host --
// a crash in one could still affect overall process health
builder.Services.AddHostedService<CriticalPaymentProcessor>();
builder.Services.AddHostedService<NiceToHaveAnalyticsExporter>();

// Consider separate deployments if their failure/scaling profiles genuinely differ
Real-world example A team splits a previously monolithic Worker Service (combining critical payment processing and non-critical analytics export in one host) into two separately deployed services after an analytics bug caused an unrelated outage in payment processing, illustrating the blast-radius trade-off.

Common follow-ups: What specific configuration determines whether one hosted service's crash affects others?;How do you decide when combining services into one host versus separate deployments is appropriate?