🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Topic: Data Governance & Classification

Snowflake AdvancedData Governance⭐ Premium

Snowflake Advanced · Interview Prep

Data Governance & Classification

Difficulty: Hard · Commonly asked at Google, Microsoft, Amazon

Interview Question

"How would you implement a comprehensive data governance framework in Snowflake? Walk me through data classification, tagging, access policies, and compliance monitoring."

ℹ️

Companies Asking This: Google (Senior Data Governance Engineer), Microsoft (Principal Data Architect), Amazon (L6 Data Engineer), Meta (Data Platform Engineer)


Governance Framework

Data Governance FrameworkData Classification• Tags• Categories• SensitivityAccess Control• RBAC• Masking• Row SecurityCompliance Monitoring• Audit• Reports• AlertsData Catalog• Metadata• Descriptions• SearchLineage Tracking• Dependencies• Transformations• Impact AnalysisQuality Monitoring• Rules• Metrics• Alerts

Data Classification with Tags

-- 1. Create tags for data classification
CREATE TAG security_pii VARCHAR;
CREATE TAG data_sensitivity VARCHAR;
CREATE TAG data_owner VARCHAR;
CREATE TAG compliance_region VARCHAR;
CREATE TAG retention_period VARCHAR;

-- 2. Apply tags to tables
ALTER TABLE customers SET TAG security_pii = 'PII';
ALTER TABLE customers SET TAG data_sensitivity = 'HIGH';
ALTER TABLE customers SET TAG data_owner = 'CUSTOMER_SUCCESS';
ALTER TABLE customers SET TAG compliance_region = 'GDPR';

-- 3. Apply tags to columns
ALTER TABLE customers MODIFY COLUMN email SET TAG security_pii = 'EMAIL';
ALTER TABLE customers MODIFY COLUMN ssn SET TAG security_pii = 'SSN';
ALTER TABLE customers MODIFY COLUMN phone SET TAG security_pii = 'PHONE';

-- 4. Query tags
SELECT 
    tag_name,
    tag_value,
    object_name,
    object_domain
FROM information_schema.tag_references
WHERE tag_name = 'SECURITY_PII';

-- 5. Create tag-based policies
CREATE OR REPLACE MASKING POLICY pii_tag_mask 
AS (val VARCHAR) RETURNS VARCHAR ->
    CASE
        WHEN CURRENT_ROLE() IN ('DATA_ADMIN', 'PRIVACY_OFFICER') THEN val
        WHEN CURRENT_ROLE() = 'ANALYST' THEN '***MASKED***'
        ELSE '***REDACTED***'
    END;

-- 6. Auto-apply masking based on tags
ALTER TABLE customers MODIFY COLUMN email 
    SET MASKING POLICY pii_tag_mask 
    TAG (security_pii = 'EMAIL');

-- 7. Query all tagged objects
SELECT 
    tag_name,
    tag_value,
    COUNT(*) AS object_count
FROM information_schema.tag_references
GROUP BY 1, 2
ORDER BY 3 DESC;

Data Quality Framework

-- 1. Create data quality rules table
CREATE TABLE data_quality_rules (
    rule_id NUMBER AUTOINCREMENT,
    table_name VARCHAR(100),
    column_name VARCHAR(100),
    rule_type VARCHAR(50),
    rule_expression VARCHAR(2000),
    severity VARCHAR(20),
    owner VARCHAR(100),
    enabled BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP()
);

-- 2. Insert quality rules
INSERT INTO data_quality_rules (table_name, column_name, rule_type, rule_expression, severity, owner)
VALUES 
    ('CUSTOMERS', 'CUSTOMER_ID', 'NOT_NULL', 'CUSTOMER_ID IS NOT NULL', 'CRITICAL', 'DATA_ENGINEERING'),
    ('CUSTOMERS', 'EMAIL', 'FORMAT', 'REGEXP_LIKE(EMAIL, ''^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'')', 'HIGH', 'DATA_ENGINEERING'),
    ('ORDERS', 'AMOUNT', 'RANGE', 'AMOUNT > 0 AND AMOUNT < 1000000', 'HIGH', 'FINANCE'),
    ('ORDERS', 'ORDER_DATE', 'NOT_FUTURE', 'ORDER_DATE <= CURRENT_DATE()', 'CRITICAL', 'DATA_ENGINEERING');

-- 3. Quality check procedure
CREATE OR REPLACE PROCEDURE run_quality_check(table_name VARCHAR)
RETURNS VARIANT
LANGUAGE SQL
AS
$$
DECLARE
    results ARRAY DEFAULT ARRAY_CONSTRUCT();
    rule_record RECORD;
    violation_count NUMBER;
