Cracking ML Interviews

Open in the interactive study hub

Data Modeling

Data modeling is the discipline of translating business processes, operational constraints, and analytical needs into durable data structures. For a senior data engineer, it is not a documentation exercise. It is a control surface for correctness, performance, governance, cost, and long-term change velocity.

Well-modeled systems make downstream work easier: analytics becomes interpretable, machine learning features become reproducible, and operational services can evolve without every schema change turning into a breaking event. Poor modeling creates the opposite outcome: brittle joins, duplicate logic, silent metric drift, and expensive rework.


What Data Modeling Is and Why It Matters

Data modeling defines:

At enterprise scale, modeling decisions directly affect:

The correct question is rarely "What is the ideal schema?" The better question is "What model best serves the operating and analytical reality of this business with acceptable complexity?"


Conceptual, Logical, and Physical Data Models

These are separate layers. Teams that skip that separation usually mix business semantics with engine-specific implementation too early.

Model Type Purpose Audience Typical Content Common Mistake
Conceptual Define core business concepts and boundaries Business stakeholders, architects Customer, Order, Product, Subscription Treating conceptual entities as tables too early
Logical Define attributes, relationships, keys, and business rules Data engineers, analytics engineers, architects Entity relationships, cardinality, optionality, domains Ignoring grain and temporal rules
Physical Implement for a specific engine and workload Data engineers, DBAs, platform engineers Partitioning, clustering, indexes, file layout, compression Copying logical design without tuning for access patterns

Practical Example

For a commerce platform:

If you jump directly into physical tables, you usually encode the first use case instead of the stable business model.


OLTP vs OLAP Modeling

Operational and analytical systems should not be modeled the same way by default.

Characteristic OLTP Modeling OLAP Modeling
Primary goal Correct transactional updates Fast reads and aggregations
Typical workload Point lookups, inserts, updates, deletes Scans, joins, aggregates, time-series analysis
Data shape Normalized Denormalized or dimensional
Latency target Milliseconds for transactions Seconds to minutes for broad queries
History handling Often current-state oriented Usually historical and audit-friendly
Typical engines Postgres, MySQL, SQL Server Snowflake, BigQuery, Redshift, Databricks, DuckDB

When to Use OLTP Modeling

When Not to Use OLTP Modeling

When to Use OLAP Modeling

When Not to Use OLAP Modeling

Common mistake: forcing a normalized application schema into the warehouse and asking analysts to rebuild business semantics in every query.


Keys and Relationships

Keys determine both integrity and usability. Weak key design creates duplicate facts, broken joins, and unstable lineage.

Primary Keys

Primary keys uniquely identify a row within a table. In analytical platforms, they are often logical rather than physically enforced, so teams must validate them with tests.

Foreign Keys

Foreign keys express relationships between entities. Even if the warehouse does not enforce them, the model should declare them semantically and validate them in tests or contracts.

Surrogate Keys

Surrogate keys are synthetic identifiers, typically integers, hashes, or UUIDs, created independently of business meaning.

Use surrogate keys when:

Natural Keys

Natural keys come from the business domain, such as email, order_number, or country_code.

Use natural keys when:

Do not confuse familiarity with stability. Email addresses, SKU names, and human-readable codes often change more than teams expect.

Practical Guidance

Key Type Pros Cons Typical Use
Natural key Business-readable, easy for debugging May change, may not be globally unique Stable reference data
Surrogate integer Efficient joins, compact storage Requires mapping logic Warehouse dimensions
UUID Easy distributed generation Large, less efficient for some workloads Event IDs, distributed systems
Hash key Useful for dedupe and integration Collision risk, opaque to users Data Vault hubs, lakehouse merge keys

Common Mistakes


Normalization vs Denormalization

Normalization reduces redundancy and update anomalies. Denormalization reduces join cost and improves read performance. Neither is universally better.

Topic Normalized Model Denormalized Model
Read performance Lower for wide analytical queries Higher for common analytics queries
Write integrity Stronger Weaker unless carefully managed
Redundancy Lower Higher
Ease of change Better for transactional domains Better for stable reporting domains
Ease for analysts Lower Higher
Typical use OLTP systems Data marts, serving layers

