Database Design: Pragmatic Schema Engineering

Schema design decisions compound over time. A resilient database is built on pragmatic normalization, consistent column standards, and robust constraints.

I. Normalization and Consistency

Start in Third Normal Form (3NF) to eliminate data redundancy and preserve the single source of truth. Denormalize only when performance metrics demonstrate that join costs exceed the overhead of managing duplicate state.

Standard Column Infrastructure

Every mutable table should include the following standard columns:


II. Key Selection: Surrogate vs. Natural

Always favor surrogate keys for primary and foreign keys. Natural keys should be enforced via Unique Constraints but never used as the target for a relationship.

Key TypeStrengthWeakness
BIGINTSequential, small (8 bytes), cache-friendly.Reveals creation order; centralized sequence.
UUID v4Distributed, random (16 bytes).Fragmented indexes; poor locality.
UUID v7Timestamp-prefixed (2024 standard).Recommended default: Locality of BIGINT with the distributability of UUID.

III. Data Integrity and Constraints

The database is the final arbiter of correctness. Do not rely exclusively on application-layer validation.


IV. Architectural Patterns

Soft Delete

Use soft delete selectively for data where "undo" is expected. For derived or ephemeral data, use hard DELETE to maintain index performance and storage efficiency.

Audit and History

For high-integrity domains, use History Tables. A database trigger writes a row snapshot to a parallel table on every change, providing a verifiable audit trail with minimal application logic overhead.

Multi-Tenancy with RLS

Implement shared-schema multi-tenancy using Postgres Row-Level Security (RLS). By binding the tenant_id to the session context, the database enforces isolation at the storage layer, preventing cross-tenant leakage even if application queries omit a WHERE clause.

Indexing Strategy

V. Migration Discipline

Schema changes must be versioned, immutable, and additive-by-default.