Can you explain the concept of schema-on-read vs. schema-on-write?

Instruction: Describe the differences between schema-on-read and schema-on-write and their implications on data storage and retrieval.

Context: This question tests the candidate's knowledge of data modeling approaches, specifically focusing on how data schemas are applied in different data storage technologies.

Updated

Official answer

Schema-on-write validates or transforms data against a defined structure as it is stored. Schema-on-read applies an interpretation when data is read. These describe where structure is enforced, not a strict relational-versus-NoSQL division.

For example, a raw event archive may preserve incoming JSON while a reporting transformation extracts a typed event_time, event_id and amount. That reporting layer should reject or quarantine incompatible values and record the schema version it understood. Storing raw data without validation does not remove the need for a contract; it moves some failure discovery to consumers.

Conversely, a document database can enforce validation on writes. MongoDB supports rules for field types and ranges, so “NoSQL means no schema” is inaccurate. Relational systems can also store semi-structured values alongside typed columns.

Choose enforcement at each layer from compatibility, ingestion latency, consumer expectations and quality requirements. Keep provenance and versioned transformations, test backward/forward compatibility, and define handling for missing or newly added fields. Neither approach automatically guarantees correct data or faster queries; the interpretation and access pattern determine the work.

Related Questions