ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#โ€ข4mo agoโ€ข
48 replies
Merlin

Recommended way to implement a Channel consumer with async handlers & backpressure?

Hey everyone ๐Ÿ‘‹

Iโ€™m working on a microservice (DDD style) where aggregates communicate through an in-memory Channel (System.Threading.Channels).
Producers push domain messages/events into it, and a background consumer runs handlers for each message.

I want to keep backpressure (so producers block if the consumer is behind) but still handle multiple messages asynchronously โ€” without serializing everything or flooding the system.

Hereโ€™s the trade-off Iโ€™m running into:

await foreach (var msg in reader.ReadAllAsync())
{
    await HandleAsync(msg); // preserves backpressure but no parallelism
}


await foreach (var msg in reader.ReadAllAsync())
{
    _ = Task.Run(() => HandleAsync(msg)); // loses backpressure
}
await foreach (var msg in reader.ReadAllAsync())
{
    await HandleAsync(msg); // preserves backpressure but no parallelism
}


await foreach (var msg in reader.ReadAllAsync())
{
    _ = Task.Run(() => HandleAsync(msg)); // loses backpressure
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

โ” Callback consumer to async Task
C#CC# / help
4y ago
โ” Is there a better way to implement this "pattern"?
C#CC# / help
3y ago
Best way to implement a regex based lexer [Answered]
C#CC# / help
4y ago
โ” Need help with Event Handlers to update a field.
C#CC# / help
3y ago