Terminologies

A few terms are used in Kafka you need to know.

  • Message: A stream of bytes. For simplicity, assume it as a string.
  • Producer: The application or client that produces messages which will be consumed by other clients.
  • Consumer: A client who receives the messages produced by the producers.
  • Broker: Receives the messages, stores it, and decides the consumers who should get these messages.
  • Topic: A unique name through which the data is streamed.
  • Partition: A Partition is a virtual division which allows parallelizing a topic by splitting the data in a particular topic across multiple brokers. A topic can have multiple partitions. Minimum of 1.
  • Offset: A unique number for a message in a topic’s partition.
  • Consumer Group: A group of consumers.
  • Leader: The responsible unit for the topic’s partitions to store messages.
  • Replica: The mirror/sync of your data to handle the faults. So that the data doesn’t get lost.
  • In-Sync Replica(ISR) (Replication Group): The in-sync replicas are replicas that are alive and are in sync with the leader.

 

중요 포인트

  • 토픽으로 통하는 모든 데이터의 read/write는 오직 리더와 이루어진다.
  • ISR 내의 모든 follower들은 누구라도 리더가 될 수 있다.
  • 자신이 읽고 있는 파티션에는 같은 그룹내 다른 컨슈머가 읽을 수 없다.
  • 한번 늘린 파티션은 절대로 줄일 수 없기 때문에 운영중에 파티션을 늘리는 것은 충분히 고려해야한다.
  • 파티션에 순차적으로 메세지가 쓰여지지 않는다. 곧 컨슈머가 메세지를 순서대로 읽지 못할수있다.
  • 파티션 개수 >= 컨슈머 개수
  • 여러개의 컨슈머 그룹은 동일한 레코드를 받는다. 이때 각 컨슈머 그룹마다 별도로 오프셋 관리를 한다.

 

토픽, 리플리케이션 팩터, 카프카 클러스터 한눈에 정리

Topic Peter-Topic01 Peter-Topic02
파티션 수 2 2
레플리케이션 팩터 3 2
브로커 수 3 3

토픽의 파티션 리더의 위치를 유심히 보자
Kafka replication example
파티션 개수는 컨슈머 개수보다 크거나 같다

Offset 이란?

Partition 의 특정 Consumer 가 메세지를 읽어들인 위치를 나타냄. Consumer 가 메세지 수신 처리를 재개할 때 어떤 메세지 부터 가져 가야 하는 지 알 수 있음.

 

Offset Topic

Kafka 에는 Consumer 의 offset 을 저장 하는 topic 이 존재함. (v0.9 release)

  • __consumer_offsets
    • 일반 토픽처럼 partitioning, replication 되어 있음(offsets.topic.replication.factor=1 (default=1)
      • Consumer 가 Kafka에 현재까지 읽은 메세지의 offset 정보를 알려주는 것을 commit 이라 한다.

 

 

'빅데이터 > Kafka Cluster' 카테고리의 다른 글

Kafka restart과 retention  (0) 2022.02.28
Kafka 스트레스 테스트  (0) 2022.02.28
Kafka Consumer/Producer  (0) 2022.02.28
Kafka 자주 사용하는 명령  (0) 2022.02.28
Kafka cluster failover  (0) 2022.02.28

Kafka에서는 토픽별로 leader와 follower가 존재한다.

토픽으로 통하는 모든 데이터의 read/write는 오직 leader와 이루어진다. leader가 다운되거나 leader가 있는 브로커가 다운된다면 flower 중의 하나가 leader가 된다.  이때, 일시적으로 follower가 leader가 되는 과정에서 read/write의 timeout이 발생할 수 있겠지만, retry가 일어나면 new leader와 read/write가 가능하기 때문에 장애 상황을 피할 수 있다.

 

ISR(In Sync Replica)

topic이 생성되고 옵션으로 replication factor를 설정하면 replication factor 수에 맞추어 ISR이 구성된다. 

leader : follower 중에서 자신보다 일정시간 동안 뒤쳐지면 leader가 될 자격이 없다고 판단하여 뒤쳐지는 follwer를 ISR에서 제외

follower : leader와 동일한 데이터 내용을 유지하기 위해서 짧은 주기로 leader로부터 데이터를 가져온다.

 

All down

1. 마지막까지 leader였던 broker1번이 up이 되고 다시 leader가 될 때까지 기다린다.

2. (default)ISR과 상관없이 누구라도 가장 빨리 up이 되는 topic이 leader가 된다(데이터 손실이 되더라도 장애 대응이 빠르다)


출처 : https://www.popit.kr/kafka-%EC%9A%B4%EC%98%81%EC%9E%90%EA%B0%80-%EB%A7%90%ED%95%98%EB%8A%94-topic-replication/

'빅데이터 > Kafka Cluster' 카테고리의 다른 글

Kafka restart과 retention  (0) 2022.02.28
Kafka 스트레스 테스트  (0) 2022.02.28
Kafka Consumer/Producer  (0) 2022.02.28
Kafka 자주 사용하는 명령  (0) 2022.02.28
Kafka Overview  (0) 2022.02.28

+ Recent posts