Community연구 & 데이터 분석github.com

Kafka 컨슈머/프로듀서 구축

신뢰할 수 있는 Apache Kafka 컨슈머와 프로듀서를 구축합니다 — 컨슈머 그룹 및 파티션 할당, 오프셋 커밋 전략, 최소 한 번 전송 vs 정확히 한 번 전송, 멱등/트랜잭셔널 프로듀서, 리밸런싱, 데드레터 처리 등을 다룹니다. Kafka 컨슈머/프로듀서를 작성하거나, 오프셋 커밋 또는 컨슈머 그룹을 구성하거나, 처리량을 튜닝하거나, 리밸런스 및 포이즌 메시지를 처리할 때 사용하세요.

프로듀서 구축란 무엇인가요?

이 스킬은 개발자가 Apache Kafka 기반의 안정적인 컨슈머와 프로듀서를 설계하고 구현할 수 있도록 돕는 가이드입니다. 오프셋 커밋 전략, 컨슈머 그룹 병렬 처리, 리밸런싱 대응, 데드레터 라우팅 등 운영 환경에서 자주 마주치는 문제를 해결하는 방법을 제시합니다. 주요 패턴으로는 수동 오프셋 커밋, 멱등적 싱크, 트랜잭셔널 프로듀서를 포함하며, 최소 한 번 전송과 정확히 한 번 전송 보장 간의 차이를 명확히 설명합니다. 또한 자동 커밋과 느린 처리로 인한 메시지 유실, 파티션 수 초과로 인한 소비자 유휴, 폴 간격 초과로 인한 무한 리밸런스 등 일반적인 실수를 피하는 방법을 다룹니다. 이 스킬은 일반 Kafka 클라이언트(Java, Python 등)를 사용하는 모든 환경에서 적용 가능하며, 실무에서 바로 활용할 수 있는 구체적인 코드 예제와 워크플로를 제공합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Unknown-333/awesome-data-engineering-skills/tree/main/skills/building-kafka-consumers

Installed? Explore more 연구 & 데이터 분석 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Kafka 컨슈머 구축하기

사용 시기

  • Kafka 컨슈머/프로듀서를 작성하거나 디버깅할 때
  • 오프셋 커밋 전략과 전달 보장을 선택할 때
  • 컨슈머 그룹 병렬 처리, 리밸런싱, 또는 데드레터 처리를 튜닝할 때
  • 스트림 프로세싱/윈도잉에는 사용하지 마세요 (processing-streaming-data 사용)

워크플로

- [ ] 타겟 병렬 처리량에 맞게 파티션 크기 조정 (컨슈머 수 <= 파티션 수)
- [ ] 성공적인 처리 후에 오프셋 커밋
- [ ] 싱크를 멱등적으로 만들기 (이벤트 키 기준 upsert)
- [ ] 리밸런스 처리 (revoke 시 커밋, 긴 poll 간격 방지)
- [ ] 포이즌 메시지를 데드레터 토픽으로 라우팅
  1. 파티션이 병렬 처리량을 결정합니다. 컨슈머 그룹은 파티션 수까지만 확장 가능하며, 추가 컨슈머는 유휴 상태가 됩니다. 피크 처리량에 맞춰 파티션을 선택하세요.
  2. 처리 후에 커밋하세요. 작업이 안전하게 완료된 후에 오프셋을 커밋하고, 그 전에 커밋하지 마세요 — 일찍 커밋하면 크래시 시 메시지가 유실됩니다.
  3. 멱등적 싱크. 최소 한 번 전송은 재시도 시 중복을 의미합니다. 안정적인 이벤트 키로 upsert하여 재처리가 무해하도록 만드세요.
  4. 리밸런스는 발생합니다. 파티션 revoke 시 커밋하고 poll() 간격을 max.poll.interval.ms 미만으로 유지하여 브로커가 컨슈머를 축출하지 못하게 하세요.
  5. 포이즌 메시지는 오류와 함께 데드레터 토픽으로 전송하여, 하나의 잘못된 레코드가 파티션 전체를 막지 못하게 하세요.

패턴

처리 후 수동 커밋:

consumer = KafkaConsumer("orders", group_id="etl",
                         enable_auto_commit=False,
                         max_poll_records=500)
for msg in consumer:
    try:
        upsert(process(msg))          # 키 기준 멱등 처리
        consumer.commit()             # 성공 후에만 커밋
    except PoisonError:
        send_to_dlq(msg)
        consumer.commit()             # 잘못된 레코드는 건너뜀

