Section 3 : Consumers Flashcards

1
Q

How do Kafka Consumers work?

A
  • Kafka consumers is an application that consumes messages (generated by producers) by subscribing to a topic.
  • Step 1: Create a Kafka consumer object
  • Step 2: Subscribe/assign to the topic (Depending upon whether it’s standalone consumer or part of consumer group)
  • Step 3: Start receiving messages
  • Step 4: Validate message
  • Step 5 : Send for further processing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Kafka Consumer?

A
  • Consumer can be either standalone consumer or can be part of a consumer group but not both at the same time
  • Standalone consumer:
    • Simple to implement
    • No need for rebalancing
    • Needs to find partitions by itself:
      • Uning consumer.partitionsFor() periodically
    • Consumer assigns partitions to itself
      • using assign() method as it’s the only consumer which needs to read all records from the all the partitions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are Kafka Consumer Group?

A
  • Consumer group is a group of consumers all of which read from the same topic.
  • You add consumer to help deal with the load
  • Kafka can scale to a large number of consumer and consumer groups without reducing performance.
  • If Number of consumer in the group > number of partitions of the topic, some of the consumer may be iddle [Though having 1 or 2 idle consumers in the consumer group is recommended]
  • Create a new consumer group for each application that needs all the messages from one or more topics consumers to an existing consumer
  • Consumer group is to scale the reading and processing of messages from topics.
  • To maintain membership to consumer group and to maintain ownership of the partitions assigned, consumers send heartbeats to the Group coordinator.
    • Heartbeats are sent:
      • When the consumer polls
      • When consumer commits records it has consumed
      • Release 0.10.1 onwards, heartbeats can be sent in between polls as well
      • If heartbeat are not received for soemtime, the repartition is triggered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Partition Rebalance?

A
  • Moving partition ownership from one consumer to another is called Partition Rebalancing
  • When Partition Rebalancing comes into picture?
    • When a new consumer is added to the group
    • When a consumer shuts down
    • When a consumer crashes
    • When a consumer leaves the consumer group
    • When the topics are modified
    • When a new partition is added
  • Why Partition Rebalancing?
    • To enable consumer group for high availability and scalability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Partition Rebalance Functioning?

A
  • The consumer sends “JoinGroup request” to the group Coordinator
  • The first consumer in the group becomes the group leader
  • Leader consumer gets the following:
    • List of consumers in the groups
    • List of partition assignments
  • Group leader decides partition/ set of partition to the other consumers in the group.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Partition Rebalance Issues?

A
  • Unavailability
    • During rebalancing process entire consumer group is unavailable
  • Loosing state
    • Consumer looses it’s current state
  • Impact on performance
    • Looses cache and hence slows down the preformance for a while
  • Partition rebalance is not desired and should be avoided
How well did you know this?
1
Not at all
2
3
4
5
Perfectly