# What Space Is Every Format a Point In?

*A data format is not a file extension or a brand name. It is a set of promises across four independent axes, and every bet carries a measurable bill.*

**By Femi Adeniran** (https://femiadeniran.com/) · **Mostly Quantized** (https://mostlyquantized.com/) · **Published with OmenWorks** (https://omenworks.dev/)

---

## 01. A format is a set of promises, not a file extension

Start with a cheque. Along its bottom edge runs a line of digits printed in magnetic ink: a routing number, an account number, a cheque number. Nothing in that line explains itself. It works because the clearing system extracted four promises and wrote them down: one nine-digit group is the routing number and passes a check-digit test; another group identifies the account; another is the cheque number; a reader that finds fewer than three groups may reject the item. The digits are not the format. The promises are.

Now a boarding pass. The printed slip carries a name in capitals, a route, a seat, and a two-dimensional barcode whose fields sit at fixed positions: a fixed number of characters for the name, a filler character for unused space, a check digit over the document number. The airline does not trust the printer to be correct; it trusts the arithmetic inside the barcode. Again the promise, not the ink.

A data format is the same kind of object. It promises four things, whether or not its specification says so out loud. First, which byte strings are admissible: what may appear, in what order, with what lengths. Second, what a reader may assume without checking: that a length is truthful, that a string is valid text, that a checksum matches, that a field is present. Third, what happens when a promise breaks: reject the whole input, skip the record, substitute a default, or leave behaviour undefined. Fourth, how the admissible set may grow: which changes are legal, which are detectable, which quietly corrupt older readers.

A file extension promises none of these. Neither does the name of a format. Those are labels for a family of promises, and the family has members that disagree.

Two lines can encode the same order and promise different things. A fixed-width purchase-order line, 23 bytes:

WIDGET04 00001220261130

The first nine bytes are the SKU, padded with a space to a fixed width; the next six the quantity, zero-padded; the last eight the date, YYYYMMDD. The promise is positional: byte 0 always starts the SKU; byte 9 always starts the quantity. A field may not contain a space, because a space is padding. A record is always exactly 23 bytes, so a truncated record is detectable by length alone. Adding a field means changing the width of every record ever written.

The delimited line for the same order is 23 bytes:

WIDGET04,12,2026-11-30

Here the promise is separational: commas divide fields, a newline ends the record, and a field containing a comma must be quoted. Nothing in the format says how many bytes a field or record must occupy. That buys extensibility: an extra column can be appended without breaking an older reader, which simply ignores column 4.

The price shows up the moment a wire drops bytes. Slice the last four bytes off the fixed-width record and you have 19 bytes instead of 23; the reader rejects the frame before touching a single field. Slice the last four bytes off a delimited line like WIDGET04,2026-11-30,120000 and you get WIDGET04,2026-11-30,120: both commas are still there, all three fields are still there, and even a reader that counts commas silently ingests a quantity off by a factor of a thousand. Comma-counting cannot detect truncation inside the final field because total record length was never part of the contract.

Notice what the two lines have already decided: positional against separational, fixed against variable, schema-bound against self-describing. Those are axes, not brands.

Only now name the formats you already know. The first line is the ancestor of every fixed-format record; the second is CSV. The JSON version of the same order is 45 bytes, and its promises differ again: field names travel with the values, strings are escaped rather than comma-quoted, and slicing off the last few bytes leaves an unclosed quote or brace so the grammar fails loudly instead of parsing short.

The useful question is never "which format is better". It is: which of these promises does your reader actually rely on, and which does your writer actually keep?

```text
Three encodings of one purchase order; byte counts as written.

fixed-width, 23 B
  WIDGET04 00001220261130
  offsets: SKU 0..8, qty 9..14, date 15..22
  promise: length must be 23, so truncation is detectable

CSV, 23 B
  WIDGET04,12,2026-11-30\n
  promise: comma separates, newline ends; 2 fields is still a valid record

JSON, 45 B
  {"sku":"WIDGET04","qty":12,"on":"2026-11-30"}
  promise: names travel with values; an unclosed brace fails to parse

Check digit, ABA weights 3,7,1 over the nine routing digits:
  0 2 1 0 0 0 0 2 1
  3*(0+0+0) + 7*(2+0+2) + 1*(1+0+1) = 0 + 28 + 2 = 30
  30 mod 10 = 0 -> the routing number passes
```

> **Takeaway:** A format is the set of assumptions a reader is allowed to make without checking. The more it promises, the less the reader validates and the more the writer must guarantee; the fewer it promises, the more each reader invents its own rules.

### Checkpoint 01 (Contracts & promises)

A team switches a 23-byte fixed-width order record to CSV so they can append optional fields later. A network hiccup slices the last 4 bytes off 'WIDGET04,12,2026-11-30' (leaving 'WIDGET04,12,2026-1' at EOF). Why does the CSV reader silently ingest broken data while the fixed-width reader catches it before parsing a single field?

- **A)** CSV splits on commas instead of counting bytes, so truncation shifts the second delimiter and merges quantity 12 into the date field.
- **B)** CSV omits a trailing checksum byte, whereas fixed-width records include a built-in length verification byte at offset 22.
- **C)** All three comma-separated fields remain intact so CSV's framing rule is satisfied, whereas fixed-width makes total 23-byte stride part of the format contract.
- **D)** RFC 4180 instructs CSV readers to right-pad a truncated trailing column with null bytes rather than raising an unexpected EOF error.

