Effective governance is presented as essential for Kafka-based data platforms. As organizations depend on real-time streams, they need structured practices that preserve data integrity, ensure producer–consumer compatibility, secure access to data, and prevent any single client from exhausting shared resources. The chapter motivates this with concrete failure modes—schema drift breaking consumers, weak security leading to data exposure, and uncontrolled clients overloading brokers—framing governance as both a technical necessity and a business reliability imperative.
The chapter positions schema governance as the backbone of interoperability. It emphasizes documenting schemas centrally, planning for evolution, and choosing explicit compatibility strategies (none, backward, forward, full, including transitive variants) because Kafka retains historical data and supports many independent producers and consumers. Schema registries are introduced as the source of truth that version schemas, check compatibility, and integrate with clients, while also noting operational trade-offs (complexity, opaque IDs, migration challenges). Avro’s self-describing model and registry-backed IDs are used to illustrate efficient, traceable evolution. For enforcement, patterns include limiting write access, broker-side validation in commercial distributions, or validation via Kafka proxies, and teams are urged to route schema changes through CI/CD rather than allowing ad hoc version creation.
Security guidance spans transport encryption with TLS, client authentication via mutual TLS or SASL mechanisms (Kerberos, OpenID Connect, SCRAM), and least-privilege authorization with ACLs, along with pragmatic advice on encrypting data at rest, when true end-to-end encryption must be implemented in clients, and how to handle key management. The chapter also explains securing ZooKeeper where applicable and outlines a zero-downtime path to migrate from an unsecured to a secured cluster using additional listeners and staged client cutovers. Finally, it covers quotas as safeguards against overload—per-user/client byte-rate and request-percentage limits enforced per broker, using conservative defaults with targeted exceptions, understanding throttling behavior, and monitoring throttle-time metrics—so that clusters are protected from misconfigurations without penalizing healthy workloads.
We start with a simple JSON object for a product. Based on this, we can add, delete, or modify fields. From the beginning, we should consider which schema changes should be supported and what the process for this looks like.
We consider schema compatibility from the consumer's perspective and which schema versions they can understand. If we cannot or do not want to guarantee any compatibility, a consumer can only understand their own schema version. A backward-compatible consumer can read historical data but cannot handle newer data. A forward-compatible consumer can read new data, but not historical data. The optimum is a consumer that can read both historical and new data, which is fully compatible in both directions.
Securing a Kafka cluster involves transport encryption for communication, user authentication and authorization, and, lastly, encryption of data at rest.
An encryption proxy can reduce the risk of using an untrusted Kafka provider.
Required steps to secure an unsecured Kafka cluster.
Summary
Proper schema management in Kafka helps ensure data consistency and compatibility.
Using schema registries allows for the centralized management of data schemas, enabling easier updates.
Schemas facilitate versioning, allowing producers and consumers to evolve independently without breaking changes.
Compatibility checks can be enforced to prevent incompatible schema updates that might lead to data issues.
Schemas can be serialized in different formats, such as Avro or JSON, enhancing interoperability across systems.
Transport Layer Security (TLS) utilizing encryption, authentication, and authorization is mandatory for safeguarding data in Kafka.
Authentication in Kafka can be implemented using various mechanisms, such as Simple Authentication and Security Layer (SASL), to verify the identity of clients and ensure secure connections.
Authorization is managed through Access Control Lists (ACLs) to regulate which users or applications can access specific Kafka resources, ensuring only authorized actions are permitted.
Data at rest must be encrypted using underlying storage systems, as Kafka lacks native support for this.
End-to-end encryption is recommended to secure sensitive data, implemented at the client level.
The key management process for encryption requires careful handling, potentially utilizing tools like Vault.
Zookeeper must be secured as it stores critical Kafka metadata and transmits data unencrypted by default. Kafka 2.5 and later supports TLS connections for secure communication with Zookeeper, and mutual TLS is advised for broker-to-Zookeeper communication.
It is possible to migrate from an unsecured Kafka cluster to a secured one without impacting availability, by sequentially configuring TLS listeners and restarting brokers.
Quotas are essential for protecting Kafka clusters from excessive load caused by misconfigured or malicious clients.
Quotas can limit the number of produce or consume requests and restrict CPU time on brokers.
Quotas can be set at the client ID level or user level. User-level quotas provide better reliability.
Kafka brokers monitor throttle-time metrics to detect and manage quota violations effectively.
Care must be taken when setting quotas, as overly aggressive limits can disrupt service and lead to cascading failures.
FAQ
What is Kafka governance and why does it matter?Governance is the set of practices that ensure data integrity, security, and fair resource usage across Kafka. Without it, you risk incompatible schema changes that break consumers, unauthorized access and data leaks, and resource hogging that degrades cluster performance. Good governance aligns producers and consumers on schemas, protects data with authentication/authorization and encryption, and prevents overload through quotas.How should schemas be documented and discovered in Kafka?Provide a central, discoverable place for topic schemas and their documentation—such as a schema registry, a corporate wiki, a dedicated portal, or a Git repo. For each schema, define:
- Ownership and purpose
- Compatibility level (and what it implies for producer/consumer rollout order)
- Version history and change process
This shared “source of truth” reduces breakages and accelerates onboarding.What schema compatibility levels should I know, and what changes do they allow?From a consumer’s perspective:
- No compatibility: Anything goes; consumers must always be in lockstep with producers. Breaks historical reads.
- Backward compatibility: New consumers can read older data. Typical safe change: remove required fields; do not add new required fields.
- Forward compatibility: Old consumers can read new data. Typical safe change: add new fields (preferably optional or with defaults); do not remove required fields.
- Full compatibility: Consumers can read both older and newer data. Typically only add/remove optional fields.
Transitive modes (e.g., forward-transitive, full-transitive) extend guarantees across all future or past versions, not just adjacent ones.When do I need a new topic for schema changes?Create a new topic when a change breaks your declared compatibility level (for example, renaming fields or adding/removing required fields in ways that violate forward/backward/full guarantees). Then migrate data and move producers/consumers over in a coordinated fashion, similar to how you would handle a partition-count change.What is a schema registry, and what are the pros, cons, and options?A schema registry stores and versions schemas, enforces compatibility on new versions, and integrates with clients for serialization. Benefits:
- Single source of truth for schemas
- Automated compatibility checks
- Integration with Avro/JSON/Protobuf serializers
Trade-offs:
- Added component and operational complexity
- Migration challenges (IDs have no semantic meaning; manual export/import can change IDs)
- Limited built-in documentation/visualization
Common options:
- Confluent Schema Registry (feature-rich; licensing considerations for non-Confluent stacks)
- Karapace (API-compatible alternative, fewer features but sufficient for most)
- Apicurio (supports OpenAPI/AsyncAPI plus design tooling and richer docs)How does Avro work with Kafka and a schema registry?Avro messages are self-describing (schema + payload). To keep Kafka messages small, store the schema in the registry and send only the schema ID with each message. This preserves schema traceability over time without bloating messages. Avro works well in Kafka because topics often contain multiple schema versions over long retention periods.How can I ensure producers don’t bypass schemas and write invalid data?Since Kafka brokers handle bytes, schema checks happen client-side unless you add enforcement:
- Limit write access (Single Producer Pattern) to the topic owner team
- Use broker-side validation (available in Confluent Server/Cloud)
- Place a Kafka proxy that validates schemas (e.g., Conduktor Proxy, Kroxylicious)
Also, avoid allowing producers to auto-create new schema versions in production; manage versioning via CI/CD against the registry.How do I secure Kafka (authentication, authorization, and encryption)?Core layers:
- Transport encryption: TLS for client-broker and inter-broker traffic; plan certificate management (keystores/truststores, CA).
- Authentication: mTLS (clients present certificates) or SASL (GSSAPI/Kerberos, OAUTHBEARER/OpenID Connect, SCRAM, PLAIN with custom callback).
- Authorization: ACLs based on the authenticated principal; follow least privilege.
- Encryption at rest: Use OS/storage/cloud disk encryption (Kafka has no native feature). Proxies like Kroxylicious can add at-rest encryption from client perspective but are not true end-to-end.
- End-to-end encryption: Implement at client level (e.g., custom serializer/deserializer) and manage keys with a tool like Vault. Be aware encrypted data compresses poorly.
If migrating from an unsecured cluster, add a secure listener, migrate inter-broker traffic, reconfigure clients, shut down the old listener, then enable ACLs—carefully planned to avoid downtime.mTLS vs SASL for Kafka authentication: which should I use?mTLS:
- Pros: Strong, certificate-based mutual trust; often minimal extra effort if TLS is already in place; no external user store required.
- Cons: Certificate lifecycle management for every client.
SASL:
- SASL-GSSAPI (Kerberos) or SASL-OAUTHBEARER (OIDC) integrate with enterprise identity providers.
- SASL-SCRAM stores credentials in ZooKeeper/KRaft—simple to run, no external IDP needed.
- SASL-PLAIN requires a custom callback for validation.
Choose based on your org’s identity standards, tooling, and operational preferences.How do Kafka ACLs work, and what permissions do components usually need?ACLs answer: “Is principal X allowed/denied operation Y on resource Z (optionally by host)?” Typical needs:
- Brokers: ClusterAction on Cluster
- Producers: Topic:Write; add Cluster:IdempotentWrite for idempotent producers; Write on a TransactionalId for transactions
- Consumers: Topic:Read on topics + Group:Read on their consumer group
- Kafka Streams apps: Topic:Create on application ID prefix for internal topics, plus necessary Read/Write as applicable
- CI/CD pipelines (provisioning): Create/Delete/Alter/AlterConfigs/Describe/DescribeConfigs on topics; Alter/Describe on Cluster (ACL mgmt); possibly AlterConfigs/DescribeConfigs on Cluster (quota mgmt)
Use the least-privilege principle and automate ACL provisioning.How do quotas protect a Kafka cluster, and how should I set and monitor them?Quotas throttle clients to prevent overload and ensure fairness:
- Scope: Per user/client and per broker (clients can multiply throughput by connecting to more brokers—quotas are protective, not billing-grade).
- Types: producer_byte_rate, consumer_byte_rate (bytes/sec); request_percentage (CPU share across I/O + network threads).
- Strategy: Set conservative defaults; override for heavier clients; prefer user-based quotas with authentication.
- On violation: Broker delays responses and mutes the connection briefly, restoring balance even with misbehaving clients.
- Monitoring: Watch throttle-time metrics (Produce/Fetch/Request). Non-zero indicates active throttling—often a misconfigured client. Tune quotas carefully; overly tight limits can cause cascading failures.
pro $24.99 per month
access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!