Applying "Make Invalid States Unrepresentable" to Schema Design
Two production cases of the "make invalid states unrepresentable" principle applied to schema design. First: modelling a contiguous timeline as a List (Date, Date) admits gaps and overlaps; storing only the split dates as a Set Date makes contiguity and non-overlap structural, and adding a split becomes a single set insert. Second: a contract system that stored both fixed and default contracts in one table allowed contract gaps — an optional end date plus a "default" flag made them easy to create, the per-contract mutation API guarded nothing, and real gaps reached production, costing hours to trace. Removing default contracts from the table and inferring them when no fixed contract exists eliminates both the gaps and the optional end date. The author traces the original design to object-oriented thinking that reifies every concept as a row rather than a proposition, and closes with two ways to forbid overlapping contracts: a database excludes constraint, or allowing overlaps in the write model and flattening them in a read-model projection terminated by the next contract's start date.