When to Use Normalized Models

When Not to Use Normalized Models

When to Use Denormalized Models

When Not to Use Denormalized Models

Common Mistakes


Dimensional Modeling

Dimensional modeling is still the default recommendation for business analytics and BI because it optimizes for understandable queries, stable metrics, and predictable performance.

Facts

Facts represent measurable business events at a specific grain.

Examples:

Good fact tables define:

Dimensions

Dimensions describe the context around facts.

Examples:

Dimensions should carry descriptive attributes used for filtering, grouping, and slicing metrics.

Star Schema

A star schema has a central fact table with directly connected denormalized dimensions.

dim_customer   dim_product   dim_date
      \             |          /
           fact_order_line
                |
           dim_channel

Pros

Cons

When to Use

Common Mistakes

Snowflake Schema

A snowflake schema normalizes one or more dimensions into additional related tables.

Use it when:

Do not choose snowflake by default for BI. It usually increases query complexity faster than it increases value.

Slowly Changing Dimensions (SCD)

Historical behavior is a modeling choice, not an accident.

SCD Type Behavior Use Case Main Risk
Type 0 Keep original value forever Immutable attributes Limited correction flexibility
Type 1 Overwrite current value Typos, non-historical cleanup Loses history
Type 2 New row per change with effective dates Customer tier, product category changes Larger dimensions and more complex joins
Type 3 Add previous value columns Limited before/after analysis Poor scalability for many changes
Type 4 Current table plus history table Large history management separation Dual-table complexity
Type 6 Hybrid of 1, 2, and 3 Complex reporting with current and historical views High implementation complexity

Practical Example: Fact and Dimension Grain

Bad model:

Better model:

This allows revenue by product, by channel, by customer cohort, and by fulfillment path without re-deriving grain later.


Data Vault Basics

Data Vault is an integration-oriented modeling approach optimized for auditability, historical traceability, and parallel ingestion from many source systems.

Core structures:

Simplified Example

Hub_Customer(customer_bk, customer_hk, load_ts, record_source)
Hub_Order(order_bk, order_hk, load_ts, record_source)
Link_Customer_Order(customer_hk, order_hk, link_hk, load_ts)
Sat_Customer_Profile(customer_hk, customer_name, segment, effective_ts)
Sat_Order_Status(order_hk, status, amount, effective_ts)

When to Use Data Vault

When Not to Use Data Vault

Pros

Cons

Common Mistakes

In practice, many enterprise teams use Data Vault for integration and lineage, then publish dimensional or domain-serving marts for consumption.


Modeling for Analytics, BI, Machine Learning, and Operational Systems

Different consumers need different shapes of truth.

Consumer Model Preference Why
Operational application Normalized OLTP Transaction correctness and efficient updates
BI dashboards Dimensional marts Predictable joins and business-friendly semantics
Ad hoc analytics Wide marts plus reusable conformed dimensions Speed with enough semantic control
Machine learning training Event-level tables, snapshot tables, feature views Point-in-time correctness and reproducibility
Online inference Narrow, low-latency feature serving model Fast lookup and freshness guarantees

Modeling for Analytics and BI

Prefer:

Modeling for Machine Learning

Prefer:

Common ML mistake: training on a denormalized "latest state" table that accidentally includes future information.

Modeling for Operational Systems

Prefer:


Modeling for Lakehouse Environments

Lakehouse environments change the physical implementation, not the need for good modeling.

What changes in a lakehouse:

Warehouse Modeling vs Lakehouse Modeling

Topic Warehouse-Centric Modeling Lakehouse-Centric Modeling
Storage abstraction Managed warehouse tables Open table formats on object storage
Change handling Often warehouse-native DML Merge/upsert plus incremental file compaction
Performance tuning Distribution, sort keys, clustering Partitioning, clustering, file size, compaction
Governance risk More centralized controls Easier sprawl if contracts are weak
Typical advantage Simplicity for BI Flexibility across BI, DS, and ML workloads

When to Use Lakehouse-Oriented Modeling

When Not to Use It


Schema Evolution and Schema Design Best Practices

Schema evolution should be intentional, versioned, and observable.

Best Practices

Common Evolution Strategies