<details><summary>Answer & Craft Gem</summary>

**Correct Answer:** **C** — All three comma-separated fields remain intact so CSV's framing rule is satisfied, whereas fixed-width makes total 23-byte stride part of the format contract.

**Why:** CSV's format layer has no record-length promise — slicing off the last 4 bytes leaves all 3 comma-separated fields intact so the CSV parser succeeds with zero framing error (and if the trailing field is a string or integer like 120000 -> 12, downstream parsing silently ingests corrupted data).

**Craft Gem — Why Postel's Law Breaks Binary Formats:** Jon Postel's 1981 maxim — 'be liberal in what you accept' — works for forgiving text protocols, but in data formats it creates security vulnerabilities. Every reader that tolerates sloppy framing, duplicate keys, or short lengths invents its own undocumented parser dialect. When two parsers disagree on the same bytes (ASN.1/BER certificate smuggling, CouchDB CVE-2017-12635 duplicate JSON keys), attackers smuggle payloads past the validator into the executor. Modern high-assurance specs (RFC 9413, langsec) invert Postel: strict grammar, reject ambiguity at byte zero.

*Source: RFC 9413 (The Harmful Consequences of the Robustness Principle) · https://www.rfc-editor.org/rfc/rfc9413*
</details>

---

## 02. Four axes describe any format you will meet

Take a library's shelf list. For decades it was a set of catalogue cards, each with fixed zones: author, title, date, call number, each beginning at a known position on the card. A reader could find the date without understanding the title, because position carried the meaning. Now take a laboratory notebook. Entries are prose, the date sits wherever the writer put it, and you must understand the language to find anything. Both are records. They are points on the same axes.

The first axis is text against binary. Text buys legibility, diffability and tools that already exist on every machine; it pays in size and in parsing ambiguity. Binary buys density and a fixed layout; it pays in opacity and in the need for a decoder everywhere.

The second is fixed against variable. Fixed-width fields buy constant-time access: field k begins at a computable offset: and cheap validation by length. They pay in wasted bytes and in painful evolution. Variable-length fields buy density; they pay in length prefixes or delimiters, and in the parsing those imply.

The third is delimited against framed. A delimiter is a byte pattern that may not appear in the payload; framing is a length or a type that tells you where a record ends. Delimited formats are easy to write by hand and hard to parse correctly. Framed formats are easy to parse and hard to write by hand.

The fourth is schema-bound against self-describing. Schema-bound means the reader must already know the layout; the bytes carry only values. Self-describing means the bytes carry names or types, so a reader can do something sensible without out-of-band knowledge. The first buys density and validation; the second buys reach.

