Marketplace
data-modeling
Use when designing data models, database schemas, or choosing between modeling approaches. Covers dimensional modeling, star schema, data vault, entity-relationship design, and schema evolution.
allowed_tools: Read, Glob, Grep
$ Installer
git clone https://github.com/melodic-software/claude-code-plugins /tmp/claude-code-plugins && cp -r /tmp/claude-code-plugins/plugins/systems-design/skills/data-modeling ~/.claude/skills/claude-code-plugins// tip: Run this command in your terminal to install the skill
SKILL.md
name: data-modeling description: Use when designing data models, database schemas, or choosing between modeling approaches. Covers dimensional modeling, star schema, data vault, entity-relationship design, and schema evolution. allowed-tools: Read, Glob, Grep
Data Modeling
Comprehensive guide to data modeling techniques for operational databases, data warehouses, and analytical systems.
When to Use This Skill
- Designing database schemas
- Choosing between modeling approaches
- Building data warehouses
- Planning schema evolution
- Understanding trade-offs in data models
- Designing for analytics vs operations
Data Modeling Fundamentals
Types of Data Models
Data Model Categories:
1. Conceptual Model
Purpose: Business understanding
Audience: Business stakeholders
Content: Entities, relationships, business rules
Detail: High-level, no implementation details
2. Logical Model
Purpose: Structure definition
Audience: Data architects
Content: Tables, columns, keys, relationships
Detail: Database-agnostic design
3. Physical Model
Purpose: Implementation
Audience: Database engineers
Content: Indexes, partitions, storage
Detail: Database-specific optimization
Model Evolution:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ Business Conceptual Logical Physical โ
โ Requirements โโโบ Model โโโบ Model โโโบ Model โ
โ โ
โ "Customers Customer โโโโโโบ customers customers โ
โ make orders" Order โโโ id โโโ id PK โ
โ โโโ< makes โโโ name โโโ name โ
โ โโโ email โโโ email โ
โ โโโ idx_* โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Operational vs Analytical
Operational (OLTP) vs Analytical (OLAP):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OLTP โ
โ (Online Transaction Processing) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Purpose: Run the business โ
โ Workload: Many small transactions โ
โ Model: Normalized (3NF) โ
โ Optimize: Write performance, consistency โ
โ Users: Applications, services โ
โ Example: INSERT new order, UPDATE inventory โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OLAP โ
โ (Online Analytical Processing) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Purpose: Analyze the business โ
โ Workload: Few complex queries โ
โ Model: Denormalized (star/snowflake) โ
โ Optimize: Read performance, aggregation โ
โ Users: Analysts, BI tools โ
โ Example: SUM(sales) GROUP BY region, month โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
When to Use Each:
โโโ OLTP: User-facing applications, real-time operations
โโโ OLAP: Reporting, dashboards, machine learning
โโโ Hybrid: Some systems need both (HTAP)
Normalization
Normal Forms
Database Normalization:
1NF (First Normal Form):
โโโ Eliminate repeating groups
โโโ Create separate table for related data
โโโ Identify each row with primary key
โโโ Each cell contains single value
Example (SQL Server - PascalCase):
โ Orders (Id, Item1, Item2, Item3)
โ Orders (Id, ...) + OrderItems (OrderId, ItemId)
2NF (Second Normal Form):
โโโ Meet 1NF requirements
โโโ Remove partial dependencies
โโโ Non-key columns depend on entire primary key
Example (SQL Server - PascalCase):
โ OrderItems (OrderId, ProductId, ProductName)
โ OrderItems (OrderId, ProductId) + Products (ProductId, ProductName)
3NF (Third Normal Form):
โโโ Meet 2NF requirements
โโโ Remove transitive dependencies
โโโ Non-key columns depend only on primary key
Example (SQL Server - PascalCase):
โ Orders (Id, CustomerId, CustomerCity)
โ Orders (Id, CustomerId) + Customers (Id, City)
BCNF (Boyce-Codd Normal Form):
โโโ Meet 3NF requirements
โโโ Every determinant is a candidate key
โโโ Handles multi-valued dependencies
Higher Normal Forms (4NF, 5NF):
โโโ Handle complex multi-valued dependencies
โโโ Rarely used in practice
โโโ Can lead to over-normalization
When to Denormalize
Normalization Trade-offs:
Normalized (3NF):
โโโ Pros: Data integrity, no redundancy, smaller storage
โโโ Cons: Complex joins, slower reads
โโโ Use: OLTP, write-heavy workloads
Denormalized:
โโโ Pros: Faster reads, simpler queries
โโโ Cons: Redundancy, update anomalies, larger storage
โโโ Use: OLAP, read-heavy workloads
Denormalization Triggers:
1. Read performance is critical
2. Write frequency is low
3. Data changes infrequently
4. Queries frequently join same tables
5. Aggregations are common
Controlled Denormalization Patterns:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pattern: Summary Tables โ
โ Keep normalized + materialized aggregates โ
โ โ
โ orders โโโ โ
โ items โโโผโโโบ daily_sales_summary (materialized) โ
โ productsโโ โ
โ โ
โ Best of both: Write to normalized, read from summary โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Dimensional Modeling
Star Schema
Star Schema:
Central fact table surrounded by dimension tables.
โโโโโโโโโโโโโโโโ
โ dim_date โ
โโโโโโโโโโโโโโโโ
โ date_key PK โ
โ date โ
โ month โ
โ quarter โ
โ year โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโโโโโโโโโ โโโโโโโโดโโโโโโโโ โโโโโโโโโโโโโโโโ
โ dim_product โ โ fact_sales โ โ dim_customer โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ product_key PKโโโโโ date_key FK โโโโโบโ customer_key PKโ
โ product_name โ โ product_key FKโ โ customer_nameโ
โ category โ โ customer_key FKโ โ segment โ
โ brand โ โ store_key FK โ โ region โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ quantity โ
โ revenue โ โ
โ cost โ โ
โโโโโโโโฌโโโโโโโโ โโโโโโโโดโโโโโโโโ
โ โ dim_store โ
โโโโโโโโโโโโโบโโโโโโโโโโโโโโโโ
โ store_key PKโ
โ store_name โ
โ city โ
โ state โ
โโโโโโโโโโโโโโโโ
Star Schema Benefits:
โโโ Simple queries (few joins)
โโโ Optimized for aggregation
โโโ Intuitive for business users
โโโ Works well with BI tools
โโโ Predictable query performance
Fact Table Types:
โโโ Transaction: One row per event (sale, click)
โโโ Periodic Snapshot: One row per period (daily balance)
โโโ Accumulating Snapshot: Track progress (order lifecycle)
โโโ Factless: Events without measures (attendance)
Snowflake Schema
Snowflake Schema:
Normalized dimensions (dimensions have sub-dimensions).
โโโโโโโโโโโโโโโโ
โ dim_date โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโโโโโโโโโ โโโโโโโโดโโโโโโโโ โโโโโโโโโโโโโโโโ
โ dim_category โโโโโโ dim_product โ โ dim_customer โ
โโโโโโโโโโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ
โ โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโ
โ โโโโโโโโดโโโโโโโโ โ โ
โ โ fact_sales โ โ โ
โ โโโโโโโโฌโโโโโโโโ โ โ
โ โ โ โ
โ โโโโโโโโดโโโโโโโโ โโโโโโโโดโโโโโโโ
โ โ dim_store โ โ dim_segment โ
โ โโโโโโโโฌโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ
โ โโโโโโโโดโโโโโโโโ
โ โ dim_city โ
โ โโโโโโโโโโโโโโโโ
Star vs Snowflake:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Factor โ Star โ Snowflake โ
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโค
โ Query simplicityโ Simpler โ More complex โ
โ Query speed โ Faster (fewer joins)โ Slower โ
โ Storage โ More (redundancy) โ Less (normalized) โ
โ Maintenance โ Easier โ More complex โ
โ BI tool support โ Better โ May need modeling โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Recommendation: Prefer star schema unless storage is critical concern.
Slowly Changing Dimensions
Slowly Changing Dimensions (SCD):
How to handle dimension changes over time.
Type 0: Retain Original
โโโ Never update dimension
โโโ Use for: Attributes that shouldn't change
Type 1: Overwrite
โโโ Update in place, lose history
โโโ Use for: Corrections, non-historical attributes
Type 2: Add New Row (Most Common)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ customer_keyโ customer_id โ address โ valid_from โ valid_to โ currentโ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ 1001 โ C123 โ 123 Oak St โ 2020-01-01 โ 2023-06-30โ false โ
โ 1002 โ C123 โ 456 Pine Ave โ 2023-07-01 โ 9999-12-31โ true โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโ New surrogate key, track validity period
โโโ Use for: Full history required
Type 3: Add New Column
โโโ Previous and current value columns
โโโ Use for: Limited history (just previous)
Type 4: History Table
โโโ Current in main table, history in separate table
โโโ Use for: Frequent changes, large dimensions
Type 6: Hybrid (1+2+3)
โโโ Combines approaches for flexibility
โโโ Use for: Complex requirements
Data Vault
Data Vault Architecture
Data Vault Modeling:
Enterprise data warehouse pattern for agility and auditability.
Components:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DATA VAULT โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ HUBS (Business Keys) โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ hub_customer โ โ
โ โ โโโ hub_key PK โ โ Surrogate key โ
โ โ โโโ customer_id โ โ Business key โ
โ โ โโโ load_date โ โ When loaded โ
โ โ โโโ source โ โ Where from โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ LINKS (Relationships) โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ link_customer_orderโ โ
โ โ โโโ link_key PK โ โ
โ โ โโโ hub_customer_fkโ โ
โ โ โโโ hub_order_fk โ โ
โ โ โโโ load_date โ โ
โ โ โโโ source โ โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ SATELLITES (Descriptive Data) โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ sat_customer_detailsโ โ
โ โ โโโ hub_customer_fkโ โ
โ โ โโโ load_date PK โ โ Part of PK โ
โ โ โโโ name โ โ Descriptive attributes โ
โ โ โโโ email โ โ
โ โ โโโ hash_diff โ โ Change detection โ
โ โ โโโ source โ โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Data Vault Benefits:
โโโ Full audit trail (all changes tracked)
โโโ Source system agnostic
โโโ Parallel loading possible
โโโ Handles schema changes gracefully
โโโ Good for regulatory requirements
Data Vault Challenges:
โโโ Complex queries (many joins)
โโโ Requires presentation layer
โโโ Steep learning curve
โโโ More storage than star schema
โโโ Not suitable for direct BI access
When to Use Data Vault
Data Vault Decision Matrix:
Use Data Vault When:
โโโ Multiple source systems with different schemas
โโโ Regulatory requirements for audit trails
โโโ Schema changes are frequent
โโโ Historical accuracy is critical
โโโ Large enterprise with complex data landscape
โโโ Data integration from acquisitions
Use Star Schema When:
โโโ Simpler reporting requirements
โโโ Single source system
โโโ Fast query performance priority
โโโ Business users query directly
โโโ Smaller scale, simpler needs
โโโ Quick time to value needed
Hybrid Approach:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ Source โโโบ Data Vault โโโบ Star Schema โโโบ BI Tools โ
โ Systems (Raw Vault) (Presentation) (Reports) โ
โ โ
โ Benefits: โ
โ โโโ Raw vault: Full history, audit โ
โ โโโ Star schema: Query performance โ
โ โโโ Decoupled: Change raw without breaking reports โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Schema Evolution
Schema Evolution Patterns
Schema Evolution Strategies:
1. Additive Changes (Safest)
โโโ Add new columns with defaults
โโโ Add new tables
โโโ Add new indexes
Safe: Does not break existing queries
ALTER TABLE users ADD COLUMN phone VARCHAR(20) DEFAULT NULL;
2. Non-Breaking Changes
โโโ Widen column types (VARCHAR(50) โ VARCHAR(100))
โโโ Remove NOT NULL constraint
โโโ Add optional foreign keys
Usually safe, verify with testing
3. Breaking Changes (Dangerous)
โโโ Rename columns/tables
โโโ Remove columns
โโโ Change column types
โโโ Add NOT NULL without default
Requires migration strategy
Migration Patterns:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pattern: Expand-Contract โ
โ โ
โ Phase 1 (Expand): โ
โ โโโ Add new column (name_new) โ
โ โโโ Write to both old and new โ
โ โโโ Backfill new column โ
โ โ
โ Phase 2 (Migrate): โ
โ โโโ Update readers to use new column โ
โ โโโ Verify all systems migrated โ
โ โ
โ Phase 3 (Contract): โ
โ โโโ Remove old column โ
โ โ
โ Timeline: Days to weeks per phase โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Versioning Strategies
Schema Versioning:
1. Single Schema (Most Common)
โโโ One schema, evolve in place
โโโ Use migrations (Flyway, Liquibase)
โโโ All applications use same version
2. Multi-Version Schema
โโโ Multiple schema versions exist
โโโ Applications specify version
โโโ Complex but allows gradual migration
Example: v1_users, v2_users
3. Event Sourcing
โโโ Store events, not state
โโโ Replay to any schema version
โโโ Most flexible, most complex
Events: UserCreated, UserNameChanged, UserDeleted
โ Replay to construct current state
Migration Tools:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Tool โ Language โ Approach โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Flyway โ Java/SQL โ SQL migrations, versioned โ
โ Liquibase โ Java/XML โ Changelog format, rollback โ
โ Alembic โ Python โ SQLAlchemy integration โ
โ Entity Frameworkโ .NET โ Code-first migrations โ
โ Prisma โ TypeScript โ Declarative schema โ
โ Atlas โ Go โ Declarative + imperative โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Keys and Identifiers
Primary Key Strategies
Primary Key Options:
1. Natural Keys
โโโ Business identifier (email, SSN, ISBN)
โโโ Pros: Meaningful, unique in business
โโโ Cons: Can change, privacy concerns
โโโ Use: When truly immutable
2. Surrogate Keys (Recommended)
โโโ Auto-increment integer
โโโ Pros: Simple, performant, stable
โโโ Cons: Meaningless, DB-specific
โโโ Use: Most operational systems
3. UUIDs
โโโ Universally unique identifier
โโโ Pros: Globally unique, distributed generation
โโโ Cons: Larger, less performant
โโโ Use: Distributed systems, external exposure
4. ULIDs / Snowflake IDs
โโโ Time-sortable unique identifiers
โโโ Pros: Sortable, unique, distributed
โโโ Cons: More complex generation
โโโ Use: Time-series, event systems
Comparison:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Type โ Size โ Sortable โ Distributed โ Example โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโค
โ Auto-incrementโ 4-8 bytesโ Yes โ No โ 12345 โ
โ UUID v4 โ 16 bytesโ No โ Yes โ a1b2c...โ
โ UUID v7 โ 16 bytesโ Yes โ Yes โ 0188... โ
โ ULID โ 16 bytesโ Yes โ Yes โ 01H5... โ
โ Snowflake โ 8 bytes โ Yes โ Yes โ 7890... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Composite Keys
Composite Keys:
Primary keys with multiple columns.
Use Cases:
โโโ Junction tables (many-to-many)
โโโ Time-series with partitioning
โโโ Multi-tenant systems
โโโ Natural business keys
Example: Order Items (SQL Server - PascalCase)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OrderItems โ
โ โโโ OrderId PK, FK โ
โ โโโ LineNumber PK (composite with OrderId) โ
โ โโโ ProductId FK โ
โ โโโ Quantity โ
โ โโโ Price โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Trade-offs:
โโโ Pros: Enforces uniqueness, natural ordering
โโโ Cons: Complex foreign keys, ORM challenges
โโโ Alternative: Surrogate key + unique constraint
Best Practices
Data Modeling Best Practices:
1. Understand the Use Case First
โโโ OLTP vs OLAP requirements
โโโ Query patterns expected
โโโ Write vs read ratio
โโโ Growth expectations
2. Start Normalized, Denormalize with Reason
โโโ Begin with 3NF for operational
โโโ Denormalize only for proven performance needs
โโโ Document denormalization decisions
โโโ Consider materialized views first
3. Use Consistent Naming (Database-Specific)
โโโ Singular table names (User, not Users)
โโโ SQL Server: PascalCase (CustomerId, OrderDate, CreatedAt)
โโโ PostgreSQL: snake_case (customer_id, order_date, created_at)
โโโ Foreign keys: {Entity}Id or {entity}_id per convention
โโโ Avoid reserved words
4. Document Everything
โโโ Column descriptions
โโโ Relationship meanings
โโโ Business rules
โโโ Change history
5. Plan for Change
โโโ Use surrogate keys
โโโ Design for schema evolution
โโโ Version your schemas
โโโ Test migrations thoroughly
6. Consider Performance Early
โโโ Index strategy
โโโ Partitioning needs
โโโ Data types (smallest sufficient)
โโโ Query patterns
Anti-Patterns
Data Modeling Anti-Patterns:
1. "One Table to Rule Them All"
โ Single table with many nullable columns
โ Proper entity separation
2. "Entity-Attribute-Value (EAV)"
โ Generic key-value tables
โ Proper columns or JSON fields
3. "CSV in a Column"
โ Comma-separated values in one field
โ Proper junction table
4. "Premature Denormalization"
โ Denormalize without measuring
โ Start normalized, optimize with data
5. "No Foreign Keys"
โ Skipping FK for 'performance'
โ Use FK for integrity, consider indexes
6. "Meaningless Names"
โ table1, field_a, temp_data
โ Descriptive, consistent naming
Related Skills
data-architecture- Data lake, lakehouse, data meshstream-processing- Real-time data modelingdatabase-scaling- Scaling data systemsetl-elt-patterns- Data transformation
Repository

melodic-software
Author
melodic-software/claude-code-plugins/plugins/systems-design/skills/data-modeling
3
Stars
0
Forks
Updated5d ago
Added1w ago