Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

After a schema change that added a NOT NULL column with a default to a table, downstream consumers of Debezium events fail to deserialize messages. Explain and prevent this.

Debezium turns the table's columns into the schema of its events, so adding a column changes the event schema for every consumer. With Avro and a schema registry, the new schema may be rejected by the registry's compatibility rules, which stops the connector, or accepted while consumers built for the old shape fail, for example a JSON consumer that rejects unknown fields. We prevent this by making only backward compatible changes, setting registry compatibility to BACKWARD or FULL and checking changes in CI, coordinating DDL with consumers, and exposing stable outbox events instead of raw tables when other teams depend on the data.

Why this question is asked

Schema changes are routine in a service: every sprint adds a column somewhere. With CDC, each of those changes leaks straight into Kafka, and consumers in other teams break on a deployment they never heard about. Interviewers ask this to see whether we understand how Debezium derives schemas, how a schema registry decides what is compatible, and how to prevent the problem as a team practice rather than fixing it each time. In this answer, we will see how a table change becomes an event change, reproduce two ways it breaks consumers, explain compatibility modes, and go through the preventions.

1How a Table Change Becomes an Event Change

Debezium builds the schema of each event from the table's columns: every column becomes a field, with its type and with optional or required depending on whether the column allows NULL. When the events are serialised with Avro and a schema registry, the converter registers that schema under a subject, such as shop.public.orders-value, and each message carries only a small schema id.

PostgreSQL's logical decoding does not send DDL statements at all. Instead, pgoutput sends a relation message describing the table's current columns before the first change that uses them. So Debezium notices the new column only when the first row change after the ALTER TABLE arrives, builds a new event schema, and the converter tries to register it as a new version of the subject.

SQL
ALTER TABLE orders ADD COLUMN channel text NOT NULL DEFAULT 'web';
-- PostgreSQL 11 and later: instant, existing rows are not rewritten
UPDATE orders SET status = 'PAID' WHERE id = 501;
-- Debezium receives a relation message with the new column, then the change
-- new value schema: {id, status, total, channel} channel: string, required
Step throughA column added under running CDC
DeveloperPostgreSQLDebeziumSchema registryConsumer
ALTER TABLE orders ADD COLUMN channel
next change: relation message with new columns
register value schema version 4
accepted or rejected by compatibility rule
event written with schema id 4
deserialize with code built for version 3

6 messages in order. Play them, or step through them one at a time.

2Two Ways It Breaks

The first failure is at the registry. Under the common BACKWARD rule, a new schema must be able to read data written with the previous one. A new required field with no default breaks that rule, because old messages have no value for it. Whether Debezium copies the column's database default into the Avro field's default depends on the connector and its version, so check your version. If it does not, the registry rejects the new schema, the converter throws a serialization error, and the connector task fails and stops. Consumers see no new messages at all.

The second failure is in the consumer, when the registry accepts the change or there is no registry. A common case in Java is a consumer that reads JSON with a plain Jackson ObjectMapper and maps it to a class. Jackson's default is to fail on unknown properties, so the first event containing channel throws an exception, and the consumer, retrying the same message, stops making progress.

Java
public record OrderRow(long id, String status, BigDecimal total) {}
ObjectMapper mapper = new ObjectMapper(); // FAIL_ON_UNKNOWN_PROPERTIES is true by default
mapper.readValue("{\"id\":501,\"status\":\"PAID\",\"total\":59.98,\"channel\":\"web\"}",
OrderRow.class);
// UnrecognizedPropertyException: Unrecognized field "channel"

The consumer is not wrong to be strict, and the producer is not wrong to add a column. The failure comes from a missing agreement about which changes are allowed. Consumers that want to be robust ignore unknown fields, for example with @JsonIgnoreProperties(ignoreUnknown = true) or Spring Boot's auto-configured ObjectMapper, which disables that failure.

3Compatibility Modes in the Schema Registry

A schema registry checks each new version of a subject against earlier versions using a compatibility mode. Choosing the mode is choosing who may upgrade first.

Schema registry compatibility modes
ModeNew schema mustTypical safe change
BACKWARDread data written with the previous schemaadd an optional field with a default, delete a field
FORWARDbe readable by consumers on the previous schemaadd a field, delete an optional field
FULLsatisfy both of the aboveadd or delete optional fields with defaults
NONEanything is acceptednothing is checked, consumers may break

For CDC topics, BACKWARD is the common default and lets consumers upgrade after producers in the usual order, as long as new fields have defaults. FULL is stricter, allowing only changes that work in both directions, essentially adding or removing optional fields with defaults, which suits topics with many consumers that upgrade at their own pace. Setting the transitive variants, such as BACKWARD_TRANSITIVE, checks against all earlier versions, not just the last, which matters when consumers may replay old data.