BEGIN
    FOR rule_record IN 
        SELECT rule_id, column_name, rule_type, rule_expression, severity
        FROM data_quality_rules
        WHERE table_name = :table_name AND enabled = TRUE
    DO
        EXECUTE IMMEDIATE 
            'SELECT COUNT(*) FROM ' || :table_name || 
            ' WHERE NOT (' || rule_record.rule_expression || ')'
            INTO violation_count;
        
        results := ARRAY_APPEND(results, OBJECT_CONSTRUCT(
            'rule_id', rule_record.rule_id,
            'column', rule_record.column_name,
            'rule_type', rule_record.rule_type,
            'severity', rule_record.severity,
            'violations', violation_count
        ));
    END FOR;
    
    RETURN OBJECT_CONSTRUCT(
        'table', :table_name,
        'rules_checked', ARRAY_SIZE(:results),
        'results', :results
    );
END;
$$;

-- 4. Schedule quality checks
CREATE OR REPLACE TASK daily_quality_check
    WAREHOUSE = admin_wh
    SCHEDULE = 'USING CRON 0 6 * * * UTC'
AS
    CALL run_quality_check('CUSTOMERS');

Real-World Scenario: Google

Question: "How do you implement data lineage tracking in Snowflake to understand how data flows from source to reporting?"

Solution: Lineage Tracking Pattern

-- 1. Create lineage tracking table
CREATE TABLE data_lineage (
    lineage_id NUMBER AUTOINCREMENT,
    source_database VARCHAR(100),
    source_schema VARCHAR(100),
    source_table VARCHAR(100),
    target_database VARCHAR(100),
    target_schema VARCHAR(100),
    target_table VARCHAR(100),
    transformation_type VARCHAR(50),
    transformation_logic VARCHAR(2000),
    owner VARCHAR(100),
    created_at TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP()
);

-- 2. Populate lineage from ETL procedures
INSERT INTO data_lineage (source_database, source_schema, source_table, 
                          target_database, target_schema, target_table,
                          transformation_type, transformation_logic, owner)
VALUES 
    ('RAW', 'PUBLIC', 'RAW_ORDERS', 'PROD', 'ANALYTICS', 'FACT_ORDERS', 'ETL', 'CLEAN AND AGGREGATE', 'DATA_ENGINEERING'),
    ('RAW', 'PUBLIC', 'RAW_CUSTOMERS', 'PROD', 'ANALYTICS', 'DIM_CUSTOMERS', 'ETL', 'DEDUPLICATE AND VALIDATE', 'DATA_ENGINEERING'),
    ('PROD', 'ANALYTICS', 'FACT_ORDERS', 'PROD', 'REPORTING', 'DAILY_SALES', 'VIEW', 'AGGREGATE BY DATE', 'ANALYTICS');

-- 3. Lineage query function
CREATE OR REPLACE FUNCTION get_upstream_tables(target_table VARCHAR)
RETURNS TABLE (source_table VARCHAR, transformation VARCHAR)
LANGUAGE SQL AS
    $$
    WITH RECURSIVE lineage_chain AS (
        SELECT source_database || '.' || source_schema || '.' || source_table AS source_table,
               transformation_logic AS transformation,
               target_database || '.' || target_schema || '.' || target_table AS target_table
        FROM data_lineage
        WHERE target_database || '.' || target_schema || '.' || target_table = target_table
        
        UNION ALL
        
        SELECT l.source_database || '.' || l.source_schema || '.' || l.source_table,
               l.transformation_logic,
               l.target_database || '.' || l.target_schema || '.' || l.target_table
        FROM data_lineage l
        JOIN lineage_chain lc ON l.target_database || '.' || l.target_schema || '.' || l.target_table = lc.source_table
    )
    SELECT source_table, transformation FROM lineage_chain;
    $$;

-- 4. Query lineage
SELECT * FROM TABLE(get_upstream_tables('PROD.REPORTING.DAILY_SALES'));

From Tag to Enforced Policy

A tag on its own changes nothing. The value only appears when a policy consumes it, and the chain has to be complete before the first classification lands in production: a tag definition, an application step, a policy that reads the tag, and a query against information_schema.tag_references that proves the tag is actually attached where you think it is. Teams that skip the last step end up with a spreadsheet claiming 400 columns are classified while the account shows 120. Run the verification query in the same deployment pipeline that applied the tags and fail the build on any drift.

The order of policy attachment matters too. A masking policy applies to a column and is resolved at query time based on the caller's role, so it works for both direct selects and views built on top. A row access policy evaluates a boolean per row and is combined with any other policy on the table using logical AND, which means two restrictive policies can make a table appear empty rather than throwing an error. Developers frequently read that as a data bug instead of a policy bug, so document which policies are attached to which columns and surface the policy name in your error messages where you can.

Retention Windows and Deletion Requests

