Schemas, Connect, Streams and Production Failure Modes

Schemas, Connect, Streams and Production Failure Modes in Apache Kafka: Kafka has no notion of a record's structure.

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.

FormatSelf-describingSchema evolutionNotes
JSON (plain)Human-readable, unvalidatedNone enforcedFine for prototypes; verbose; drifts silently
AvroNo, needs schemaStrong, with a registryCompact; common default for data platforms
ProtobufNo, needs schemaStrong, field-number basedCompact; good cross-language tooling
JSON SchemaReadable plus validatedGoodCompromise 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.

ModeAllowsUse when
BackwardNew schema reads old dataConsumers upgrade first (most common)
ForwardOld schema reads new dataProducers upgrade first
FullBothStrictest, 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:

AbstractionSemanticsBacked by
KStreamAn unbounded sequence of events; each record is a factNormal topic
KTableLatest value per key; a changelog viewCompacted 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:

  1. TLS on client and inter-broker listeners, so traffic is not readable on the wire.
  2. SASL authentication, so every client has an identity.
  3. 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

SymptomLikely causeFirst check
Events processed out of orderNull key, or key that is not the ordering unitAre the events for one entity in one partition?
Ordering broke after a scale-upPartition count increased, key-to-partition mapping shiftedCompare partition count before and after
Lag grows while consumers idleMore consumers than partitionsPartition count versus group size
Group rebalances constantlyProcessing exceeds max.poll.interval.msBatch duration versus max.poll.records
Records missing after broker restartacks=1, or min.insync.replicas=1Producer acks and topic config
Duplicate side effectsAuto-commit, or non-idempotent consumerCommit strategy and dedup design
Consumer stuck on one record foreverPoison message with no dead-letter pathDeserialisation error handling
One partition lags badlyKey skew, hot partitionPer-partition lag
Under-replicated partitionsSlow or failing broker, network, diskBroker metrics, ISR shrink events
Producer blocks or throws on sendBuffer full because brokers are slowbuffer.memory, max.block.ms, broker health
New consumer processed nothing historicalauto.offset.reset=latest on a fresh groupGroup's committed offsets
Disk full on a brokerRetention or retention.bytes under-estimatedStorage arithmetic per partition

What to monitor

Four signals cover most of the ground:

  1. Consumer lag per partition — the primary consumer SLI. Alert on sustained growth, not absolute value.
  2. Under-replicated partitions — the primary broker durability signal. Should be zero.
  3. Rebalance rate per group — a rising rate means the group is thrashing.
  4. 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.