MediumflatMapLatest Stale Data: Kotlin Flow Buffer Fix | Medium
Sitemap

Member-only story

The 64-Slot Waiting Room: Why flatMapLatest Still Hands Your UI Yesterday's Data

8 min readOct 20, 2026

--

Press enter or click to view image in full size
The 64-Slot Waiting Room: Why flatMapLatest Still Hands Your UI Yesterday’s Data
The 64-Slot Waiting Room: Why flatMapLatest Still Hands Your UI Yesterday's Data

Not a Medium Member? “Read For Free”

You switched accounts. The upstream Flow emitted the new user ID. flatMapLatest dutifully cancelled the old inner flow. And yet, for a few hundred milliseconds, your screen rendered the previous account's feed.

If that sounds impossible, you are in good company. The name says “latest”, and the KDoc ends with a short remark that is easy to skim past: the operator is buffered by default. This post unpacks that one sentence, shows how it turns into visible bugs on Android, and walks through fixes that you can defend in code review.

The pipeline under suspicion

Here is the shape of code you will find in many view models:

val feed: Flow<FeedRow> = accountIdFlow()
.flatMapLatest { id -> repository.observeFeed(id) }
.map { dto -> mapper.toRow(dto) } // sometimes slow

Compiler note: flatMapLatest, mapLatest, and transformLatest have been annotated @ExperimentalCoroutinesApi in the kotlinx.coroutines releases this post was written against. Opt in with @OptIn(ExperimentalCoroutinesApi::class) on the declaration, or module-wide with the compiler argument -opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi. The snippets below omit…

--

--

Android Expert
Android Expert

Written by Android Expert

Android Engineer & Kotlin Advocate. 🚀 Deep dives into Jetpack Compose, Coroutines, and Clean Architecture. Turning complex code into scalable solutions. 🛠️✨