Quick revision
The short answer
Define each key metric once, in a governed semantic or metrics layer such as dbt models or a BI semantic layer, with a named owner, tests and documentation, and make published numbers come only from those certified models. Move analytical and pivot workloads off the OLTP databases into a warehouse fed by CDC, with services exposing stable data contracts, keep self-service on certified datasets, retire duplicate tools, and fund a small central team measured by certified metrics, retired reports and fewer disagreement incidents.
What to remember
In this answer, we traced disagreeing reports to many unowned definitions, fixed definitions once in a metrics layer with owners, tests and docs, moved analytical workloads to a warehouse fed by CDC with data contracts, chose tools by skills and cost while retiring duplicates, kept self-service while requiring published numbers to come from certified models, and funded a small central team measured by certified metrics, retired reports and disagreement incidents.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Define each key metric once, in a governed semantic or metrics layer such as dbt models or a BI semantic layer, with a named owner, tests and documentation, and make published numbers come only from those certified models. Move analytical and pivot workloads off the OLTP databases into a warehouse fed by CDC, with services exposing stable data contracts, keep self-service on certified datasets, retire duplicate tools, and fund a small central team measured by certified metrics, retired reports and fewer disagreement incidents.
Why this question is asked
When two reports rarely agree, the real cost is not the wrong number but the meetings: every planning session starts with an argument about whose revenue figure is right, and decisions wait. Thousands of hand-written queries across services, cron jobs and spreadsheets mean that every metric has been redefined many times, slightly differently. Interviewers ask this at principal level because it is an organisational problem with a technical backbone, and the answer must cover ownership, platform and the change process. In this answer, we will see why the numbers disagree, how a governed metrics layer fixes definitions, where reporting workloads should run, how to keep self-service without chaos, and how to fund and measure the program.
1Why Two Reports Disagree
Take revenue. One query sums order totals by order date in UTC, another subtracts refunds, a third uses payment capture date in the local zone and excludes test accounts. Each is a defensible definition, written by someone solving a real problem, and each lives in its own place. Nobody is wrong; nobody is responsible.
So the root cause is not bad SQL but the absence of an owned, shared definition. Any fix that only rewrites queries will decay, because the next urgent request will produce another hand-written version. The governance must make the shared definition the easiest path.
2Define Metrics Once, With Owners
The core move is a semantic or metrics layer: a place where a metric such as net revenue is defined once, with its filters, time zone, currency rules and grain, and from which every dashboard and export reads. dbt models with tests and documentation, or the semantic layer of a BI tool, are common choices. Each metric has a business owner who decides the definition, such as the finance controller for revenue, and a technical owner who maintains it.
Definitions are code, so they get version control, review, tests and a changelog. A test might assert that daily net revenue equals the finance ledger within 0.1 percent, or that no order is counted twice. When the definition changes, everyone's number changes at the same moment, with a note explaining why.
- Dashboards, exports, spreadsheetsread only certified datasets for published numbers
- Metrics or semantic layerone definition per metric, owner, tests, docs
- Warehouse modelscleaned, joined, history kept
- CDC and event ingestionDebezium, events, data contracts
- Product services and OLTP databasesserve customers, not reports
5 layers, from the top down. Step through them one at a time.
3Where Reporting Runs
Pivot and analytical queries on production OLTP databases compete with customers for resources and couple every report to internal table layouts. We move them to a warehouse or lakehouse fed by change data capture or published events. Product teams then commit to data contracts: a documented, versioned shape of the data they emit, so that renaming a column in a service is a contract change rather than a silent break in finance's report.
Build versus buy follows from skills and cost rather than fashion. A team strong in SQL and Git suits dbt on a managed warehouse; a team of analysts may get more from a BI tool with a strong semantic layer. Either way, part of the program is retiring duplicate BI tools, because five tools mean five places where metrics get redefined and five licences to pay.
4Self-Service Without Chaos
Banning ad hoc SQL would fail and should fail, because exploration is how analysts find things. The rule I use is simple: anyone may query certified datasets and write ad hoc analysis, but a number that is published, in a board deck, a KPI dashboard or a regulatory report, must come from a certified model. Certification is a visible badge in the BI tool and the catalogue, so people can see which numbers are official.
When an ad hoc query proves useful and becomes a recurring report, it graduates: the central team or the domain team turns it into a certified model with an owner and tests, and the hand-written version is retired.
- Ad hoc query on certified datasetsanyone may explore
- Used for a published number?Yesmust come from a certified modelNostays ad hoc
- Define or reuse the metric in the semantic layerowner, tests, docs
- Review by the metric owner
- Publish and retire the old query
5 steps in order. Play them, or step through them one at a time.
5Funding, Measuring and Running the Change
This needs a small, funded central data team, often four to eight people, that owns the platform and the semantic layer, while domain teams own their own models with the central team's standards. Without dedicated people, governance becomes a document nobody follows.
Progress is measured with numbers leadership can follow: how many of the top metrics are certified, starting with the 20 that appear in executive reviews; how many hand-written reports and cron jobs are retired each quarter; and how many disagreement incidents are raised, ideally logged when someone finds two numbers that do not match. Starting with the most argued-about metrics, usually revenue and active customers, delivers visible wins in the first quarter and builds the support to continue.
6Follow-up questions
How would you handle a team that refuses to move off its own report database?
First find out why. Often their database serves a real need the warehouse does not yet meet, such as fresher data or a specific join, and that is a gap to fix rather than a fight to win. Then offer a migration they can live with: we rebuild their key reports on certified models, run both side by side and show where the numbers differ and why. Their numbers may stay for internal use, but published numbers must come from certified models, a rule set by leadership rather than by the data team. If the old database keeps costing operations time, put that cost on their budget so the decision is visible.
Who should own a metric definition, engineering or the business?
The business owns the meaning, because what counts as revenue is a finance decision. Engineering or the data team owns the implementation, tests and reliability. Both names are written next to the metric in the catalogue.
How do you avoid the semantic layer becoming a bottleneck?
Let domain teams contribute models through the same review process, with the central team providing templates, tests and automation, so the central team reviews standards rather than writing every model.
7Conclusion
In this answer, we traced disagreeing reports to many unowned definitions, fixed definitions once in a metrics layer with owners, tests and docs, moved analytical workloads to a warehouse fed by CDC with data contracts, chose tools by skills and cost while retiring duplicates, kept self-service while requiring published numbers to come from certified models, and funded a small central team measured by certified metrics, retired reports and disagreement incidents.
Open with
The numbers disagree because each metric has been defined many times by different people, and nobody owns the definition. So my first move is a governed metrics layer, for example dbt models or a BI semantic layer, where each key metric such as net revenue is defined once with its filters, time zone and currency rules, a business owner who decides the meaning, a technical owner, tests against the finance ledger and documentation.
Then, if they want more
Published numbers, meaning dashboards, board decks and regulatory reports, must come from those certified models. Second, I would move analytical and pivot workloads off the OLTP databases into a warehouse fed by change data capture, and ask product teams for data contracts so schema changes do not silently break reports.
Third, build versus buy should follow the team's skills and cost, and part of the work is retiring duplicate BI tools. I would keep self-service: anyone can explore certified datasets, and useful ad hoc queries graduate into certified models.
To make it real, I would fund a small central data team to own the platform and standards, with domain teams owning their own models. I would start with the most disputed metrics, revenue and active customers, and report progress quarterly as certified metrics, reports and cron jobs retired, and disagreement incidents raised.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, The SQL Language
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your organization has thousands of hand-written report and pivot queries spread across...": https://scrivio-interview-library.netlify.app/databases/sql-coding-problems/f972316580/