The axes are independent, which is the point. Binary does not imply schema-bound: a binary format can carry its own type tags or field names inside every message (PNG chunks, CBOR, and MessagePack all do). Conversely, text does not imply self-describing: a fixed-width text line or headerless CSV carries zero field names and is as schema-bound as a C struct. A format is a coordinate, not a camp.

Together the four predict most of what will hurt later. Fixed and positional means insertion breaks every reader. Delimited means payload bytes can collide with the delimiter unless escaped. Self-describing means metadata travels inside the file: and how much that costs depends on amortisation granularity: tagging one multi-megabyte compressed block once costs four bytes total, whereas repeating field names on every single row across ten million rows burns hundreds of megabytes. Schema-bound means the schema never disappears; it simply moves out of the bytes and into every reader's build.

Only now walk all four corners as real formats. CSV sits at text, variable, delimited, weakly self-describing (only if a header row is present). JSON sits at text, variable, delimited by grammar, self-describing: every record repeats "sku", "qty", and "on" in plain ASCII so any language can inspect it without a shared schema file. PNG sits at binary, variable, framed, self-describing by chunk type: each block announces its own length and four-letter name (like IHDR or IDAT), amortising a 4-byte label over thousands or millions of image bytes so an older decoder can skip unknown chunks safely.

Protocol Buffers sits at the opposite binary corner: binary, variable, framed, schema-bound. On the wire, none of the field names ("sku", "qty", "on") travel at all. Each value is prefixed only by a tiny integer field number and a wire type (so a reader knows whether to read a varint or a length-prefixed byte slice, and can skip unknown field numbers without crashing). Our 45-byte JSON order shrinks to 17 bytes in Protocol Buffers (0A 08 "WIDGET04" | 10 0C | 18 8A D2 D4 09), or 14 bytes in a raw packed struct. That compression is real, and so is the trade: without the external .proto schema mapping field 1 to sku, field 2 to qty, and field 3 to date, those 17 bytes are three anonymous numbered values. Switching from JSON to Protocol Buffers does not remove schemas: it relocates them from the wire into every producer and consumer. Each corner is a coherent answer to a different constraint, and each becomes the wrong answer when the constraint changes.

```text
One three-field record - sku WIDGET04, qty 12, date 2026-11-30 - in four positions.

packed binary, 14 B
  57 49 44 47 45 54 30 34 0C 00 0A 29 35 01
  sku 8 B | qty u16 LE | date u32 LE (20261130 = 0x0135290A)

tag-length-value, 22 B
  01 08 57 49 44 47 45 54 30 34
  02 01 0C
  03 04 01 35 29 0A
  three tags, three lengths, three values; skip tag 03 without knowing what it means

CSV, 23 B
  WIDGET04,12,2026-11-30\n

JSON, 45 B
  {"sku":"WIDGET04","qty":12,"on":"2026-11-30"}

At 10,000,000 rows:
  packed  140 MB
  TLV     220 MB
  CSV     230 MB
  JSON    450 MB

Packing saved 310 MB and moved the schema out of the file and into every reader.
```

> **Takeaway:** Axes are independent, so 'binary against text' is not a decision; it is four decisions that happen to be visible at once. Naming all four stops one choice from silently making the others for you.

### Checkpoint 02 (Four design axes)

An engineer pitches: 'Switch from JSON to a binary format so files stop carrying schemas around and immediately shrink.' Which counter-argument exposes the exact design-axis error in that pitch?

- **A)** Binary formats are actually larger than minified JSON on short records because every binary field needs an 8-byte alignment header and magic prefix.
- **B)** Medium (text vs binary) is independent of layout knowledge: CBOR and PNG are self-describing binary formats, while Protobuf moves the schema out of band rather than erasing it.
- **C)** JSON is already schema-bound because RFC 8259 fixes the exact UTF-8 wire representation of numbers, strings, and object delimiters.
- **D)** Binary only shrinks files once gzip is applied; uncompressed binary encodes the exact same field metadata overhead as UTF-8 JSON.

