     end
   end
 
+  # OTP setup
   use Application
 
+  # aliases for convenience
   alias KafkaEx.ConsumerGroup.PartitionAssignment
   alias KafkaExExamples.Consumer
 
   require Logger
 
+  # standard OTP Application.start/2 callback
   def start(_type, _args) do
     import Supervisor.Spec
 
     consumer_group_opts = [
+      # commit relatively often to make demonstration easy
       commit_interval: 1_000,
+      # same with a relatively quick heartbeat rate
       heartbeat_interval: 1_000,
+      # name for process registration
       name: ExampleConsumerGroup,
+      # name for the Manager process (for convenience)
       gen_server_opts: [name: ExampleConsumerGroup.Manager],
+      # override the partition assignment callback (optional, see below)
       partition_assignment_callback: &assign_partitions/2,
+      # how long before Kafka considers a consumer gone
       # must be >= group.min.session.timeout.ms from broker config
       session_timeout: 6_000
     ]
 
+    # standard OTP supervisor setup
     children = [
       supervisor(
         KafkaEx.ConsumerGroup,

defmodule KafkaExExamples do
  @moduledoc """
  Documentation for KafkaExExamples.
  """

  defmodule KafkaExExamples.Consumer do
    use KafkaEx.GenConsumer

    alias KafkaEx.Protocol.Fetch.Message

    require Logger

    def handle_message_set(messages, consumer_state) do
      for  message = %Message{} <- messages do
        Logger.debug(fn -> "GOT: #{inspect message}" end)
      end

    Supervisor.start_link(children, supervisor_opts)
  end

  @doc """
  Partition assignment callback

  This is optional.  We choose to override it here so that we can use it as a
  hook to log a message.  This could be used for, e.g., collecting metrics in
  a production system.
  """
  def assign_partitions(members, partitions) do
    # call through to the default KafkaEx partition assignment algorithm
    result = PartitionAssignment.round_robin(members, partitions)

    # log out the assignments for demonstration purposes
    Logger.debug(fn ->
      "ASSIGN: #{inspect members} | #{inspect partitions} | #{inspect result}"
    end)

    # return the assignment result
    result
  end
end
