title: How to process a KStream in a batch of max size or fallback to a time window?
body: <p>I would like to create a Kafka stream-based application that processes a topic and takes messages in batches of size X (i.e. 50) but if the stream has low flow, to give me whatever the stream has within Y seconds (i.e. 5).</p>
  
  <p>So, instead of processing messages one by one, I process a <code>List[Record]</code> where the size of the list is 50 (or maybe less).</p>
  
  <p>This is to make some I/O bound processing more efficient.</p>
  
  <p>I know that this can be implemented with the classic Kafka API but was looking for a stream-based implementation that can also handle offset committing natively, taking errors/failures into account. 
  I couldn't find anything related int he docs or by searching around and was wondering if anyone has a solution to this problem.</p>