<details><summary>Answer & Craft Gem</summary>

**Correct Answer:** **B** — Medium (text vs binary) is independent of layout knowledge: CBOR and PNG are self-describing binary formats, while Protobuf moves the schema out of band rather than erasing it.

**Why:** They conflated Text-vs-Binary with Self-Describing-vs-Schema-Bound — those two axes are independent.

**Craft Gem — Protobuf's 1-Byte Hot Zone (Field Tags 1–15):** Protocol Buffers packs each field's wire type (3 bits) and field number into a single varint tag: (field_number << 3) | wire_type. Because varint uses 7 payload bits per byte, field numbers 1 through 15 fit in exactly 1 byte (max 0x7F), while 16 through 2047 cost 2 bytes on every single record. Experienced format architects guard tags 1–15 strictly for hot, high-frequency fields and push rare/optional metadata to 16+ before v1 ever ships — because tag numbers are permanent.

*Source: Protocol Buffers Encoding · https://protobuf.dev/programming-guides/encoding/*
</details>

---

## 03. The axes you did not name are the ones that decide

A printed railway timetable and a live departure board encode the same facts under different policies. The timetable is eager: every train, every stop, resolved at press time. The board is lazy: it resolves only the next departures, from a feed that may change. A faxed signature and a notarised copy differ on another axis: one is lossy, one is exact. You already reason this way about documents. Do it about bytes.

Canonical against permissive. A canonical format admits exactly one byte string per value; a permissive one admits many and asks readers to treat them as equal. Canonical buys stable hashes, signatures, deduplication and byte equality. It costs encoder discipline and constrains implementations. Permissive buys tolerance of other people's encoders; it costs the guarantee that two equal values look equal.

Eager against lazy. Eager decoding turns the whole input into a tree before anything is used: simple readers, no random access, memory proportional to the input. Lazy decoding leaves bytes in place and resolves on access: fast startup, random access, but every access must validate or trust.

Exact against lossy. Exact formats preserve every distinction the writer made. Lossy formats discard detail irreversibly: fine when the consumer is a human eye, poisonous when the output feeds a computation or a signature.

Human against machine. Text is debuggable, greppable, diffable; it needs escaping, parsing and a character encoding. Binary is compact and unambiguous in width; it is opaque without a decoder and a hex dump.

Wire against storage. A wire format describes transit: one record at a time, no indexes. A storage format must answer for pages, durability and finding one record among billions. The same logical data often needs both, and the two formats rarely look alike.

None of these axes is independent of the others. Canonical and permissive is a contradiction unless you say what is canonicalised; eager and lazy is a decoder policy, not a file property. That is why a format that advertises one virtue: "human-readable", "compact", "fast": is telling you which axis it wants you to look at first.

Only now the named formats. JSON is text, permissive, eager in most parsers, lossy for large integers (numbers above 2^53 lose precision in IEEE 754 doubles), human-first. Engineers routinely try to make JSON signable by sorting object keys and stripping whitespace: and still watch signatures diverge in production. Permissive text hides degrees of freedom everywhere: 1, 1.0, 1e0, and -0.0 all parse to the same number; "\u0061" and "a" (or "\/" and "/") parse to the same string; Unicode characters can appear in composed or decomposed form (NFC vs NFD); and a single trailing newline changes every bit of a SHA-256 digest. Until every spelling rule is pinned across every language runtime, a hash signs a dialect, not a value.

DER (Distinguished Encoding Rules, from ASN.1) sits at the opposite pole: binary, canonical, eager, exact within its type system, machine-first. It eliminates decimal formatting and whitespace altogether by permitting exactly one binary encoding per value, which is why X.509 certificates and content-addressed binary protocols (like deterministic CBOR) sign canonical binary profiles instead of permissive text. A gzip file sits in a third spot: exact about content and permissive about bytes, because timestamps, header flags, and compressor choices mean the same input compressed twice can hash differently.

The decision procedure is to name the axis before you argue about the format. "Should we use JSON or a binary format" is unanswerable. "Do we need one byte string per value so signatures verify" is answerable, and it decides several formats at once.

