The mechanism
Every system that stores data validates it somewhere. The choice between schema on write and schema on read decides three things: who checks the data, when they check it, and who finds out when it is wrong.
- Schema on write. The store refuses data that does not match a declared shape: a relational table with types,
NOT NULLandCHECKconstraints, a warehouse table with a fixed schema, or an event stream whose producers must use a registered schema. A bad write fails at once, the error goes to the producer that sent it, and nothing bad is stored. The price is coordination: every change of shape is a schema change someone has to ship, and the declared types are limits the data can outgrow. - Schema on read. The store accepts any bytes that parse: JSON or Parquet files in object storage, a Postgres
jsonbcolumn with no constraints, a raw event log. Each reader applies its own idea of the shape. Writes never fail for shape, so producers change freely. A bad write is found by whichever reader first parses the broken field: perhaps days later, perhaps a team that does not own the producer, and by then the bad records are stored, replicated and mixed with good ones.
So the question is not whether to validate, but whether validation runs once, at the producer, before the data is stored, or in every reader, after it is stored. Most systems do both, and the failures come from the gaps between them.
Where the check actually runs
Relational tables and warehouses. The database runs the check inside the write. PostgreSQL raises an error when a value "would violate a constraint". But "a check constraint is satisfied if the check expression evaluates to true or the null value." A CHECK on a field that is missing evaluates to null, and the row is accepted.
Event streams. The Kafka broker stores bytes and does not look at them. The producer's serializer does the schema-on-write work: it puts "a 4-byte schema ID" at the start of each message, and Schema Registry "checks compatibility before accepting the new version." The serializers "automatically register schemas by default", so the first message sent with a new schema registers it. Confluent's broker-side Schema ID Validation is off by default ("Both default to false"), and even when on it "doesn't inspect the data"; it checks only that the ID is registered under a valid subject. A producer that skips the serializer can write any bytes it likes. Confluent's data contract rules can check content, such as size(message.ssn) == 9, but they also run in the client.
Lakes and JSONB. A Parquet file stores its own column types, but nothing stops two files in the same directory from disagreeing. A jsonb column checks only that the value is valid JSON. You can add schema on write to jsonb one field at a time with CHECK constraints and generated columns. A stored generated column "is computed when it is written (inserted or updated)", so an expression that fails, such as a bad cast, fails the write. Since PostgreSQL 18, generated columns are virtual by default ("computed when it is read"): a virtual column with a bad cast accepts the row, and every query that reads the column then fails. Write STORED to get the check on write; before PostgreSQL 18, only STORED exists.
Schema evolution
Both sides have to handle change. On write, a change is a negotiated step. On read, every shape ever written stays in storage, and every reader has to handle all of them forever.
Schema registries turn evolution into a rule the registry enforces when a new version is registered. Confluent's default is BACKWARD: a "consumer using schema X can process data produced with schema X or X-1", which allows adding optional fields and removing fields, and means you "upgrade all consumers before you start producing new events." FORWARD reverses that: upgrade producers first. FULL allows only adding and removing optional fields, and lets producers and consumers upgrade independently. NONE turns the checks off. The registry defaults to BACKWARD "so that you can rewind consumers to the beginning of the topic", but the plain modes compare a new version only with the one before it. Only the _TRANSITIVE modes compare it with every earlier version, which is what a consumer replaying old data needs. For Protobuf, Confluent recommends BACKWARD_TRANSITIVE "as adding new message types is not forward compatible."
The formats set the rules underneath. In Avro, a reader that has a field the writer did not write "should use the default value from its field"; with no default, "an error is signalled". Between primitive types, Avro resolves only widening numbers, such as int to long, and switching between string and bytes; any other primitive change is "an error". Unions resolve branch by branch, so wrapping a field in a union with null works, but long to string does not. In Protobuf, adding and removing fields is safe, but "Field numbers should never be reused." Decoding a reused number with the old definition can leak personal data or corrupt it, so reserve every deleted field number.
Table formats bring the same discipline to lakes. Iceberg schema changes "are metadata changes, so no data files need to be rewritten". Iceberg can do this safely because it "uses unique IDs to track each column". The docs explain what goes wrong without IDs: "Formats that track columns by name can inadvertently un-delete a column if a name is reused." Delta Lake checks every write against the table's schema: "If there are columns in the DataFrame not present in the table, an exception is raised", and mismatched types fail too; its mergeSchema option adds new columns instead. Renaming or dropping a column without rewriting the data needs column mapping turned on; otherwise a type change, rename or drop means "rewriting the table."
JSONB in Postgres makes evolution free for writers and expensive for readers. To tighten it later, add a constraint as NOT VALID. PostgreSQL skips the "potentially-lengthy scan", checks every new insert or update from then on, and you run VALIDATE CONSTRAINT later, which takes only a SHARE UPDATE EXCLUSIVE lock. This is the same two-step pattern as in Zero-downtime schema migrations: expand and contract.
Worked numbers
All three calculations are illustrative: the rates, sizes and versions are invented, and only the integer limit and the registry rules are real. Put in your own numbers.
How late each reader finds out. A payments service publishes 2,000 events a second. At 10:00 on a Monday, a release changes amount from integer cents to a decimal string, "12.50". With schema on read, nothing fails on write. Each consumer finds the change on its own schedule. If it is the first to notice, every event written since 10:00 needs repair:
- A fraud scorer that parses every event fails within seconds: a few thousand events.
- An hourly dashboard job runs at 11:00: 2,000 × 3,600 = 7.2 million events.
- A nightly batch runs at 02:00 Tuesday, 16 hours later: 2,000 × 57,600 = 115.2 million events.
- A month-end finance reconciliation runs 30 days later: 2,000 × 2,592,000 ≈ 5.2 billion events.
With a registry using Avro, the change fails before any of those events exist: long to string is not an Avro promotion, so under BACKWARD the registry refuses the new version, and the producer gets the error in CI or on its first send. Four teams repairing data becomes one team with a failed build.
The ceiling a declared type sets. A PostgreSQL integer, like any signed 32-bit integer column, stops at 2,147,483,647, the same ceiling Basecamp's events table hit. Take a table whose largest ID is 1,900,000,000 and that grows by 5 million rows a day: (2,147,483,647 − 1,900,000,000) ÷ 5,000,000 ≈ 49.5 days of headroom. Changing a column's type normally rewrites the table and its indexes, so on a large table moving to bigint is a planned migration, not a fix for the day it fills up. Schema on write enforces the limit exactly, at the worst moment, unless someone watches it.
Replays and non-transitive compatibility. A topic keeps 30 days of events and gets four schema versions in that time. Under BACKWARD, the registry checked three pairs: v2 against v1, v3 against v2 and v4 against v3. A consumer on v4 that rewinds to the start of the topic reads data written with v1, and nothing checked v4 against v1. Under BACKWARD_TRANSITIVE, v4 was checked against all three earlier versions, and the replay is safe to parse.
How it fails
- Blank fields a typed table accepted and the new code did not expect (Google Cloud, 12 June 2025). Google Cloud products "experienced increased 503 errors" in external API requests. The status page lists the incident from 10:51 to 18:18 US/Pacific. A new quota-checking feature had been added to Service Control on 29 May. On 12 June, "a policy change was inserted into the regional Spanner tables that Service Control uses for policies." That "policy data contained unintended blank fields", was "replicated globally within seconds", and the new code path lacked appropriate error handling and was not behind a feature flag, so "the null pointer caused the binary to crash." Nothing between the table and the new code checked those fields. Google's fixes include "Prevent our API management platform from failing due to invalid or corrupt data."
- A generated file changed shape, and the reader's hidden limit failed (Cloudflare, 18 November 2025). Cloudflare's network started failing to deliver core traffic at 11:20 UTC. A ClickHouse permissions change made the query that builds the Bot Management feature file return columns from a second database, because "the query does not filter for the database name", which was "effectively more than doubling the rows". The proxy that reads the file had a limit of 200 features, "well above our current use of ~60 features". The bad file had "more than 200 features", so it went over the limit and the proxy panicked. Core traffic was "largely flowing as normal by 14:30", and all systems were normal at 17:06. The 200-feature limit was part of the file's schema, but only the reader knew it. One follow-up is "Hardening ingestion of Cloudflare-generated configuration files in the same way we would for user-generated input."
- The validator and the reader used different schemas (CrowdStrike, 19 July 2024). CrowdStrike's IPC Template Type "defined 21 input parameter fields, but the integration code that invoked the Content Interpreter ... supplied only 20 input values." Its Content Validator checked the new content but "based its assessment on the expectation that the IPC Template Type would be provided with 21 inputs", so the content passed. On sensors, reading the 21st value caused "an out-of-bounds memory read" that "resulted in a system crash." Earlier content had used wildcards in the 21st field, which hid the mismatch. CrowdStrike now checks the field count when the sensor is compiled and bounds-checks the read. A write-side check protects you only if it uses the same schema as the code that reads the data.
- A declared type that ran out (Basecamp, 8 November 2018). Basecamp 3 was read-only for almost five hours, from 7:21am to 12:11pm CST, when "our database hit the ceiling of 2,147,483,647 on our very busy events table". Basecamp's update explains that "the column in database was configured as an integer rather than a big integer," and that the Rails default had moved to big integer "two years ago." (The update is dated 8 November; the later postmortem says 9 November.) Basecamp called it "an avoidable problem": it "failed to properly account for how quickly we were running out of headroom."
- A lake with no contract (Uber, described in 2018). In Uber's first-generation data platform, "Most of our source data was in JSON format, and ingestion jobs were not resilient to changes in the producer code"; "we lacked a formal schema communication mechanism". Its second generation moved to Parquet and added "a central schema service to collect, store, and serve schemas". The post describes a design change, not a dated incident.
The first two reached every machine within minutes, and rolling back the producer does not remove bad data already stored. Our episode Before You Migrate: Can You Really Roll Back? works through the data a rollback cannot undo.
Traps without a published incident
- A change in meaning passes every compatibility check. Changing
amountfrom cents to dollars while keeping it alongis compatible under every mode. Registries check structure, not meaning. Give the field a new name, or add a data contract rule that checks the range. - `CHECK` on a missing field passes.
CHECK ((payload->>'amount')::numeric >= 0)accepts a document with noamountkey, because the expression evaluates to null. It also accepts{"amount": null}and the string"12.50", because->>returns text. Check the JSON type and make a missing key evaluate to false, as the constraint in the weekly check below does. - Auto-registration with `NONE`. On a subject set to
NONE, any change a producer ships becomes the new registered version, with no check at all.
Decision table
| Option | What it costs | Choose it when |
|---|---|---|
Relational columns with types, NOT NULL, CHECK | Every shape change is a migration; declared types are limits you must watch; CHECK accepts nulls | Many writers or readers depend on the data, and a wrong value costs more than a rejected write |
Postgres jsonb with no constraints | Every reader must handle every shape ever written; bad data is found late, by the reader | The data is opaque to the database: kept for display or audit, and read back by the code that wrote it |
jsonb plus CHECK or STORED generated columns on the fields you query | Some write-time cost; a CHECK needs the NOT VALID then VALIDATE sequence; adding a STORED column rewrites the table and its indexes under an exclusive lock | Most of the document is open, but a few fields drive queries, joins or money |
| Raw JSON or Parquet files in object storage, no table format | No shared schema; files can disagree; renames and drops depend on each reader | Landing raw data you will reprocess, and nothing reads it directly |
| Iceberg or Delta table | A catalog and table-format operations to run; schema changes go through the table | Several engines or teams read the lake, and you need adds, drops and renames without rewrites |
Event stream with a registry, BACKWARD_TRANSITIVE or FULL_TRANSITIVE | Consumers or producers must upgrade in a set order; some changes need a new field or topic | Many consumers, replays from old offsets, or retention longer than one schema version lasts |
Event stream with no registry, or a registry set to NONE | Every consumer is a separate parser; one producer change can break all of them at once | One producer and one consumer owned by the same team, and only until a second consumer arrives |
A check you can run this week
Pick one field in a jsonb column, or in a raw event table, that something downstream depends on. Count how many shapes it actually has in the last week (here payload->'amount' in events):
SELECT jsonb_typeof(payload->'amount') AS shape, count(*)
FROM events
WHERE created_at > now() - interval '7 days'
GROUP BY 1
ORDER BY 2 DESC;An empty shape (SQL NULL) means the key is missing; a shape of null means the key is there with a JSON null. Any mix of shapes beyond the one you expect means your readers are already handling a schema that nobody wrote down. Decide which shape is correct, fix or quarantine the rest, then add the constraint as NOT VALID so new writes are checked from today, and validate it once the old rows are clean:
ALTER TABLE events ADD CONSTRAINT amount_is_number
CHECK (CASE WHEN jsonb_typeof(payload->'amount') = 'number'
THEN (payload->'amount')::numeric >= 0 ELSE false END) NOT VALID;
ALTER TABLE events VALIDATE CONSTRAINT amount_is_number;If you run Schema Registry, read the compatibility level your topics actually use:
curl -s "$SCHEMA_REGISTRY_URL/config"
curl -s "$SCHEMA_REGISTRY_URL/config/payments-value?defaultToGlobal=true"If a subject that consumers replay from the start says BACKWARD or NONE, move it to a transitive mode. Then have CI send each changed schema to `POST /compatibility/subjects/payments-value/versions` (no version number, so a transitive mode checks every earlier version) and fail the build when is_compatible is false, so a producer finds out from a failed build, not from a reader a month later.
Sources
The primary sources this guide was checked against.
- Confluent documentation: Schema evolution and compatibility
- Confluent documentation: Formats, serializers and deserializers (wire format, auto-registration)
- Confluent documentation: Schema ID Validation on the broker
- Confluent documentation: Data contracts and domain rules
- Confluent documentation: Schema Registry API reference
- Apache Avro 1.12.0 specification: schema resolution
- Protocol Buffers: proto3 language guide (updating a message type, reserved fields)
- Apache Iceberg documentation: Evolution
- Delta Lake documentation: schema validation and schema evolution
- PostgreSQL documentation: JSON types
- PostgreSQL documentation: constraints
- PostgreSQL documentation: generated columns
- PostgreSQL documentation: ALTER TABLE (NOT VALID, VALIDATE CONSTRAINT, type changes)
- Google Cloud: Service Health incident report, 12 June 2025
- Cloudflare: Cloudflare outage on November 18, 2025
- CrowdStrike: External Technical Root Cause Analysis, Channel File 291
- Basecamp: Postmortem on the read-only outage of Basecamp, November 2018
- Basecamp: Update on Basecamp 3 being stuck in read-only, 8 November 2018
- Uber Engineering: Uber's Big Data Platform, 100+ petabytes with minute latency
Hear it discussed
Episodes of the show that work through this decision.