What considerations do you take into account when selecting a data serialization format?
Instruction: Discuss your criteria for choosing a data serialization format for data storage and processing.
Updated
Official answer
Start with the exchange pattern: individual messages, a human-facing API, long-lived files or column-selective analytical scans. JSON, Protobuf, Avro and Parquet serve different needs; comparing their names without the workload is insufficient.
For messages, assess schema contracts, reader/writer compatibility, supported languages, payload size and serialization cost. Binary does not universally mean faster. For analytical files, columnar layout and statistics may reduce scans, while small files and unsupported logical types can erase the benefit.
Specify decimals, timestamp units/time zones, null versus absent fields and integer range. Test round trips in every required runtime. JSON numbers can lose integer precision in some consumers. Adding an Avro reader field needs a valid default to read older records that lack it; schema evolution is conditional, not automatically seamless. With Protobuf, preserve field-number compatibility and follow its reserved-field rules.
Benchmark representative encoded/compressed size and CPU, not just toy records. Plan schema discovery, format versions and historical readability. Bound parser input sizes and treat externally supplied data as untrusted. Choose the simplest interoperable format that satisfies correctness and measured performance; document limitations instead of assuming a format enforces business meaning.