Justine Acosta
JUSTINE ACOSTA · GMT+8 ·
All articles
BLOG / ARTICLE

The Schema Decisions You Can't Undo

Code is cheap to change and data isn't. A handful of early modeling choices decide how much your product costs to build for the next three years.

6 min readDatabasesArchitectureData modeling

Rewriting a component is an afternoon. Renaming a function is a keystroke. Changing how you represent a customer, after eighteen months and four hundred thousand rows, is a project with a rollback plan and a maintenance window.

That asymmetry is the whole reason data modeling deserves more care than the rest of the codebase. Not because it's harder to get right, but because it's much more expensive to get wrong.

Sort decisions by cost to reverse

Before agonizing over a schema, sort the choices by how hard each one is to change later. Most aren't hard at all.

Cheap, don't overthink: column names, indexes, adding a table, adding a nullable column, denormalizing for read performance, most query patterns. All of these are one migration and no data loss.

Expensive, think now:

  • The tenancy model
  • What a "user" is
  • How you represent money
  • How you represent time
  • Whether relationships are one-to-one or one-to-many
  • Whether deletes are real

Six things. That's the list worth a day of thought before you write the first migration.

Tenancy is the hardest to retrofit

If your product will ever be used by an organization rather than an individual (and B2B products always end up here), decide the tenancy model before anything else.

The trap is starting with users owning data directly:

create table project (
  id uuid primary key,
  user_id uuid not null references app_user(id),
  name text not null
);

This works perfectly until your first customer says "can my colleague see this?" Now every table needs an organization, every query needs a new filter, every permission check needs rewriting, and you need a data migration that invents an organization for each existing user and reassigns everything they own. That's weeks, and it touches every authorization path in the system, which is the worst possible place to do a large mechanical change.

Adding the organization on day one costs nothing:

create table project (
  id uuid primary key,
  org_id uuid not null references org(id),
  created_by uuid not null references app_user(id),
  name text not null
);

Single-user accounts are just organizations with one member. You'll never think about it again, and the day a customer asks for team access it's a feature, not a migration.

Money is integers, always

Floating point cannot represent 0.10 exactly. This is not a rounding inconvenience: it's arithmetic that silently produces wrong totals, and it will be found by an accountant, not by you.

Store minor units as integers: amount_cents bigint, or a numeric type with explicit precision. Never float or double.

Store the currency alongside every amount, even if you only support one today. Adding it later means auditing every existing row to assert what it was denominated in, and hoping the answer is uniform.

And keep amounts, not just relationships. When someone changes a product's price, historical orders must not change value. Copy the price onto the order at purchase time. Invoices are records of what happened, not queries against current state: this is the same reason accounting systems never edit a posted entry.

Time has more decisions in it than it looks

Three separate choices, often conflated:

Store instants in UTC, in a timestamp-with-time-zone column. Convert at display time. This is settled practice and the only mistake is failing to be consistent.

Store the user's time zone if you'll ever send them something scheduled. "9am" means different instants for different people, and you can't recover the intent from a UTC timestamp.

For anything recurring, store the rule and not the occurrences. A weekly meeting is every Tuesday 09:00 Asia/Manila, not a thousand precomputed rows. The moment daylight saving shifts somewhere, or someone edits the series, precomputed occurrences become wrong and there's no way to distinguish an intentional exception from stale data.

Also worth separating: created_at (when the row appeared) and the business date the row is about. They diverge constantly (a backdated invoice, an imported record, a retroactive correction) and conflating them makes every report subtly wrong.

The "one per" trap

Any time you model something as one-to-one, ask how confident you are.

  • One address per customer → billing and shipping differ.
  • One email per user → they want a work address for notifications.
  • One payment method → the card expires and they add another.
  • One image per product → they want a gallery.
  • One owner per account → they hire a second admin.

Every one of these starts as a column and becomes a table. The migration isn't technically hard, but it touches every read path, every form, and every place the singular value was assumed, which is everywhere, because it was a column.

The heuristic that's served me well: if you can construct a plausible story where a user wants two, model it as a collection now. A table with one row per parent costs you a join. Discovering you need it later costs you a sprint.

Decide about deletion once

Soft delete or hard delete: either is defensible. What's not defensible is choosing per-table as you go, which is what happens by default.

Hard delete is simpler, keeps queries honest, and makes data-deletion requests straightforward. Soft delete preserves history and lets you undo, at the price of where deleted_at is null on every query forever, and the one place someone forgets it becomes a bug where deleted records reappear.

Whichever you pick, apply it uniformly and enforce it somewhere structural: a view, a base query, or row-level security. Relying on developers to remember is relying on developers to never be in a hurry.

If you soft delete, also decide what a deletion request means. "Deleted" in your UI and "erased" under GDPR are different obligations, and only one of them is satisfied by setting a timestamp.

Getting out of a bad decision

You will get one of these wrong anyway. The way out is expand-contract, and it works for almost any schema change without downtime:

  1. Expand. Add the new structure alongside the old. Nothing reads it yet.
  2. Backfill. Populate it from the old structure, in batches, with the ability to resume.
  3. Dual-write. Write both, read from the old one. Let it soak.
  4. Flip reads. Read from the new one, keep writing both. This is your rollback point: reverting is a config change.
  5. Contract. Stop writing the old, then drop it, once you're confident.

Each step ships independently and is individually reversible. It's slower than a big-bang migration and vastly less frightening, which matters because the frightening version tends to be attempted at 2am.

What I'd actually do

Spend a day before the first migration. Write down, in plain sentences, what the core entities are and how they relate. Walk three real scenarios through the model out loud: a signup, a purchase, a team member being added. Ask the six expensive questions above.

Then start building, and don't agonize over anything not on that list. Column names can be fixed on a Tuesday.