멱등적 / 트랜잭셔널 프로듀서 — enable.idempotence=true를 설정하여 (재시도 중복 제거) 트랜잭션을 사용해 토픽 간 읽기-처리-쓰기 정확히 한 번을 구현합니다.

처리량 튜닝 — max.poll.records, fetch.min.bytes를 늘리고 배치로 처리하세요. 리밸런스 축출을 피하기 위해 처리를 빠르게 유지하세요.

일반적인 함정

  • 자동 커밋 + 느린 처리 — 오프셋이 작업 완료 전에 진행되어 크래시 시 메시지가 유실됩니다. 처리 후 수동 커밋을 선호하세요.
  • 파티션 수보다 많은 컨슈머 — 여분의 컨슈머는 유휴 상태가 됩니다. 확장을 위해 파티션을 재분배하세요.
  • poll 사이의 긴 처리 시간 — max.poll.interval.ms를 초과하여 무한 리밸런스를 유발합니다. 제한된 배치로 처리하거나 백그라운드 워커를 사용하세요.
  • 데드레터 경로 없음 — 하나의 포이즌 메시지가 전체 파티션을 차단합니다.
  • 멱등적 싱크 없이 정확히 한 번 전송에 의존 — 최소 한 번 전송 단계가 있으면 중복이 다시 발생합니다.

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

Unknown-333/authoring-airflow-dags

Write production-grade Apache Airflow DAGs using the TaskFlow API — idempotent tasks, correct scheduling and catchup, retries/SLAs, connections/variables, and avoiding top-level code. Use when creating or reviewing Airflow DAGs, scheduling pipelines, wiring task dependencies, configuring retries/backfills, or fixing non-idempotent tasks.

Unknown-333/building-dagster-assets

Build Dagster pipelines using software-defined assets — asset dependencies, partitions, resources and IO managers, asset checks, and schedules/sensors. Use when creating Dagster assets or jobs, modeling data as assets, adding partitions or backfills, wiring resources/IO managers, or migrating from task-based orchestration to assets.

Unknown-333/building-dbt-models

Build well-structured dbt models — staging/intermediate/marts layers, ref() and source(), materializations, and incremental models with the right strategy. Use when creating or refactoring dbt models, choosing table vs view vs incremental, structuring a dbt project, or writing incremental logic.

Unknown-333/building-feature-pipelines

Build ML feature pipelines and feature stores — point-in-time-correct joins to avoid label leakage, offline/online parity, feature freshness and backfills, and materialization with tools like Feast. Use when engineering features for ML, preventing train/serve skew or data leakage, building a feature store, or backfilling historical features for training.

Unknown-333/building-iceberg-tables

Design and operate Apache Iceberg tables — partitioning and hidden partitioning, partition/schema evolution, snapshots and time travel, compaction and small-file cleanup, and MERGE/upsert for lakehouse tables on Spark, Flink, Trino, or Snowflake. Use when creating or maintaining Iceberg tables, choosing partitioning, evolving schema/partitions, or fixing small-file and metadata bloat.

Unknown-333/building-ingestion-pipelines

Build batch and incremental data ingestion (extract-load) pipelines — full vs incremental extraction, change data capture (CDC), watermarks and high-water marks, API pagination and rate limits, and choosing managed EL tools (Fivetran, Airbyte) vs custom code. Use when ingesting data from databases, APIs, files, or SaaS into a warehouse/lake, or designing incremental extraction and CDC.

Unknown-333/debugging-data-pipelines

Systematically root-cause data pipeline failures and data incidents — job errors, wrong or missing data, duplicates, and freshness misses — by tracing lineage upstream, isolating the failing stage, reconciling against source, and planning a safe fix and backfill. Use when a pipeline fails, numbers look wrong, data is missing or duplicated, a dashboard is stale, or a stakeholder reports a data discrepancy.

Unknown-333/designing-backfills-and-replays

Plan and run safe data backfills and replays — idempotent reprocessing of historical windows, partition-by-partition execution, isolating backfill compute from production, verifying results, and avoiding double-counting or changed history. Use when backfilling a new or fixed model, reprocessing after a bug, replaying events, or loading history for a new pipeline without corrupting existing data.

Unknown-333/designing-data-contracts

Define and enforce data contracts between producers and consumers — explicit schema, semantics, ownership, SLAs, and versioning — to prevent silent upstream changes from breaking downstream pipelines. Use when a producer schema change could break consumers, defining an interface between teams/services and the warehouse, or adding schema enforcement at ingestion.

관련 스킬