Kotlin Coroutines Channels and Backpressure for a Resilient Event Bus
A tutorial walks through building a typed event bus in Kotlin using coroutines, aimed at fan-out dispatch to multiple subscribers. It compares the four channel capacity modes (rendezvous, buffered, unlimited, conflated) and warns that unlimited channels risk out-of-memory failures under sustained load. It recommends SharedFlow with a suspending overflow policy as the event bus foundation, since silently dropping events is a data integrity concern. To stop one slow subscriber from stalling others, each subscriber gets its own local channel fed via non-suspending sends, with supervisorScope isolating failures. Finally, it proposes a simple formula relating peak emission rate and consumer processing time to required buffer depth.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in