Skip to main content

When I design data models I optimize for speed, and the schema becomes a house of cards to change later

PhaseArchitectureRolesArchitect ยท EngineerSeverityHighApplies toAll coding agentsEvidenceCommunity case

In one sentence: I may check that a schema stores the sample while missing types, constraints, queries, and evolution contracts; after deployment, correcting those choices also requires historical-data and multi-version compatibility work.

Symptomโ€‹

I often see this opening: you say "design me a table to store orders." In seconds I hand you a version that looks complete enough โ€” id, user_id, amount, status, created_at, it runs. But look closely and it falls apart:

  • amount I made a float โ€” and it's money.
  • status I made a varchar, into which "pending", "paid", "PAID", "ๅทฒๆ”ฏไป˜" will all get stuffed over time.
  • No foreign-key constraint, so user_id can point at a user that doesn't exist.
  • No index, so when you query a user's order history by user_id it's a full table scan.
  • address I crammed into one field, never considering that a user has multiple addresses, and that the address will later need to be split into province/city/district for separate lookups.

Each one, on its own, "works." The problem is that once this schema ships and a few hundred thousand rows of real data pour in, every one of those points has to be corrected by a migration โ€” and a migration is nothing like changing code.

Why this happensโ€‹

I may validate only a normal write path without designing queries, constraints, historical data, and multiple client versions together. Such a schema stores the sample but may not preserve real business invariants.

Types, indexes, and constraints need business facts: monetary precision and currency, state transitions, uniqueness scope, volume, and query patterns cannot be inferred from field names alone. Code can also carry persistent state and compatibility contracts; it is misleading to treat code as freely changeable and schemas as uniquely expensive.

Fowler's evolutionary database and Parallel Change describe versioned migrations and expand / migrate / contract. They reduce evolution risk; they do not guarantee zero downtime, no data loss, or reversibility, or exactly three releases. I must state the conditions for migration, validation, rollback, or forward repair.

Consequencesโ€‹

  • Changing a shipped schema adds migration and compatibility work. Change a line of code: commit, run tests, merge. Change a shipped field's type: write a migration script, convert stored data, validate on a test DB, schedule a release window, plan recovery or forward repair โ€” and the more data there is, the slower and riskier the migration.
  • Historical data becomes baggage you can't shake off. Want to tighten free-text status into an enum? First you have to normalize every "PAID", "ๅทฒๆ”ฏไป˜", "paid" already in the DB โ€” and you may no longer be able to tell what each spelling originally meant. A careless schema cements dirty data into the foundation along with everything else.
  • You need downtime or a phased rollout where you wouldn't have to. For systems that can't tolerate downtime, changing a schema often has to go through expand-contract: add the new structure, dual-write through a transition, migrate the data, then drop the old (Martin Fowler calls this Parallel Change). The process has expand, migrate, and contract phases; release count depends on the system, and dual-schema coexistence must be validated โ€” complexity a forward-looking design could have spared you.
  • A wrong contract spreads outward. Once an interface contract is published and depended on downstream, changing it isn't just changing your DB โ€” it's coordinating with every caller. The more careless the schema, the more people you'll have to drag along later.

What to do insteadโ€‹