Retention is where governance meets cost, and where most interview answers stop short. Snowflake keeps deleted and historical rows for DATA_RETENTION_TIME_IN_DAYS (0 to 90 days on standard tables), and after Time Travel expires a non-transient table still sits in Fail-Safe for seven days of read-only storage that no one can shorten. A GDPR erasure request therefore has three stages: delete or mask the row in the base table, drop the retention window to zero on the tables that held it so Time Travel stops preserving the value, and accept that Fail-Safe copies for the following week may still contain the record for disaster-recovery purposes only.

-- Apply an erasure request and close the Time Travel window
UPDATE customers SET email = '[email protected]', ssn = NULL
WHERE customer_id = :customer_id;

ALTER TABLE customers SET DATA_RETENTION_TIME_IN_DAYS = 0;
ALTER TABLE customers MODIFY COLUMN ssn SET MASKING POLICY pii_tag_mask;

-- Evidence for the audit file
SELECT policy_name, ref_database_name, ref_schema_name, ref_entity_name
FROM snowflake.account_usage.policy_references
WHERE policy_name = 'PII_TAG_MASK'
  AND ref_entity_name = 'CUSTOMERS'
ORDER BY policy_name;

Transient tables skip Fail-Safe entirely, which makes them the right home for staging copies of regulated data, but they also lose the seven-day recovery net. State the trade-off explicitly in the design document rather than discovering it during an incident.

Lineage: Why the Recursive Query Terminates

The lineage function above walks the dependency graph bottom-up: the WHERE clause inside the common table expression pins the first row to the reporting table you asked about, and each iteration joins data_lineage rows whose target matches the sources found so far. That is a standard reverse breadth-first traversal, and it terminates because the graph has no cycles — which is an assumption, not a guarantee. A view defined on itself through a chain of intermediate objects, or a pair of tables that reference each other, produces an infinite recursion that Snowflake catches with its own depth limit rather than with a friendly message.

Two practical refinements separate a demo from something an on-call engineer will trust. Add a depth column and filter on it so the output shows how far upstream each object sits, and cap it at a number your warehouse can finish inside a few seconds. Then decide whether you are recording lineage by hand, as the insert statement above does, or harvesting it automatically from query history; manual rows are curated and readable but drift the moment somebody edits a view, while automatic capture is complete and noisy. Most mature teams keep a hand-maintained catalog for the certified layer and generate everything below it.

Lineage earns its budget at the moment something breaks. When a revenue figure drops 4% overnight, the first question is which upstream feeds landed late, and the second is which dashboards now show wrong numbers. With the recursive query in place both answers come from one call against the reporting table, in seconds, instead of an afternoon of grepping SQL files. That incident response is also the cheapest justification for governance spend you will ever present: it converts an abstract compliance obligation into hours not spent chasing a defect through six teams.

Who Owns the Rules, and How Often They Are Checked

Governance fails quietly when nobody is accountable for the exception queue. The minimum set of owners is small: a data steward per domain who classifies new tables, a platform owner who grants and revokes roles, and one engineering lead who signs off on policy changes. Below is a cadence that has held up in practice.

ControlOwnerFrequencyEvidence produced
New column classificationData stewardOn creationTag reference query result
Privileged role reviewPlatform ownerMonthlyGranted-roles diff report
Masking policy changesEngineering leadPer changePull request and policy DDL
Quality rule thresholdsData stewardQuarterlyViolation counts by severity
Lineage certificationAnalytics leadQuarterlySigned catalog snapshot
Access log samplingSecurityQuarterlySample of ACCESS_HISTORY rows

The evidence column is the point of the table. Auditors do not want a description of the process, they want the artifact the process produced, dated and attributable to a person.


Best Practices

PracticeImplementation
ClassificationUse tags for PII, sensitivity, ownership
Access controlRBAC with tag-based masking
Quality monitoringAutomated rules with alerts
Lineage trackingDocument all transformations
ComplianceRegular audits and reports
DocumentationMaintain data catalog

⚠️

Governance Anti-Patterns:

  1. No classification — Can't protect what you don't know
  2. Over-privileged roles — Use least privilege principle
  3. No quality checks — Bad data corrupts analytics
  4. Missing lineage — Can't trace data issues
  5. No audit trail — Compliance requires audit logs

Key Takeaways

  • A classification tag only does something once a masking or row access policy reads it, so the deployment pipeline must verify tag coverage against information_schema before it reports success.
  • Erasure requests need three steps: modify the base row, drop the retention window so Time Travel stops preserving it, and document that Fail-Safe holds a read-only copy for seven more days.
  • Recursive lineage queries terminate only because the dependency graph is assumed acyclic, so add a depth column and decide between curated manual rows and captured query history.
  • Every governance control needs a named owner, a fixed cadence, and a dated artifact — auditors review the evidence the process produced, never a description of the process.
🔒

Premium Content

Topic: Data Governance & Classification

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
💼Interview Prep
📜Certificates
🤝Community Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-15

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Advertisement