principleMajorpending
Principle: Single source of truth
Viewed 0 times
single-source-of-truthSSOTduplicationconsistencynormalization
Problem
When the same information exists in multiple places, they inevitably go out of sync. Bugs arise from using the stale copy.
Solution
Every piece of knowledge should have one authoritative source:
Bad: user email in users table AND in orders table
Good: orders references users.id, join for email
Bad: version in package.json AND in docker-compose AND in CI
Good: Read version from package.json everywhere
Bad: API types defined in frontend AND backend
Good: OpenAPI spec generates types for both
Bad: Same state in parent and child via two-way binding
Good: Lift state up, pass down as props
Bad: README manually duplicates code behavior
Good: Tests document behavior, API docs auto-generated
When caching or denormalizing (read replicas, CDN, search index):
- Data: One database table owns each entity
Bad: user email in users table AND in orders table
Good: orders references users.id, join for email
- Configuration: One config file, derived elsewhere
Bad: version in package.json AND in docker-compose AND in CI
Good: Read version from package.json everywhere
- Types: Generate from schema, don't duplicate
Bad: API types defined in frontend AND backend
Good: OpenAPI spec generates types for both
- State: One component owns each piece of state
Bad: Same state in parent and child via two-way binding
Good: Lift state up, pass down as props
- Documentation: Code as source, docs generated
Bad: README manually duplicates code behavior
Good: Tests document behavior, API docs auto-generated
When caching or denormalizing (read replicas, CDN, search index):
- Acknowledge these are copies, not sources
- Have a clear invalidation strategy
- Document which is the source of truth
Why
Duplicated knowledge creates maintenance burden and inconsistency. Changes must be made in N places instead of 1, and forgetting any creates bugs.
Revisions (0)
No revisions yet.