Roadmap/Kotlin Coroutines
Intermediate

Kotlin Coroutines

Asynchronous programming and concurrency in Android (modern best practices)

3-4 weeks
12.3k students
4.6 rating
Progress0/120 lessons

Key Topics You'll Master

1
Getting Started with Coroutines (Absolute Basics)
2
Suspending & Builders — Foundations
3
Structured Concurrency — Deep Dive
4
Context & Dispatchers — Mastery
5
CoroutineStart Modes — Practical Control
6
Cancellation & Timeouts — Real-World Patterns
7
Exception Handling & Supervision — Mastery
8
Shared Mutable State & Synchronization — Practical Patterns
9
Flow Fundamentals
10
Flow Operators & Backpressure
11
Hot Flows: StateFlow & SharedFlow
+4
more...
Learning Outcomes
  • Use suspending functions, scopes, and structured concurrency correctly
  • Choose the right Dispatcher and switch context with withContext
  • Model streams with Flow, and app state/events with StateFlow/SharedFlow
  • Collect safely using repeatOnLifecycle and collectAsStateWithLifecycle
  • Handle cancellation, timeouts, retries, and exceptions predictably
  • Test coroutines/flows with kotlinx-coroutines-test and Turbine
  • Know when to use Channels vs SharedFlow (no GlobalScope, no BroadcastChannel)
Prerequisites
  • Basic Kotlin knowledge
  • Functions & Lambdas
  • OOP Basics
