이동진
-
카프카 핵심 가이드 5 : 멱등성책책책 책을 읽읍시다/프로그래밍 2023. 6. 12. 23:07
8. '정확히 한 번' 의미 구조 멱등적 프로듀서 멱등성 의미 구조가 아닌 '최소 한 번' 의미 구조를 가지도록 프로듀서를 설정한다면, 프로듀서가 메세지 전송을 재시도함으로써 메세지가 최소 한 번 이상 도착할 수 있는 불확실성이 존재하게 된다. 이렇게 재시도는 메세지 중복으 발생시킬 수 있다. 가장 고전적인 경우리면, 이런 경우가 있겠다. 파티션 리더가 프로듀서로부터 레코드를 받아서 팔로워들에게 성공적으로 복제한다. 프로듀서에게 응답을 보내기 전, 파티션 리더가 있는 브로커에 크래시가 발생한다. 프로듀서 입장에서는 응답을 받지 못한 채 타임아웃이 발생하고, 메세지를 재전송한다. 재전송된 메세지가 새 리더에 도착한다. 하지만 이 메세지는 이미 저장되어 있다(결과적으로, 중복이 발생한다). 어떤 애플리케..
-
카프카 핵심 가이드 4 : 내부 메커니즘책책책 책을 읽읍시다/프로그래밍 2023. 6. 11. 15:47
6. 내부 메커니즘복제 복제는 카프카 아키텍처의 핵심이다. 실제로 카프카는 '분산되고, 분할되고, 복제된 커밋 로그 서비스'로 표현되기도 한다. 복제가 중요한 이유는 개별적인 노드에 필연적으로 장애가 발생할 수밖에 없는 상황에서 카프카가 신뢰성과 지속성을 보장하는 방식이기 때문이다. 카프카에 저장되는 데이터는 토픽을 단위로 해서 조직화한다. 각 토픽은 1개 이상의 파티션으로 분할되며, 각 파티션으 다시 다수의 레플리카를 가질 수 있다. 각각의 레플리카는 브로커에 저장되는데, 대개 하나의 브로커는 (서로 다른 토픽과 파티션에 속하는) 수백 개에서 심지어 수천 개의 레플리카를 저장한다. 레플리카에는 두 종류가 있다.리더 레플리카 : 각 파티션에는 리더 역할을 하는 레플리카가 하나씩 있다. 일관성을 보장하기 ..
-
카프카 핵심 가이드 3 : 컨슈머책책책 책을 읽읍시다 2023. 6. 11. 01:23
카프카 컨슈머: 개념컨슈머와 컨슈머 그룹 카프카 토픽으로부터 메세지를 읽어서 몇 가지 검사를 한 후, 다른 데이터 저장소에 저장하는 애플리케이션을 개발해야 한다고 가정해 보자. 이 경우 애플리케이션은 컨슈머 객체(KafkaConsumer 인스턴스)를 생성하고, 해당 토픽을 구독하고, 메세지를 받기 시작한 뒤 받은 메세지를 받아 검사하고 결과를 써야 한다. 한동안이야 잘 작동하겠지만, 만약 프로듀서가 애플리케이션이 검사할 수 있는 속도보다 더 빠른 속도로 토픽에 메세지를 쓰게 된다면 어떻게 될까? 만약 데이터를 읽고 처리하는 컨슈머가 하나뿐이라면 애플리케이션은 새로 추가되는 메세지의 속도를 따라잡을 수 없기 때문에 메세지 처리가 계속해서 뒤로 밀리게 될 것이다. 따라서, 우리는 토픽으로부터 데이터를 읽어 ..
-
카프카 핵심 가이드 2 : 프로듀서책책책 책을 읽읍시다/프로그래밍 2023. 6. 9. 21:35
3. 카프카 프로듀서: 카프카에 메세지 쓰기카프카 프로듀서 생성하기 카프카에 메세지를 쓰려면 우선 원하는 속성을 지정해서 프로듀서 객체를 생성해야 한다. 카프카 프로듀서는 아래의 3개의 필수 속성값을 갖는다.bootstrap.servers 카프카 클러스터와 첫 연결을 생성하기 위해 프로듀서가 사용할 브로커의 host:port 목록이다. 이 값은 모든 브로커를 포함할 필요는 없는데, 프로듀서가 첫 연결을 생성한 뒤 추가 정보를 받아오게 되어 있기 때문이다. 다만 브로커 중 하나가 작동을 정지하는 경우에도 프로듀서가 클러스터에 연결할 수 있도록 최소 2개 이상을 지정할 것을 권장한다.key.serializer 카프카에 쓸 레코드의 키의 값을 직렬화하기 위해 사용하는 시리얼라이저(serializer) 클래스의..
-
카프카 핵심 가이드 1 - 카프카 입문책책책 책을 읽읍시다/프로그래밍 2023. 6. 6. 15:53
저자 : 그웬 샤피라(Gwen Shapira), 토드 팔리노(Todd Palino), 라지니 시바람(Rajini Sivaram), 크레트 페티(Krit Petty) 옮긴이 : 이동진 들어가며 아파치 카프카 관련 다른 책들은 안 읽어봤는데, 이 책만으로도 카프카 기반 지식은 꽤 많이 얻어갈 수 있었다. Real MySQL처럼 각 기능에 대해 세세하고 적용점 예시까지는 안나와있지만, 기본 원리와 주의사항들은 잘 나와있는 편이다. 더 깊게 공부하려면 공식 문서와 코드레벨을 봐야할 것 같다. 초중반부가 카프카를 메세지 브로커로 사용하는 개발자에게 유용한 토픽, 파티션, API 등에 대해 나와있고, 후반부는 모니터링과 클러스터링 등 인프라적인 내용이 많이 서술되어 있다. 발췌 내용 정리 1. 발행/구독 메세지 전..