```text
Same JSON value, three spellings:

A  {"a":1,"b":2}
B  {"b":2,"a":1}
C  { "a": 1, "b": 2 }

SHA-256:
A  43258cff783fe7036d8a43033f830adfc60ec037382473548ac742b888292777
B  3fb75453225c732a76b7899ea2096dda1455189c89817239732182f73fe5a09f
C  dff00ea25fe8c50e7aa5c8990614ad8f4ede53b61b821eb029993ada4a58aca3

A signature or content address over these bytes is a statement about a spelling, not about the value. Canonicalise first: sort keys, remove insignificant whitespace, fix number formatting. Sorted and compact, all three become A, and the three hashes collapse to one.

The same rule in ASN.1: BER admits several encodings of one value; DER admits one. That is why certificates are signed over DER and not over BER.
```

> **Takeaway:** A hash is a statement about bytes, not about meaning. If you want it to be about meaning, you must first collapse the many spellings to one: and that collapse is a design decision, not a library call.

### Checkpoint 03 (Canonicalisation)

Two microservices sign JSON payloads by sorting object keys alphabetically, stripping all whitespace, and taking SHA-256 of the UTF-8 bytes. Both hold the exact same logical record, yet signatures still diverge in production. Which pair of legal JSON payloads breaks that rule?

- **A)** {"a":1,"b":2} vs {"b":2, "a": 1} — one runtime preserves insertion order inside nested maps before hashing.
- **B)** {"ok":true} vs {"ok":TRUE} — RFC 8259 allows encoders to emit uppercase boolean tokens on strongly typed runtimes.
- **C)** {"id":10} vs {"id":010} — C-family serializers permit leading decimal zeros while JavaScript strips them.
- **D)** {"k":"a","n":1} vs {"k":"\u0061","n":1.0} — key sorting and whitespace stripping leave string escapes and equivalent number spellings unconstrained.

<details><summary>Answer & Craft Gem</summary>

**Correct Answer:** **D** — {"k":"a","n":1} vs {"k":"\u0061","n":1.0} — key sorting and whitespace stripping leave string escapes and equivalent number spellings unconstrained.

**Why:** Key sorting + whitespace stripping doesn't canonicalise number spellings (1 vs 1.0 vs 1e0, -0.0, float precision), string escapes ('\u0061' vs 'a', '\/' vs '/'), Unicode normalisation (NFC vs NFD), or trailing newlines.

**Craft Gem — The UTF-16 Landmine Inside RFC 8785 (JSON Canonicalisation):** When RFC 8785 (JCS) finally standardised canonical JSON, it hit two subtle traps: numbers must follow ECMAScript's shortest-round-trip IEEE 754 serialization (rejecting NaN/Infinity and turning -0 into 0), and object keys must be sorted by UTF-16 code units (JavaScript's native string sort) — NOT UTF-8 byte order! For characters above U+FFFF (like emoji or rare scripts), UTF-16 surrogate pairs sort in a different order than UTF-8 bytes, causing naive Python/Go/Rust sort-by-bytes implementations to silently produce mismatched hashes.

*Source: RFC 8785 (JSON Canonicalization Scheme) · https://www.rfc-editor.org/rfc/rfc8785*
</details>

---

## 04. Read a format as a position, not a precedent

An address is a position: a house number tells you where to look without walking the street. A library shelf mark is the same kind of object: 823.914 SMI locates a book without reading the collection, because the scheme, not the neighbours, defines the place. A direction is a precedent: "the third house after the church" works only if you start where the speaker started, and "the book after the atlas" stops working the moment a new book is shelved. Formats are addresses. Reading one as a precedent: "do what the winner did": copies a solution without its problem.

Take PNG. It is binary, big-endian, chunk-framed, self-describing by chunk type, lossless, parse-on-read, and used both on the wire and on disk. Each of those is a coordinate, not a virtue. Binary buys density for pixels; big-endian buys one order across architectures; chunk framing buys skipping and resynchronisation; self-describing chunk types buy extensibility; lossless buys exact pixels; parse-on-read buys tolerance of compression and unaligned data, at the cost of CPU per access.

