title: mark end of logical section at kafka when multiple partitions are used
body: <p>I want to share a problem and a solution I used, as I think it may be beneficial for others, if people have any other solutions please share.</p>
  <p>I have a table with 1,000,000 rows, which I want to send to kafka, and spread the data between 20 partitions.
  I want to notify the consumer when producer reached end of data, I don't want to have direct connection between producer and consumer.</p>
  <p>I know kafka is designed as logical endless stream of data, but I still need to mark the end of the specific table.</p>
  <p>There was a suggestion to count the number of items per logical section, and send this data (to a metadata topic), so the consumer will be able to count items, and know when the logical section ended.</p>
  <p>There are several disadvantages for this approach:</p>
  <ol>
  <li><p>As data is spread between partitions, I can tell there are total x items at my logical section, however if there are multiple consumers (one per partition), they'll need to share a counter of consumed messages per logical section. I want to avoid this complexity. Also when consumer is stopped and resumed, it will need to know how many items were already consumed and keep context.</p>
  </li>
  <li><p>Regular producer session guarantees at-least-once delivery, which means I may have duplicated messages. Counting the messages will need to take this into account (and avoid counting duplicated messages).</p>
  </li>
  <li><p>There is also the case where I don't know in advance the number of items per logical session, (I'm also kind of consumer, consuming stream of event and signaled when data ended), so at this case, the producer will also need to have a counter, keep it when stopped and resumed etc. Having several producers will need to share the counter etc. So it adds a lot of complexity to the process.</p>
  </li>
  </ol>