Channel Types: Rendezvous, Buffered, Conflated, Unlimited
Choose the right channel type for your communication pattern.
Channel Types: Rendezvous, Buffered, Conflated, Unlimited is a free Kotlin Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Channel Factory
Create channels with Channel<T>(capacity). The capacity determines buffering and suspension behavior.
import kotlinx.coroutines.channels.Channel
val rendezvous = Channel<Int>() // capacity 0
val buffered = Channel<Int>(64) // capacity 64
val unlimited = Channel<Int>(Channel.UNLIMITED)
val conflated = Channel<Int>(Channel.CONFLATED)
fun main() { println("Channel types created") }Rendezvous Channel (capacity=0)
Default channel. send suspends until a receiver is ready, and receive suspends until a sender sends. They rendezvous — meet at the same point.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>() // rendezvous
launch {
println("Sending...")
ch.send(1) // suspends until receiver is ready
println("Sent")
}
delay(100)
println("Receiving...")
println(ch.receive())
}Buffered Channel
A buffered channel allows the sender to continue without waiting until the buffer is full. When full, send suspends.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>(3) // buffer of 3
launch {
repeat(3) {
println("Sending $it")
ch.send(it) // does not suspend until buffer full
}
ch.close()
}
delay(500)
for (v in ch) println("Got $v")
}Channel.BUFFERED
Channel.BUFFERED uses the default capacity (64). This is equivalent to Channel(64).
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.*
fun main() = runBlocking {
val ch = Channel<String>(Channel.BUFFERED)
println("Default buffer capacity is implementation-defined (~64)")
ch.close()
}Unlimited Channel
Channel.UNLIMITED never suspends the sender — it buffers all values. Use with caution: unlimited memory growth possible.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>(Channel.UNLIMITED)
launch {
repeat(1000) { ch.send(it) } // never suspends
ch.close()
}
var sum = 0
for (v in ch) sum += v
println("Sum: $sum")
}Conflated Channel
Channel.CONFLATED keeps only the most recent value. If a new value arrives before the previous is received, the old one is dropped.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>(Channel.CONFLATED)
launch {
repeat(5) { ch.send(it) } // 0..4 sent rapidly
ch.close()
}
delay(50) // let all sends happen
println("Received: ${ch.tryReceive().getOrNull()}") // likely 4 (last)
}RENDEZVOUS vs BUFFERED Timing
Rendezvous synchronizes producer and consumer. Buffered lets the producer run ahead, decoupling timing.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>(Channel.BUFFERED)
val t = System.currentTimeMillis()
launch {
repeat(5) { ch.send(it) } // fast — doesn't wait
ch.close()
}
for (v in ch) { delay(100); println("$v at ${System.currentTimeMillis()-t}ms") }
}onBufferOverflow Strategy
With Channel(capacity, onBufferOverflow), choose what happens when the buffer is full: SUSPEND (default), DROP_OLDEST, or DROP_LATEST.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ch = Channel<Int>(2, BufferOverflow.DROP_OLDEST)
launch {
repeat(5) { ch.trySend(it) } // 0,1,2,3,4 — buffer keeps newest 2
ch.close()
}
for (v in ch) println(v) // likely 3 4
}Choosing Channel Type
Decision guide: Rendezvous for tight synchronization; Buffered for throughput; Conflated for latest-value-only (like UI state); Unlimited for event logging where loss is unacceptable.
import kotlinx.coroutines.channels.Channel
// Use cases:
// RENDEZVOUS — handshake between producer and consumer
// BUFFERED — decouple I/O-heavy producer from slow consumer
// CONFLATED — UI updates (only latest matters)
// UNLIMITED — audit log (never drop)
fun main() { println("Choose based on your loss tolerance and timing needs") }Channel in select
select allows waiting on multiple channels simultaneously, taking the first one ready.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.selects.*
fun main() = runBlocking {
val a = produce { delay(100); send("from a") }
val b = produce { delay(50); send("from b") }
val result = select<String> {
a.onReceive { it }
b.onReceive { it }
}
println(result) // "from b"
coroutineContext.cancelChildren()
}Ticker Channel
ticker(delay) creates a channel that emits Unit every delay milliseconds — useful for repeated polling.
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
val ticker = ticker(delayMillis = 100, initialDelayMillis = 0)
var count = 0
for (tick in ticker) {
println("Tick ${++count}")
if (count == 3) { ticker.cancel(); break }
}
}Quick Check
Which channel type keeps only the most recent value?
Recap
Rendezvous: synchronized, no buffer. Buffered: decouple timing. Conflated: latest value only, drops old. Unlimited: never suspend sender. Choose based on your loss tolerance and throughput needs.
Frequently asked questions
Is the “Channel Types: Rendezvous, Buffered, Conflated, Unlimited” lesson free?
Yes — the full text of “Channel Types: Rendezvous, Buffered, Conflated, Unlimited” is free to read here on the web, and the Kotlin Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Academy course, upgrade to CoddyKit PRO.
What will I learn in “Channel Types: Rendezvous, Buffered, Conflated, Unlimited”?
Choose the right channel type for your communication pattern. You practise Kotlin Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Academy?
No prior experience is required. Kotlin Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Channel Types: Rendezvous, Buffered, Conflated, Unlimited” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Academy lesson?
Yes. Every Kotlin Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Channel Basics: send, receive, and close
- Channel Types: Rendezvous, Buffered, Conflated, Unlimited
- Mutex and Semaphore for Shared State
- Actors and Structured State Management