Its signature is the clearest small example of design-as-position. Eight bytes:

89 50 4E 47 0D 0A 1A 0A

The first byte has its high bit set, so a channel that strips the eighth bit mangles the signature visibly. The next three spell PNG. The CRLF detects a transfer that translates line endings. The 0x1A stops a DOS type command from printing the rest. The final 0x0A detects a translation of LF. None of these bytes is decoration; each is a bet about a failure mode the designers expected.

Then the first chunk, IHDR, begins at offset 8: a four-byte length, a four-byte type, thirteen bytes of data, and a four-byte CRC-32 over the type and data. That chunk envelope is a deliberate framing bet: a reader that knows the envelope can skip any unknown chunk in O(1) by advancing past the length, type, payload, and CRC without understanding a single byte inside. A reader that sees a mangled signature still rejects the file in eight bytes.

Every framing bet also has a trust boundary. A length prefix is an untrusted claim until the reader bounds it against the remaining file size and a hard memory limit: if a malicious 64-byte file writes 0xFFFFFFFF (4 GB) into that four-byte length field and a naive reader allocates or seeks blindly, O(1) chunk skipping turns instantly into memory exhaustion or an out-of-bounds read. Likewise, the trailing CRC-32 defends against accidental transmission bit-flips, never against an adversary: anyone who alters the payload bytes can trivially recompute a matching CRC-32. Integrity against noise is a checksum; authenticity against tampering requires a cryptographic MAC or signature.

Now read a git object the same way. Its bytes are a header: "blob", a space, the decimal length, a NUL: followed by the content, then deflated. Identity is the hash of the uncompressed header plus content. The position: binary, self-describing only in that the header names the type, canonical enough for content addressing, storage-oriented, parse-on-read because of the deflate. The NUL is a length terminator; the decimal length is a promise the reader can check.

Only now name the ancestor. ASN.1 sits at the opposite corner: binary, tag-length-value, schema-bound, with several encodings: BER, CER, DER: over one abstract syntax. Its position bought generality across protocols and paid in a space so large that implementations disagreed. None of these formats is a template. Each is a point you can locate, and the location tells you which workloads it will serve.

```text
PNG, first 33 bytes of a 1920x1080 RGBA image:

89 50 4E 47 0D 0A 1A 0A
00 00 00 0D 49 48 44 52
00 00 07 80 00 00 04 38
08 06 00 00 00 E8 D3 C1 43

  89 50 4E 47   signature: "PNG" with the high bit set on the first byte
  0D 0A 1A 0A   CRLF, DOS-EOF, LF: three newline-failure detectors
  00 00 00 0D   chunk length = 13
  49 48 44 52   chunk type = IHDR
  00 00 07 80   width  = 1920 (big-endian)
  00 00 04 38   height = 1080 (big-endian)
  08 06 00 00 00  depth 8, colour type 6 (RGBA), compression 0, filter 0, interlace 0
  E8 D3 C1 43   CRC-32 over type + data

git blob for the 12 bytes "hello world\n":

  62 6C 6F 62 20 31 32 00 68 65 6C 6C 6F 20 77 6F 72 6C 64 0A
  "blob 12" NUL "hello world\n"
  id = SHA-1(those 20 bytes) = 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
  stored on disk: zlib-deflated, so a reader inflates before it can hash
```

> **Takeaway:** A format is legible when you can say what it bought and what it paid in the same sentence. If you can only say what it is, you have memorised a precedent, not read a position.

### Checkpoint 04 (Format-as-position)

A chunked binary format frames records as [4-byte length][4-byte type][payload][4-byte CRC-32] so old readers can skip unknown chunks in O(1). A 64-byte untrusted file arrives over the wire. Which attack defeats a naive reader BEFORE the CRC-32 check even runs?

