Overview
Curated: · Written: · Reviewed:
Semantic Data Modeling for BI
In one line
A semantic layer compiles each business metric (revenue, conversion, active subscribers) from one governed definition with declared grain, keys, time basis, exclusions and access rules, so every dashboard, notebook and agent gets the same scoped number. Reach for it when the same name is being computed differently in more than one place.
Key definitions
- Grain: what one row of a fact table represents. Declare it before designing the table and test that it holds.
- Fan-out: a join between facts at different grains repeats one side's values, so totals inflate.
- Additivity: fully additive measures sum everywhere; semi-additive ones (balances, inventory) do not sum across time; non-additive ones (ratios, distinct counts) must be recomputed from numerator and denominator.
- Conformed dimension: one agreed key, hierarchy and change behaviour shared by several facts.
- Time basis: the timestamp that stamps a fact (event, booking, settlement, ingestion). Choose it per metric.
- As-of join: a join to a type-2 dimension that filters on validity dates, not just the natural key.
Formulas and complexity
Pooled across segments. The average of segment rates is wrong.
For HyperLogLog with m registers. Storage per sketch is m times 6 bits. For 200 countries over 90 days, m = 16384 gives about 0.81% error and about 221 MB, which fits the 250 MB limit. m = 8192 gives about 1.15% and fails.
How it works
The metric is declared once with its formula, grain, population, exclusions, time basis and access rule. A consumer requests the metric by name and dimensions. The layer compiles SQL that joins facts only through conformed dimensions, applies row-level security at a trusted boundary, and either serves a pre-aggregation whose grain, filters and currency match or queries the base facts.
When to use and when not to
| Situation | Use a semantic layer | Keep the logic in the BI tool |
|---|---|---|
| Same metric read by several tools or agents | Yes | No |
| One team, one dashboard, exploratory | No | Yes |
| Metric feeds a board deck or contract | Yes, with owner and version | No |
| Definition still changing weekly | Only as a versioned draft | Acceptable |
| Needs row or column security across consumers | Yes, enforced at query boundary | Dashboard-only filters are insufficient |
Traps interviewers probe
- Joining facts at different grains. Joining order headers to shipments multiplies revenue per shipment. Fix: aggregate each fact to the shared grain first, or keep them in separate tables joined through conformed dimensions.
- Summing ratios or semi-additive measures. Averaging segment conversion rates or summing inventory across days gives wrong totals. Fix: store numerator and denominator and recompute; use end-of-period or average for balances.
- Joining slowly changing dimensions on the natural key alone. Both rows of a type-2 dimension match, so each fact counts twice. Fix: join on the surrogate key or add an as-of predicate on validity dates.
- Ignoring NULL in filters. A predicate like is_refunded = false drops NULL rows silently. Fix: state the NULL semantics in the contract and test them.
- Caching without the full scope. Keys that omit tenant, metric version or currency return another caller's or another definition's result. Fix: include all of them in the key, or partition the cache.
Interview tips
Open with the contract: "A semantic layer owns definition and access. The warehouse owns storage and keys. The BI tool owns presentation." Then name the contract fields that matter for the question.
Expect these follow-ups:
- Two dashboards differ by 3%: diff grain, population, time basis, currency and version before reading SQL.
- Late corrections: version the change and keep the closed period's value reproducible.
- Late dimension members: load facts to an unknown-member key so reconciliation ties out, then reassign when the real row arrives.
- Role-playing dates: create one alias per role from a single calendar table.
- Competing definitions: rename to distinct certified metrics and migrate consumers under the owner's decision.
- Natural-language queries: resolve to certified metrics only, and reject requests whose grain the metric does not support.
30-second outline: definition in one sentence; the grain and time basis; the join path that prevents fan-out; the security and cache scope; one test that would catch the failure.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.