Introducing a new way to review your PRs.

Read the announcement

aio-libs / aiokafka

asyncio client for kafka

View on GitHub

19 documents · Updated Nov 23, 2026

overview

Knowledge Base updated: 2026-11-22

aiokafka knowledge base

aiokafka is an asyncio-native Python client for Apache Kafka. Its public producer, consumer, and admin clients share a metadata-aware network client, Kafka protocol codecs, and record encoding support.

Critical runtime state lives in producer accumulators and transaction management, consumer subscription/fetch/group-coordinator state, and the shared client's cluster metadata and broker connections.

System architecture

flowchart TD
  App[Application] --> Producer[AIOKafkaProducer]
  App --> Consumer[AIOKafkaConsumer]
  App --> Admin[AIOKafkaAdminClient]
  Producer --> Accumulator[MessageAccumulator]
  Producer --> Sender[Sender]
  Producer --> Txn[TransactionManager]
  Consumer --> Fetcher[Fetcher]
  Consumer --> Coordinator[GroupCoordinator]
  Consumer --> Subscription[SubscriptionState]
  Admin --> Client[AIOKafkaClient]
  Sender --> Client
  Fetcher --> Client
  Coordinator --> Client
  Client --> Cluster[ClusterMetadata]
  Client --> Conn[Broker Connection]
  Conn --> Kafka[Kafka brokers]
flowchart LR
  Send[producer.send] --> Batch[Record batch accumulator]
  Batch --> Sender[Sender]
  Sender --> Request[Produce request]
  Request --> Broker[Broker]
  Broker --> Response[Produce response]
  Response --> Result[Delivery future]
flowchart LR
  Subscribe[subscribe or assign] --> State[SubscriptionState]
  State --> Coord[GroupCoordinator]
  Coord --> Fetcher[Fetcher]
  Fetcher --> Records[Consumer records]
  Records --> Position[Partition positions]
  Position --> Commit[Offset commit]

Glossary

  • Accumulator: per-topic-partition producer buffering that forms record batches before sending.
  • SubscriptionState: consumer-owned state for subscriptions, assignment, seek positions, and partition fetchability.
  • GroupCoordinator: consumer component that manages group membership, heartbeats, rebalances, and committed offsets.
  • TransactionManager: producer state machine for idempotent sequencing and Kafka transactions.
  • ClusterMetadata: the shared representation of brokers, topic partitions, leaders, and coordinator locations.

Codebase-wide invariants

Routing table