- **A)** Writing 0xFFFFFFFF into the 4-byte length field tricks the reader into allocating 4 GB or seeking past the buffer end before ever checking CRC-32.
- **B)** Flipping one bit in the 4-byte chunk type creates a CRC-32 collision so the reader skips checksum validation and executes an unknown chunk.
- **C)** Appending trailing zero bytes after the CRC-32 overflows the 32-bit length header and traps the parser in an infinite backward seek loop.
- **D)** Setting the first letter of an unknown chunk type to uppercase forces an old reader to buffer the entire file into RAM instead of skipping it.

<details><summary>Answer & Craft Gem</summary>

**Correct Answer:** **A** — Writing 0xFFFFFFFF into the 4-byte length field tricks the reader into allocating 4 GB or seeking past the buffer end before ever checking CRC-32.

**Why:** Trusting the 4-byte length field before validating it against remaining buffer/file size and a hard memory budget allows an attacker to declare length = 0xFFFFFFFF (4 GB) on a 64-byte file, triggering OOM allocation or out-of-bounds pointer jumps.

**Craft Gem — PNG's 4-Bit Case Grammar Inside Every Chunk Name:** PNG didn't spend a single extra header byte on chunk capability flags. Instead, it encoded four orthogonal rules directly into bit 5 (uppercase vs lowercase ASCII) of the four chunk-type letters: Letter 1 uppercase = Critical (abort if unknown, e.g. IHDR) vs lowercase = Ancillary (safe to skip, e.g. tEXt); Letter 2 = Public vs Private; Letter 3 = Reserved; Letter 4 lowercase = Safe-to-copy by an editor that doesn't understand the chunk even after modifying image pixels. Every reader gets a 4-bit evolution contract for free inside a human-readable ASCII name.

*Source: W3C PNG Specification §5.4 Chunk Naming Conventions · https://www.w3.org/TR/png/*
</details>

---

## 05. Local best practice is a global trap

A factory standardises on inches because its machines were built in inches. A city builds tram tracks at the gauge of the fleet it already owns. Each choice is locally correct and globally expensive: the cost appears when a new machine, a new supplier, or a new city arrives. Data formats accumulate the same sediment.

There are three ways into the trap. The first is designing for the demo: the constraint that matters is the one in the README, and every other constraint becomes a surprise. The second is copying the winner's accidents: you adopt a format because it is everywhere, then inherit its number type, its escaping rules and its evolution model without inheriting the constraints that made them tolerable. The third is choosing tools before naming constraints: you pick a library, then let the library's format decide your durability, your framing and your schema policy.

The escape is arithmetic, not taste. Write down the workload: records per second, bytes per record, years of retention, who reads it, how often, and what must never be lost. Then compute. You do not need a benchmark to know that 45 bytes per row and 14 bytes per row differ by a factor of three; you need a multiplication.

Forty-five bytes per row, one reading per second, five years: 157,680,000 rows and 7.1 GB. Fourteen bytes per row: 2.2 GB. The packed form is 3.21 times smaller: a 69% reduction. That ratio is a fact about the encoding, independent of hardware. Whether it should decide your format depends entirely on the binding constraint. At 10,000 internal config rows, the exact same 69% reduction saves only 310 KB (0.45 MB versus 0.14 MB): completely invisible on disk, while costing you schema distribution, cross-language decoders, and the ability to inspect or diff a config at 2 AM. Multiply that same 1 Hz logger across 50,000 cellular field sensors, however, and the identical 3.21x ratio swings 354.8 TB down to 110.4 TB: saving 244 TB of storage and radio battery life. Nothing about the formats changed; the binding constraint flipped from engineer-hours to bandwidth and energy.

The reason JSON wins anyway in small and medium systems is not that bytes do not matter. It is that the global constraint is coordination: parsers exist everywhere, a human can read the file, and a new consumer costs minutes rather than a schema negotiation. That is a real advantage, priced in engineer-hours rather than bytes. The trap is not choosing JSON. The trap is believing you chose it for its bytes: or quoting a percentage reduction without multiplying it by your actual row count.

So before importing a best practice, restate the constraint it was solving. "Always use text" was a solution to debugging and tooling in a world of small records. "Always use binary" was a solution to scale in a world of controlled readers. Neither travels without its world.

