Kafka only moves bytes
Kafka has no notion of a record's structure. Serialisation is entirely a producer/consumer agreement, and the topic will happily accept anything.
That is a problem, because a topic is a long-lived contract read by teams you have not met, including consumers replaying data written months ago. A producer changing a field name is a breaking API change with no compile-time signal.
| Format | Self-describing | Schema evolution | Notes |
|---|---|---|---|
| JSON (plain) | Human-readable, unvalidated | None enforced | Fine for prototypes; verbose; drifts silently |
| Avro | No, needs schema | Strong, with a registry | Compact; common default for data platforms |
| Protobuf | No, needs schema | Strong, field-number based | Compact; good cross-language tooling |
| JSON Schema | Readable plus validated | Good | Compromise when readability matters |
Schema registry and compatibility
A schema registry stores versioned schemas and enforces a compatibility rule at registration time, so an incompatible producer fails at deploy rather than corrupting consumers at 3am.
| Mode | Allows | Use when |
|---|---|---|
| Backward | New schema reads old data | Consumers upgrade first (most common) |
| Forward | Old schema reads new data | Producers upgrade first |
| Full | Both | Strictest, safest for shared topics |
Practical rules that survive contact with reality: add optional fields with defaults; never reuse or renumber a field; never change a field's type in place — add a new field and migrate; and treat removing a required field as a breaking change requiring a new topic or a coordinated migration.
Bad records still happen, so consumers need a dead-letter topic. A deserialisation failure that throws in the poll loop will retry the same record forever and halt the partition — an entirely self-inflicted outage. Route the poison record aside, record enough context to debug it, and keep going.
Kafka Connect: do not write another integration service
Connect is a framework for moving data between Kafka and external systems using configuration instead of code. Source connectors pull data in; sink connectors push data out.
Postgres ──[source connector]──► Kafka ──[sink connector]──► Elasticsearch
│
└────[sink connector]──► S3
It runs as a cluster of workers, and gives you offset tracking, restarts, retries, scaling, and dead-letter handling for free. Reach for Connect before writing a bespoke consumer whose only job is "read topic, write to database" — that code is where subtle at-least-once bugs breed.
Change Data Capture connectors deserve a specific mention: reading a database's write-ahead log turns table changes into an event stream without dual-writes, which is usually far more reliable than having application code write to both the database and Kafka.
Kafka Streams: processing, not plumbing
Streams is a library (not a separate cluster) for transforming topics into topics. Two abstractions:
| Abstraction | Semantics | Backed by |
|---|---|---|
KStream | An unbounded sequence of events; each record is a fact | Normal topic |
KTable | Latest value per key; a changelog view | Compacted topic |
That KTable/compaction link is the same idea from the previous topic, showing up as an API. Streams also handles stateful operations — aggregations, joins, windows — by keeping local state stores backed by compacted changelog topics, so state survives restarts and rebalances.
Two things to know before adopting it: Streams instances are consumer group members, so all the partition and rebalance rules still apply, and Streams' exactly-once processing guarantee is Kafka transactions under the hood — it covers Kafka-to-Kafka, not your external side effects.
Use Streams for continuous transformation and enrichment. Use a plain consumer when the job is mostly "call an external system". Use Connect when the job is purely moving data.
Security: plaintext is a decision, not a default
A Kafka listener on PLAINTEXT with no authentication means anyone with network access can read every topic and write to any of them.
PLAINTEXT no encryption, no authentication → the entire event stream, readable
SSL/TLS encryption in transit, optional mutual auth
SASL_SSL authentication (SCRAM, GSSAPI, OAUTHBEARER) over TLS
Kafka topics concentrate risk in a way individual services do not: one orders topic may carry customer records, addresses, and payment references from every part of the business. Three things belong in any production setup:
- TLS on client and inter-broker listeners, so traffic is not readable on the wire.
- SASL authentication, so every client has an identity.
- ACLs granting least privilege per principal — read on the topics it consumes, write on the topics it produces, and access to its own consumer group only.
Also disable automatic topic creation (auto.create.topics.enable=false) in production. Otherwise a typo in a consumer's topic name creates a new topic with default partition and replication settings, and the real symptom is "my consumer reads nothing" with no error anywhere.
The failure modes that cause real incidents
| Symptom | Likely cause | First check |
|---|---|---|
| Events processed out of order | Null key, or key that is not the ordering unit | Are the events for one entity in one partition? |
| Ordering broke after a scale-up | Partition count increased, key-to-partition mapping shifted | Compare partition count before and after |
| Lag grows while consumers idle | More consumers than partitions | Partition count versus group size |
| Group rebalances constantly | Processing exceeds max.poll.interval.ms | Batch duration versus max.poll.records |
| Records missing after broker restart | acks=1, or min.insync.replicas=1 | Producer acks and topic config |
| Duplicate side effects | Auto-commit, or non-idempotent consumer | Commit strategy and dedup design |
| Consumer stuck on one record forever | Poison message with no dead-letter path | Deserialisation error handling |
| One partition lags badly | Key skew, hot partition | Per-partition lag |
| Under-replicated partitions | Slow or failing broker, network, disk | Broker metrics, ISR shrink events |
| Producer blocks or throws on send | Buffer full because brokers are slow | buffer.memory, max.block.ms, broker health |
| New consumer processed nothing historical | auto.offset.reset=latest on a fresh group | Group's committed offsets |
| Disk full on a broker | Retention or retention.bytes under-estimated | Storage arithmetic per partition |
What to monitor
Four signals cover most of the ground:
- Consumer lag per partition — the primary consumer SLI. Alert on sustained growth, not absolute value.
- Under-replicated partitions — the primary broker durability signal. Should be zero.
- Rebalance rate per group — a rising rate means the group is thrashing.
- Broker disk usage trend and produce/fetch latency — the two things that turn a healthy cluster into an outage.
Design checklist before creating a topic
[ ] What is the ordering unit? → that is the key
[ ] Partition count sized for throughput AND future consumer parallelism
[ ] Events (delete + retention) or state (compact)?
[ ] Retention long enough to cover worst-case replay
[ ] replication.factor=3, min.insync.replicas=2, acks=all
[ ] Schema and compatibility mode agreed
[ ] Consumer idempotence strategy
[ ] Dead-letter topic and poison-message path
[ ] TLS, SASL, and least-privilege ACLs
[ ] Lag and under-replicated-partition alerts wired up
Exercise: You are reviewing a proposed topic: user-events, 3 partitions, null keys, replication.factor=1, retention.ms of one hour, plain JSON payloads, consumed by one group with auto-commit that writes rows into a warehouse and sends welcome emails, on a PLAINTEXT listener with auto topic creation enabled. List the problems in order of the damage they would cause in production, and give the change you would require for each before approving it.