1
Getting Started with Coroutines (Absolute Basics)
Zero-prereq intro: mental model, first coroutine, basic suspend, and core terms.
3 days
What Are Coroutines? (not threads) — the mental model
video10 min
Hello Coroutine: runBlocking + launch + delay (console demo)
video12 min
suspend Functions 101: writing & calling your first suspending API
video12 min
Cheat Sheet: coroutine • job • scope • builder — quick definitions
article8 min
Project Setup (JVM & Android): coroutines-core/android + test libs
article8 min
Practice: two coroutines printing → refactor into a suspending function
exercise25 min
2
Suspending & Builders — Foundations
Clear separation of concepts: suspension vs blocking, builders, scope boundaries, and a first taste of structured concurrency.
5 days
Suspension vs Blocking: delay() vs Thread.sleep()
video9 min
Suspension Points in Practice: delay, I/O with withContext(Dispatchers.IO), Flow collect/emit
video12 min
Cooperative Cancellation: isActive, ensureActive, yield (keep work responsive)
video10 min
Builders Deep Dive: launch vs async/await (returning results)
video12 min
coroutineScope vs supervisorScope: structure & child-failure behavior
video10 min
Structured Concurrency 101 (overview): parents, children, Job trees
video10 min
runBlocking — when it’s OK (tests/main) and when it’s not (Android/UI)
video9 min
Cheat Sheet: choosing a builder & scope (quick reference)
article6 min
Practice: Parallel API calls with async + cancellation propagation
exercise35 min
3
Structured Concurrency — Deep Dive
Principles, job hierarchies, failure propagation, supervision, and real-world scope design.
5 days
Structured Concurrency Principles (the key invariants)
video10 min
Job Hierarchies & Cancellation Trees (visual walkthrough)
video11 min
Failure Propagation: launch vs async (who cancels whom?)
video10 min
SupervisorJob vs supervisorScope: boundaries & use-cases
video10 min
Structured Parallelism: async + awaitAll + cancellation on first failure
video11 min
Multiple Failures, finally, and NonCancellable (cleanup patterns)
video10 min
Anti-patterns & Leaks: GlobalScope, orphan Jobs, ad-hoc scopes
video9 min
Scope Design Guide (UI, repo, use-case): who owns the scope?
article10 min
Practice: Cancellation propagation lab (normal vs supervisor)
exercise35 min
Practice: Parallel fan-out with fail-fast & proper cleanup
exercise35 min
4
Context & Dispatchers — Mastery
Understand CoroutineContext deeply: elements, inheritance, dispatchers (Main/IO/Default/Unconfined), thread switching with withContext, limited parallelism, and thread-local propagation.
5 days
CoroutineContext 101: elements, + combination, inheritance & overriding
video11 min
Dispatchers: Main, IO, Default — when to use each (and why Unconfined is risky)
video12 min
Android specifics: Dispatchers.Main.immediate & main-safety notes
article8 min
withContext correctly: switching threads without nesting traps; cancellation semantics
video11 min
Tuning concurrency: Dispatchers.IO.limitedParallelism(n) and when to use it
video10 min
Custom dispatchers: Executor.asCoroutineDispatcher vs newSingleThreadContext (trade-offs & cleanup)
article9 min
Naming & diagnostics: CoroutineName + structured logging
video9 min
Thread context propagation: ThreadLocal.asContextElement / ThreadContextElement (MDC, request IDs)
video10 min
Quick note: CoroutineExceptionHandler is a context element (limitations for async)
article7 min
Practice: Reduce context hops, add CoroutineName, wire MDC, and cap IO parallelism
exercise40 min
5
CoroutineStart Modes — Practical Control
DEFAULT, LAZY, ATOMIC, UNDISPATCHED: how they start, when to use them, and common pitfalls.
3 days
The start parameter on launch/async — what it controls
video9 min
DEFAULT vs LAZY — triggering start (start/join/await) & pitfalls in structured concurrency
video10 min
UNDISPATCHED — run on caller thread until first suspension (safer than Unconfined)
video10 min
ATOMIC (Delicate) — guaranteed start before cancellation: use-cases & warnings
article8 min
Practice: Compare modes — warm-up jobs, lazy pipelines, and observing thread hops
exercise30 min
6
Cancellation & Timeouts — Real-World Patterns
Cooperative cancellation model, robust cleanup, timeouts that don’t bite you, and writing cancel-safe suspend APIs.
5 days
Cancellation Model: Job.cancel, CancellationException, parent→child rules
video11 min
Cooperative Cancellation in Practice: isActive, ensureActive, yield (CPU loops)
video10 min
Cleanup Patterns: try/finally, withContext(NonCancellable), closing resources/channels
video10 min
Timeouts Deep Dive: withTimeout vs withTimeoutOrNull, propagation & common pitfalls
video10 min
Designing Cancel-Safe suspend APIs with suspendCancellableCoroutine
video12 min
Hooking Cancellation: invokeOnCancellation, listener removal, idempotent cleanup
article9 min
Canceling Blocking Work: IO with withContext(Dispatchers.IO), interruptible ops, library caveats
video10 min
Policy & Patterns: cancel vs retry, supervisor boundaries, time-budget design
video9 min
Practice: Build a cancel-safe repository (network + cache) with timeouts & retries
exercise40 min
7
Exception Handling & Supervision — Mastery
Understand how failures propagate, where exceptions surface, how supervision isolates errors, and how to build resilient retry logic.
5 days
Exception Model: child→parent propagation & who cancels whom
video11 min
launch vs async: where exceptions surface (handler vs await)
video10 min
CoroutineExceptionHandler: root-only behavior & limitations with async/supervision
video9 min
SupervisorJob vs supervisorScope: isolation boundaries & use-cases
article,10 min
Multiple Failures & Cancellation: suppressed exceptions, failures during cleanup
video10 min
Cancellation vs Failure: handling CancellationException vs real errors (rethrow patterns)
video9 min
Retries & Backoff (no Flow): exponential backoff, jitter, cancellation-aware delays
video10 min
Practice: Fail-fast vs supervised trees + resilient use-case with retries
exercise40 min
8
Shared Mutable State & Synchronization — Practical Patterns
Avoid races with confinement, locks, semaphores, or actors. Keep critical sections tiny and responsive.
5 days
Strategies Overview: immutability, confinement, message passing
video9 min
Mutex.withLock: critical sections, tryLock, and “no blocking inside the lock”
video11 min
Semaphore.withPermit: limiting parallel work & rate limiting (vs limitedParallelism)
video10 min
Single-threaded serialization: custom dispatcher/executor & cleanup duties
article9 min
Actors for Single-Owner State: when an actor beats locks; mailbox/backpressure basics
video10 min
Choosing the Right Tool: decision guide + fairness/starvation notes
article8 min
Practice: Controlled parallel downloads + shared progress counter (lock-free → mutex)
exercise45 min
9
Flow Fundamentals
Cold streams, terminal ops, cancellation transparency, and where work runs.
1 week
Cold vs Hot — mental model & lifecycle (preview of StateFlow/SharedFlow)
video10 min
flow{} builder & terminal ops: collect, first/firstOrNull, single, toList
video12 min
Context & execution: flowOn vs withContext (upstream-only) + exception transparency
video12 min
Side-effects & structure: onStart, onEach, onCompletion, emitAll
article9 min
Wrapping callbacks with callbackFlow: awaitClose, cancellation-safe cleanup
video12 min
channelFlow vs callbackFlow — when to choose which
video9 min
Practice: Debounced search pipeline (cold Flow)
exercise45 min
10
Flow Operators & Backpressure
Transform, combine, and control rate like a pro (with correct error semantics).
5 days
Transform basics: map, transform, transformLatest (when latest cancels prior work)
video11 min
FlatMap family: flatMapConcat / flatMapMerge / flatMapLatest — trade-offs & patterns
video12 min
Combining streams: zip vs combine (+ combineTransform) — ordering & timing
video10 min
Rate control: buffer(capacity, onBufferOverflow), conflate, collectLatest, debounce, sample
video12 min
Stateful ops: distinctUntilChanged/By, scan, runningFold
article10 min
Error handling: catch placement (upstream/downstream), onCompletion, retry/retryWhen
video11 min
Practice: Performance-tuned pipeline (debounce + flatMapLatest + buffer)
exercise45 min
11
Hot Flows: StateFlow & SharedFlow
UI state, one-shot events, and sharing strategies done right.
4 days
StateFlow for UI State: replay=1, conflation, update()
video12 min
SharedFlow for Events: replay, extraBufferCapacity, onBufferOverflow (sticky vs non-sticky)
video12 min
Turning Cold → Hot: stateIn & shareIn with SharingStarted (Eagerly/Lazily/WhileSubscribed)
article10 min
Scopes & Performance: where work runs with flowOn + stateIn/shareIn; avoid per-collector hot flows
video10 min
Practice: ViewModel exposing StateFlow (UI state) + SharedFlow (one-shot events)
exercise45 min
12
Lifecycle-Aware Collection (Android)
Compose & View patterns that are safe, leak-free, and production-ready.
4 days
Launching in Android: viewModelScope & lifecycleScope (ownership, boundaries, pitfalls)
video12 min
Compose: collectAsStateWithLifecycle (vs collectAsState), LaunchedEffect, rememberCoroutineScope, snapshotFlow
video12 min
Views: repeatOnLifecycle (and why launchWhenX is discouraged)
video10 min
Avoiding Leaks & Duplicates: single source of truth, shareIn/stateIn, where to collect
article10 min
Practice: Build a lifecycle-safe screen (Compose + View example)
exercise40 min
13
Channels — Pipelines & Point-to-Point
Build producer–consumer pipelines with Channels and know when SharedFlow is the better fit.
4 days
Channel Types & Capacity: RENDEZVOUS / BUFFERED / CONFLATED / UNLIMITED
video12 min
Sending & Receiving: send/receive, trySend/tryReceive, receiveCatching
video11 min
Lifecycle: close vs cancel, iteration with for-loop, backpressure semantics
video10 min
Patterns: fan-in, fan-out, pipelines, fairness trade-offs
article9 min
Channel vs SharedFlow: decision guide (point-to-point vs broadcast)
video10 min
Practice: Multi-stage channel pipeline with multiple producers/consumers
exercise45 min
14
Integration: Networking, Storage, Background
End-to-end Android patterns with coroutines: suspend networking, offline-first storage, paging, and background work.
1 week
Retrofit suspend APIs + serialization (Moshi / Kotlinx) & OkHttp interceptors/timeouts
video12 min
Network patterns: withContext(Dispatchers.IO), retries/backoff, error mapping (HTTP→Domain)
video11 min
Room DAO with Flow: queries, transactions, and DTO → Entity → Domain mapping
video12 min
Single Source of Truth: cache-then-network, invalidation, and sync strategies
article9 min
Paging 3 in practice: Pager, PagingSource, RemoteMediator, load states, cachedIn(viewModelScope)
video12 min
Background work: WorkManager CoroutineWorker (cancellation, progress, constraints) vs Foreground service
video11 min
Practice: Offline-first repository (Retrofit + Room + Paging RemoteMediator) with retry & background sync
exercise60 min
15
Testing Coroutines & Flows — From Zero to Flake-Free
Deterministic, fast, and reliable tests with kotlinx-coroutines-test and Turbine.
5 days
Test Dispatchers 101: StandardTestDispatcher vs UnconfinedTestDispatcher
video10 min
runTest & Virtual Time: scheduler, advanceTimeBy, runCurrent, advanceUntilIdle
video12 min
MainDispatcherRule (JUnit4/JUnit5) & swapping Dispatchers.Main safely
article9 min
Testing suspend functions: success, exceptions, cancellation
video10 min
Testing Cold Flows: terminal ops, flowOn, catch placement
video10 min
Testing Hot Flows (StateFlow/SharedFlow): backgroundScope, replay, buffer, timing
video11 min
Turbine Patterns: awaitItem, skipItems, expectNoEvents, timeouts, cancelAndIgnoreRemainingEvents
video11 min
Time-based Operators: debounce, sample, retry/backoff with virtual time
video11 min
Channels & select in tests: send/receive, closing, and race scenarios
article9 min
Flake-proofing: deterministic scheduling, avoid real delays, leak checks with TestScope
video10 min
Practice: Repo Flow tests (retry + timeout) + StateFlow UI state with Turbine
exercise45 min
16
Performance, Patterns & Capstones — Ship It
Make it fast and resilient, then apply everything in real projects.
1 week
Minimize context hops & avoid needless withContext (throughput & readability)
video10 min
Tuning parallelism: Dispatchers.IO.limitedParallelism(n) vs Semaphore.withPermit
video10 min
Backpressure in hot streams: StateFlow/SharedFlow buffer, overflow, replay sizing
video10 min
Detecting cancellation leaks & logging coroutine trees (diagnostics playbook)
video10 min
Pattern catalog: retries/backoff, time budgets, circuit breaker & hedging
article9 min
Capstone A: Offline-First Search (Flow + Room + retries)
video12 min
Capstone B: Downloader (callbackFlow + StateFlow, pause/resume/cancel)
video12 min
Practice: Implement one capstone end-to-end (repo, tests, perf checks)
exercise120 min