```text
One reading per second for five years (ignoring leap days):
  365 * 24 * 3600 * 5 = 157,680,000 rows

text row (JSON, 45 B):
  157,680,000 * 45 = 7,095,600,000 B = 7.1 GB

packed row (8 B sku + 2 B qty + 4 B date):
  157,680,000 * 14 = 2,207,520,000 B = 2.2 GB

ratio: 45 / 14 = 3.21

The same arithmetic at 10,000 rows:
  text    450,000 B  (0.45 MB)
  packed  140,000 B  (0.14 MB)
At that size the difference is invisible; the schema cost is not.

What the byte count does not include:
  - the schema file the packed reader must have, and its version
  - the decoder on every platform that reads the archive
  - the human who cannot open the file in a text editor in year six
```

> **Takeaway:** Best practice is a local solution to someone else's constraint. Before you import it, restate the constraint it was solving and check that you have the same one.

### Checkpoint 05 (Workload arithmetic)

Your team stores 10,000 internal config records in JSON (~450 KB total). Someone proposes migrating to a 14-byte packed binary struct because '69% storage savings is a no-brainer.' Why does that pitch fail here, yet the exact same 3.21x ratio IS decisive for 50,000 cellular field sensors?

- **A)** Packed binary structs compress far worse under gzip than ASCII JSON, making the stored config file larger on disk after compression.
- **B)** At 10,000 rows, 69% saves only ~310 KB while sacrificing git diffs, grep, and schema-free debugging; at 50k sensors over 5 years, the same ratio saves ~245 TB and radio battery.
- **C)** Modern x86 CPUs have dedicated JSON-parsing instructions, making 450 KB of JSON strictly faster to decode than 140 KB of packed binary.
- **D)** Binary formats cannot add optional configuration fields later, whereas JSON automatically upgrades old consumers whenever key semantics change.

<details><summary>Answer & Craft Gem</summary>

**Correct Answer:** **B** — At 10,000 rows, 69% saves only ~310 KB while sacrificing git diffs, grep, and schema-free debugging; at 50k sensors over 5 years, the same ratio saves ~245 TB and radio battery.

**Why:** At 10,000 rows, 69% savings is only ~310 KB (0.45 MB vs 0.14 MB) — invisible on modern disks and networks.

**Craft Gem — Why Hyperscalers Split Control Planes (Text) from Data Planes (Binary):** Large production fleets rarely standardize on one format everywhere. Control planes (feature flags, service configs, deploy manifests, incident snapshots) live at low volume where engineer-hours and emergency 3 AM legibility dominate — so JSON/text wins despite 3x overhead. Data planes (telemetry streams, RPCs, columnar warehouses) live at 10^8 to 10^12 records where bandwidth, cache lines, and CPU dominate — so framed or columnar binary wins. Picking one format by dogma instead of separating planes is how teams either burn millions on JSON telemetry or brick deploys with unreadable binary configs.

*Source: RFC 8259 (JSON) · https://www.rfc-editor.org/rfc/rfc8259*
</details>

---

## The Burn: The zero-copy bet that won its argument and lost the market

Cap'n Proto set out to remove the parse step: the encoded buffer is the object graph, fields sit at fixed offsets, and a reader follows a pointer without copying or decoding. It delivered that. Adoption stayed small, and the format became a reference point for a trade-off rather than a default. The costs it accepted were real: larger messages, a rigid layout, an evolution model tied to a schema, and an ergonomics bill paid by every caller: and systems that needed density or schema flexibility went elsewhere. Nothing crashed. The loss was the opportunity cost of a correct local optimum.

> **Architectural Lesson:** A format is fitted to its adopters' constraints, not to its own elegance. Zero-copy is a bet on read-heavy, trusted, memory-mappable data; most systems are write-heavy, untrusted, and copy anyway.

*Source: https://capnproto.org/ - the project's own description of the zero-copy design and its trade-offs. No adoption statistic is claimed; the absence of a default slot is observable, not measured.*