Don't let me "first hand over a table that can store it" โ€” make me first ask how the data is read, at what scale, and where it's heading, then define the contract; review key fields' types, constraints, and indexes one by one; route all changes through migration tooling, never by hand.

  • Hand me the read/write patterns and scale before asking for a schema. "What dimension is this table mainly queried by? Read-heavy or write-heavy? Roughly how many rows in a year? Which fields might later need to be searchable or sortable?" Put these in the prompt. I have no visceral sense of the data's future, so make it a hard, written input.
  • Force me to type key fields explicitly. Choose fixed-point decimals or integer minor units for money according to currencies and calculations; define precision, range, and rounding instead of directly using binary floating point for decimal accounting; a finite set of values uses an enum or a lookup table with a foreign key, not free text; add NOT NULL where it should be non-null, a unique constraint where it should be unique, an index on frequently queried columns. Make me answer, for each field, "why this type, and will it change."
  • Leave room to evolve for the "will-change" parts โ€” but not over-generalization. This is one line with two ends, the other being Over-engineering, not questioning your choices: that entry warns against "piling on complexity for requirements that don't exist," this one reminds you to "leave room for evolution that will actually arrive." The difference is whether there's a real basis: a user having multiple addresses is a business fact, so use a related table from the start instead of one address field; "maybe we'll need arbitrary key-value pairs someday" is pure speculation โ€” don't reach for an EAV mega-table. Looking ahead means defining the contract by known read/write and evolution directions, not making the schema a universal container.
  • Route every change through versioned migrations, don't hand-edit the DB. Write each schema change as a versioned, verifiable migration under version control and in CI, specifying replay/retry conditions and backup restoration or forward-repair plans; data-losing changes such as deletion or precision reduction cannot promise rollback โ€” this is the core of Evolutionary Database Design: the schema iterates and evolves alongside the code, rather than being set in stone once or operated on live.
  • When downtime isn't acceptable, explicitly ask for expand-contract. For destructive changes to a live system (changing types, dropping fields, splitting tables), make me give an "add new โ†’ dual-write โ†’ migrate โ†’ switch reads โ†’ drop old" step plan, not a single ALTER slammed on top.

Exampleโ€‹

Before:

You: design me a table to store orders.
Me: Sure!
CREATE TABLE orders (
id INT PRIMARY KEY,
user_id INT,
amount FLOAT, -- money as a float
status VARCHAR(20), -- enum as free text
address VARCHAR(200), -- assumes one user has one address
created_at DATETIME
);
-- no foreign-key constraint, no indexes, no constraint on status values

After:

You: before designing the orders table, ask first: it's mainly queried by user_id and
created_at; about 500k orders a year; amounts involve only confirmed two-decimal currencies within a validated range; a user has
multiple shipping addresses; status is a fixed state machine. Give a schema with types,
constraints, and indexes, and explain where you left room for known evolution.
Me: orders table: assuming two decimal places and a confirmed amount range, amount uses DECIMAL(12,2) plus a currency column; status uses an enum
(or a status lookup table with a foreign key), not free text; user_id gets a foreign-key
constraint; build a composite index on (user_id, created_at) to support your main query.
Addresses split into a separate addresses table keyed by order_id/user_id, because "a user
has multiple addresses" is a confirmed business fact โ€” this is leaving room for known
evolution, not over-generalization. All changes go in migration scripts under version
control; if a later type change or table split is needed, it goes through expand-contract
step migrations to avoid downtime.

Same table โ€” ask about the read/write patterns, scale, and evolution direction first, and I go from "tossing off a version that can store it" to "settling the data contract's bill three years out for you."

When the exception appliesโ€‹

"Ask about reads/writes and evolution before defining the schema" is the default gate โ€” but it assumes this schema will carry real data and evolve over time. In some settings, a careless table is exactly right:

  • A throwaway spike you'll definitely discard: you just want to check "does this query even work" or "is this idea viable," with data that's used once and never reaches production. A float for money or a varchar for status doesn't matter here โ€” spending time on forward-looking design is the waste.
  • One-off scripts and local analysis: a data import you run once and delete, a throwaway report. The schema has no "later," so there's nothing to pay for in evolution that won't happen.

The test: will this data be depended on long-term, and will it evolve? If yes, pin down read/write patterns and scale before defining the contract. If its lifespan is measured in hours and it's explicitly not going to production, careless is correct โ€” but say "this is a one-off spike" out loud, so it doesn't quietly grow into a real table.

Version notesโ€‹

Applicable versions

Rechecked the original database-evolution and Parallel Change guidance on 2026-10-29. Three phases do not imply three releases; migration depends on database DDL, locks, traffic, and client compatibility. The money example assumes confirmed two-decimal precision and range; other currencies or calculations need explicit precision/minor-unit and rounding rules. The contract-review principles remain applicable.

Further reading and sourcesโ€‹