4Prevention 1: Only Backward Compatible Changes

The simplest rule for a table under CDC is to evolve it only in compatible ways. New columns are nullable, or have a default that the event schema carries. Columns are never renamed or retyped in place. A rename becomes three steps: add the new column, write both for a while and let consumers move, then drop the old one in a later release, which is the familiar expand and contract pattern.

SQL
-- compatible: nullable new column
ALTER TABLE orders ADD COLUMN channel text; -- optional field in the event
-- not compatible in place
ALTER TABLE orders RENAME COLUMN total TO amount; -- consumers lose 'total'
ALTER TABLE orders ALTER COLUMN total TYPE text; -- type change for every consumer

5Prevention 2: Check Schemas in CI

We set the registry's compatibility for CDC subjects explicitly, BACKWARD or FULL, rather than relying on whatever the default is. Then we catch problems before they reach production: the service's CI pipeline derives the expected event schema for each migration and asks the registry whether it is compatible with the latest registered version, through the registry's compatibility REST endpoint or a build plugin. A failing check blocks the migration's merge with a clear message, instead of a failed connector at night.

Java
# set compatibility for the subject
curl -X PUT -H 'Content-Type: application/json' \
--data '{"compatibility": "BACKWARD"}' \
http://registry:8081/config/shop.public.orders-value
# in CI: test a candidate schema against the latest version
curl -X POST -H 'Content-Type: application/vnd.schemaregistry.v1+json' \
--data @orders-value-candidate.json \
http://registry:8081/compatibility/subjects/shop.public.orders-value/versions/latest
# {"is_compatible": false} -> fail the build

6Prevention 3: Treat CDC as a Contract, or Publish an Outbox

Behind both failures is a deeper issue: once other teams consume a raw table's CDC stream, the table's schema has become a public API, whether the owning team meant it or not. So either we treat it as one, with a documented contract, announced changes and a migration period, or we stop exposing the table. The cleaner option for service-to-service use is a transactional outbox: the service writes stable, versioned domain events, such as OrderPlaced version 2, into an outbox table in the same transaction, and Debezium streams only that table. The internal orders table can then change freely, because the event's shape is controlled by code, not by the table.

7Follow-up questions

Why did the consumers fail only on some messages at first?

Because Debezium only learns the new schema when the first change after the ALTER TABLE arrives, and only events for changed rows carry the new field. Rows that were not touched produce no events, so the failure starts with the first update or insert after the migration.

If the connector failed with a registry error, how do we recover?

We decide on the right schema change, either by making the column nullable or by allowing the change after consumers are ready, then restart the connector task. It resumes from its stored offset, and in PostgreSQL the replication slot has kept the WAL, so no change is lost, though slot lag grew while it was stopped.

Does adding a NOT NULL column with a default rewrite the table?

Not since PostgreSQL 11: a non-volatile default is stored in the catalog and returned for existing rows without rewriting them. Those old rows produce no CDC events until they change, which is another reason consumers see the new field gradually.

8Conclusion

In this answer, we saw that Debezium derives each event's schema from the table's columns, learning about a new column from the relation message before the first change, so a column added in the database becomes a new event schema. That can be rejected by the schema registry, stopping the connector, or accepted and then break consumers that are strict about unknown fields. We prevent it with backward compatible changes only, explicit BACKWARD or FULL compatibility checked in CI, coordinated DDL, and stable outbox events instead of raw tables for other teams.

What to say in the interviewAbout 80 seconds aloud

Open with

Debezium builds its event schema from the table columns, so adding a column changes the event schema for every consumer. In PostgreSQL there's no DDL in logical decoding; Debezium sees the new column from the relation message before the first change after the migration, and the Avro converter registers a new schema version.

Then, if they want more

Two things can go wrong. If the registry runs BACKWARD compatibility and the new field is required with no default in the Avro schema, the registry rejects it and the connector task fails. Whether the database default is carried over depends on the connector version.

Or the schema is accepted, and consumers break, for example a Java consumer using a plain ObjectMapper, which fails on unknown fields by default. To prevent it, I'd allow only backward compatible changes on tables under CDC: new columns nullable or with defaults, no renames or type changes in place, expand and contract instead.

I'd set compatibility explicitly to BACKWARD or FULL and check every migration's schema against the registry in CI, so incompatible changes fail the build. And I'd treat raw CDC as a contract with announced changes, or better, give other teams stable events through an outbox table, so the internal schema can change freely.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 11
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "After a schema change that added a NOT NULL column with a default to a table, downstream...": https://scrivio-interview-library.netlify.app/databases/analytics-and-cdc/a69766588c/