Change Type Recommendation
Add nullable column Usually safe if semantics are clear
Rename column Prefer additive migration with deprecation window
Change meaning of an existing field Create a new field; do not silently repurpose
Split one table into many Publish compatibility views during migration
Change event key or grain Treat as a contract change and version it explicitly

Common Mistakes


Partitioning and Clustering Considerations

Partitioning and clustering are physical design choices. They should follow workload evidence, not vendor marketing.

Partitioning

Use partitioning when:

Avoid over-partitioning. Tiny partitions create metadata overhead and poor scan efficiency.

Good partition candidates:

Bad partition candidates:

Clustering

Clustering improves locality for frequently filtered or joined columns.

Use clustering when:

Common Mistakes


Data Quality Implications of Modeling Choices

Modeling decisions either surface or hide quality problems.

Examples:

Quality Controls That Should Map to the Model

Modeling Concern Quality Check
Primary key uniqueness Unique and not-null tests
Foreign key integrity Relationship tests
Fact grain Duplicate detection on grain-defining columns
SCD behavior Non-overlapping effective date tests
Event ordering Late-arrival and watermark monitoring
Schema stability Contract validation and drift alerts

Good models make quality checks obvious. If the testing strategy is hard to define, the model is usually underspecified.


Comparison: Dimensional Modeling vs Data Vault

Topic Dimensional Modeling Data Vault
Primary goal Business consumption and analytics Enterprise integration and history
Consumer friendliness High Low to medium
Change tolerance Moderate High
Time to first dashboard Fast Slower
Auditability Good if designed well Excellent
Number of tables Lower Higher
Best fit BI, semantic layers, reporting marts Multi-source ingestion, lineage-heavy programs

Decision Guidance

Choose dimensional modeling when the main problem is consistent business reporting.

Choose Data Vault when the main problem is integrating many changing source systems with traceable history.

In many enterprises, the right answer is both:


Comparison: Normalized vs Denormalized Models

Topic Normalized Denormalized
Best for Operational correctness Analytical usability
Redundancy Low Higher
Write complexity Lower anomaly risk Higher anomaly risk
Read complexity Higher Lower
Change management Stronger in transactional domains Stronger in reporting domains

Decision Guidance

Choose normalized structures for transactional domains and canonical integration entities.

Choose denormalized structures when the same joins are executed repeatedly by analysts, dashboards, or serving layers.


Comparison: Warehouse Modeling vs Lakehouse Modeling

Topic Warehouse Modeling Lakehouse Modeling
Main bias Managed analytical simplicity Flexible multi-engine platform
Governance posture Often centralized Must be designed explicitly
Change handling More warehouse-managed More platform-engineering responsibility
ML alignment Good, but sometimes secondary Usually better aligned with DS and ML workloads

Decision Guidance

If the organization is analytics-first and wants a tightly managed platform, warehouse-centric modeling is often the better operating model.

If the organization needs shared access across analytics, data science, ML, and streaming use cases, lakehouse modeling often pays off more, but only if metadata and table-management discipline are strong.


Common Anti-Patterns


Best Practices and Decision Framework

Use this sequence when deciding how to model a domain:

  1. Define the business process or entity boundary.
  2. Declare the grain explicitly.
  3. Identify stable keys and change behavior.
  4. Separate canonical integration models from serving models.
  5. Choose the consumer shape:
    • normalized for operations
    • dimensional for BI
    • event or feature oriented for ML
  6. Choose the physical design:
    • partitioning
    • clustering
    • compaction
    • incremental strategy
  7. Attach quality tests and ownership to the model.
  8. Document the contract and the reasons behind the design.

Opinionated Guidance


Final Summary

Good data modeling is less about formal diagrams and more about durable decisions:

Dimensional modeling remains the most practical default for analytics and BI. Normalized models remain the right default for operational systems. Data Vault is valuable for integration-heavy, high-change enterprises when used with discipline and automation. Lakehouse platforms expand implementation options, but they do not remove the need for clear keys, grain, historical strategy, and governed schemas.

If a model is easy to query, hard to misuse, resilient to source change, and explicit about time and grain, it is usually on the right track.

View or edit this guide on GitHub