Tuning batchSize and maxAwaitTimeMS is important for efficient change stream consumption.
- A larger batchSize reduces roundtrips and improves throughput.
- A sensible maxAwaitTimeMS (e.g. 200–1000 ms) ensures low-latency delivery without keeping the cursor idle too long.
Together, they strike a balance between throughput, latency, and resource usage, which is crucial for high-load scenarios like the outbox pattern.
val changeStream = collection.watch()
.fullDocument(FullDocument.UPDATE_LOOKUP)
.maxAwaitTime(500, TimeUnit.MILLISECONDS) // max väntetid innan servern returnerar batchen
.batchSize(500) // antal events per batch
.iterator()
while (changeStream.hasNext()) {
val event = changeStream.next()
println("Got event: $event")
}
Tuning batchSize and maxAwaitTimeMS is important for efficient change stream consumption.
Together, they strike a balance between throughput, latency, and resource usage, which is crucial for high-load scenarios like the outbox pattern.