← Freddie Mac Interview Insights

Freddie Mac·Data Scientist·Online Assessment (OA)·Senior

Senior
May 2026

Summary

Took a Freddie Mac data scientist assessment that was basically a full warehouse audit exercise, schema and all. Eight parts covering everything from deduplication logic to DDL constraints to self-joins. Dense stuff, felt like a take-home that someone decided to give you during a live session.

Questions Asked (8)

Q1

Given a retail analytics schema with messy data, outline a concrete ordered plan to clean the warehouse: deduplicate customers by email with justified tie-breakers, identify and remove ingestion-duplicate orders using a natural key and time/amount tolerance, standardize data types and time zones, validate referential integrity, and detect impossible values like negative quantities. Provide at least two SQL or Python snippets.

Data ModelingRoot Cause AnalysisTechnical Trade-offs
Author's notes

This was the part that took the longest.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by profiling the data to quantify issues, then execute a prioritized cleaning plan: deduplicate customers, remove duplicate orders, standardize types and time zones, validate referential integrity, and flag impossible values. For each step, justify tie-breakers and tolerances with business logic, and provide SQL/Python code to demonstrate implementation.

Pro tip: Always create a backup or snapshot before cleaning, and log every transformation with row counts to enable auditing and rollback. This shows production maturity and is crucial in regulated environments like Freddie Mac.

1. Profile and Assess Data Quality

Run exploratory queries to measure duplicates, nulls, type mismatches, and referential gaps. This informs the cleaning strategy and prioritization.

2. Deduplicate Customers by Email

Use window functions to rank records per email, applying tie-breakers like most recent update or most complete record. Justify tie-breakers based on business rules.

3. Remove Ingestion-Duplicate Orders

Identify duplicates using a natural key (e.g., order_id) and time/amount tolerance. Keep the earliest or most reliable record, and document the tolerance rationale.

4. Standardize Data Types and Time Zones

Convert columns to correct types (e.g., dates, numerics) and normalize timestamps to UTC. Use SQL CAST or Python pandas functions.

5. Validate Referential Integrity and Detect Impossible Values

Check foreign key relationships and flag negative quantities or other impossible values. Provide queries to identify and optionally correct them.

Key Points to Mention

  • Use of window functions (ROW_NUMBER, RANK) for deduplication with justified tie-breakers.
  • Natural key selection and tolerance thresholds for order deduplication, with business justification.
  • Time zone normalization to UTC and data type casting to avoid silent errors.
  • Referential integrity checks using LEFT JOIN or NOT EXISTS to find orphan records.
  • Detection of impossible values (e.g., negative quantities) and handling strategy (flag, correct, or remove).
  • Importance of logging, backups, and iterative validation to ensure data quality.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

You need to onboard a CSV file with columns for order ID, timestamp, customer email, SKU, quantity, and price in cents into the existing Orders and OrderItems tables. What fields would you include in a formal data mapping specification, and how would you map each CSV column to its target with all required transformations?

Data ModelingSystem DesignTechnical Trade-offs
Author's notes

I liked this one more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by outlining the structure of a formal data mapping specification, including source-to-target mappings, data types, transformations, and validation rules. Then walk through each CSV column, explaining how it maps to the Orders or OrderItems tables, and describe any necessary transformations such as splitting, type conversion, or key generation. Emphasize data quality checks and referential integrity to ensure a robust onboarding process.

Pro tip: Highlight the importance of handling edge cases like missing values, duplicate order IDs, and currency conversion (if applicable), and mention that you would document assumptions and get stakeholder sign-off to avoid downstream issues.

1. Define the mapping specification structure

Outline the sections of the spec: source fields, target tables/columns, data types, transformations, validation rules, and error handling. This sets a clear framework for the mapping.

2. Map CSV columns to target tables

For each CSV column, identify the corresponding target column in Orders or OrderItems. Explain how order-level fields (order ID, timestamp, email) go to Orders, and line-item fields (SKU, quantity, price) go to OrderItems, with appropriate foreign key relationships.

3. Specify transformations

Detail any required transformations: converting timestamp to a standard format, splitting full name into first/last (if applicable), converting price from cents to dollars (if the target expects dollars), and generating surrogate keys if needed.

4. Define validation and quality checks

List validation rules such as non-null constraints, data type checks, referential integrity (e.g., order ID exists in Orders before inserting into OrderItems), and business rules (e.g., quantity > 0).

5. Document error handling and edge cases

Describe how to handle errors: reject invalid rows, log issues, or apply default values. Mention handling duplicates, missing values, and potential currency conversion if prices are in cents but target expects another unit.

Key Points to Mention

  • Source-to-target mapping with explicit column names and data types
  • Transformation logic: timestamp formatting, price conversion (cents to dollars), and key generation
  • Referential integrity between Orders and OrderItems (foreign key relationship)
  • Data validation rules: non-null, unique, range checks, and format checks
  • Handling of edge cases: duplicates, missing values, and invalid data
  • Documentation of assumptions and stakeholder sign-off for clarity

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Write three queries: one that flags duplicate customers by email and returns only the row to keep with a reason code for dropped rows, one that clusters likely duplicate orders for the same customer where the order date is within 30 seconds and total amount matches to two decimal places, and one that deduplicates products by SKU and picks a survivor deterministically.

Data ModelingAlgorithms & Data StructuresRoot Cause Analysis
Author's notes

The order clustering one was rough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the business rules for each deduplication scenario, such as which record to keep and how to handle ties. Then write SQL queries using window functions (ROW_NUMBER, RANK) to identify duplicates and select survivors deterministically. For the order clustering, use a self-join or window function with time and amount conditions to group likely duplicates.

Pro tip: Always consider data quality and edge cases: for example, what if multiple rows tie on the deterministic criteria? Use additional tie-breakers like primary key to ensure a single survivor. Also, mention that these queries should be tested on sample data and validated with business stakeholders.

1. Clarify requirements and define deduplication logic

Ask clarifying questions about what constitutes a duplicate, which record to keep (e.g., most recent, highest ID), and how to handle ties. Define reason codes for dropped rows.

2. Write query for duplicate customers by email

Use ROW_NUMBER() partitioned by email, ordered by a deterministic criterion (e.g., customer_id). Select rows where row_number = 1 as 'keep', and others as 'drop' with a reason code like 'duplicate_email'.

3. Write query for clustering likely duplicate orders

Use a self-join or window function to find orders for the same customer where order dates are within 30 seconds and total amounts match to two decimal places. Assign a cluster ID or flag duplicates.

4. Write query for deduplicating products by SKU

Use ROW_NUMBER() partitioned by SKU, ordered by a deterministic criterion (e.g., product_id or last_updated). Select the survivor (row_number = 1) and optionally flag others as duplicates.

5. Review and optimize queries

Check for performance considerations (indexes on email, SKU, customer_id, order_date) and ensure queries are deterministic and handle ties. Discuss potential edge cases and validation.

Key Points to Mention

  • Use of window functions like ROW_NUMBER(), RANK(), and DENSE_RANK() for deduplication.
  • Deterministic ordering: specify a clear tie-breaker (e.g., primary key, timestamp) to ensure consistent results.
  • Reason codes: include a column that explains why a row is dropped (e.g., 'duplicate_email', 'duplicate_sku').
  • Time-based clustering: use self-join with conditions on time difference (e.g., ABS(datediff(second, o1.order_date, o2.order_date)) <= 30) and amount rounding.
  • Data quality: consider NULLs, case sensitivity for emails, and rounding issues for amounts.
  • Performance: mention indexing and partitioning strategies to handle large datasets.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Explain the practical differences between DDL and DML in the context of this warehouse schema, including transactional and locking implications. Provide one DDL statement you would actually run here to enforce integrity and one DML statement demonstrating data manipulation.

Technical Trade-offsData Modeling
Author's notes

Pretty conceptual compared to the rest of the questions.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining DDL and DML in the context of a data warehouse, emphasizing how DDL shapes the schema and enforces integrity while DML manipulates data. Then discuss transactional and locking implications, contrasting the heavy locks and auto-commit behavior of DDL with the finer-grained, transaction-controlled locks of DML. Finally, provide concrete examples: a DDL statement like adding a foreign key constraint and a DML statement like an INSERT or UPDATE, explaining their practical impact on the warehouse.

Pro tip: Mention that in many warehouses, DDL operations like adding constraints can be expensive and may require downtime, so it's common to enforce integrity during ETL rather than via database constraints. Also, highlight that DML operations should be batched to minimize lock contention and transaction log growth.

1. Define DDL and DML in warehouse context

Briefly explain that DDL defines and modifies the structure of database objects (tables, constraints, indexes) while DML manages the data within those objects (insert, update, delete). Relate this to the warehouse schema, noting that DDL sets up the star schema and DML populates it.

2. Discuss transactional implications

Explain that DDL statements are often auto-committed and cannot be rolled back in many databases, whereas DML statements are transactional and can be rolled back. In a warehouse, this means schema changes are permanent and require careful planning, while data loads can be managed in transactions.

3. Explain locking implications

Describe how DDL typically acquires exclusive locks on objects, blocking concurrent DML and queries, while DML acquires row-level or page-level locks, allowing more concurrency. In a warehouse, this affects ETL jobs and query performance during schema changes.

4. Provide a DDL example for integrity

Give a specific DDL statement, such as ALTER TABLE fact_loan ADD CONSTRAINT fk_borrower FOREIGN KEY (borrower_id) REFERENCES dim_borrower(borrower_id);, and explain how it enforces referential integrity in the warehouse.

5. Provide a DML example for data manipulation

Give a specific DML statement, such as INSERT INTO fact_loan (loan_id, borrower_id, amount) VALUES (123, 456, 100000);, and explain how it adds data to the warehouse, noting transaction and locking considerations.

Key Points to Mention

  • DDL is auto-committed and cannot be rolled back in many databases, while DML is transactional and supports rollback.
  • DDL typically takes exclusive locks, blocking concurrent operations, whereas DML uses finer-grained locks, allowing more concurrency.
  • In data warehouses, DDL changes are often avoided during peak ETL times due to locking and performance impact.
  • Enforcing integrity via DDL constraints (e.g., foreign keys) can impact load performance; some warehouses enforce integrity in ETL instead.
  • DML operations should be batched and committed frequently to avoid long-running transactions and lock escalation.
  • Provide concrete examples relevant to the warehouse schema, such as adding a foreign key on a fact table and inserting a new fact record.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

Using the Customers table, write a self-join query that returns each customer's ID, email, and their referrer's email if one exists, making sure customers with no referrer still appear exactly once.

Data ModelingAlgorithms & Data Structures
Author's notes

Standard left join on referrer_id to customer_id.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the table schema and the referrer relationship, then write a LEFT JOIN from the Customers table to itself on the referrer ID. Ensure the join condition is correct and that customers without a referrer still appear once with NULL for the referrer's email.

Pro tip: Mention that you would verify the query handles edge cases like self-referrals or circular references, and that you'd test with sample data to confirm no duplicates or missing rows.

1. Understand the schema and relationship

Identify the primary key (customer ID) and the foreign key that points to the referrer (e.g., referrer_id). Confirm that the referrer is also a customer in the same table.

2. Choose the correct join type

Use a LEFT JOIN to ensure all customers appear, even those without a referrer. The join condition should match the customer's referrer_id to the referrer's customer ID.

3. Write the self-join query

Select the customer's ID and email, and the referrer's email from the joined table. Use table aliases (e.g., c and r) to distinguish the two instances of the Customers table.

4. Handle NULLs and verify uniqueness

Ensure that customers with no referrer return NULL for the referrer's email. Check that the query does not produce duplicate rows for any customer.

5. Test and validate

Run the query on sample data to confirm it returns the expected results, including edge cases like customers without referrers and potential self-referrals.

Key Points to Mention

  • Use of LEFT JOIN to include all customers
  • Table aliasing for self-join clarity
  • Correct join condition: c.referrer_id = r.customer_id
  • Handling NULL values for referrer email
  • Ensuring each customer appears exactly once
  • Potential edge cases: self-referral, circular references, missing referrer

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q6

Show how you would insert or update a product by SKU so that duplicate SKUs collapse into a single correct row without violating constraints. How would you handle concurrent writes?

System DesignTechnical Trade-offsData Modeling
Author's notes

I went with INSERT ...

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the data model and constraints (e.g., unique SKU, primary key) and the desired upsert semantics. Then propose a concrete SQL implementation using INSERT ... ON CONFLICT (or MERGE) that deduplicates within the batch and handles conflicts. Finally, address concurrency with transaction isolation levels, locking strategies, and idempotency to ensure correctness under concurrent writes.

Pro tip: Mention that you would test the upsert logic with concurrent transactions using a tool like pgbench or a simple script, and that you'd monitor for deadlocks and retry with exponential backoff. This shows you think about production reliability, not just the happy path.

1. Clarify requirements and constraints

Ask about the database system (e.g., PostgreSQL, SQL Server), the table schema, unique constraints on SKU, and whether the operation should be insert-only, update-only, or upsert. Confirm the definition of 'duplicate SKUs' (e.g., within the same batch or across concurrent transactions).

2. Design the upsert statement

Write a single SQL statement that inserts new SKUs and updates existing ones, using the database's native upsert syntax (e.g., INSERT ... ON CONFLICT (sku) DO UPDATE). Ensure that if multiple rows with the same SKU are in the input, they are deduplicated first (e.g., using DISTINCT ON or a subquery that picks the latest).

3. Handle concurrency and isolation

Explain how the upsert behaves under concurrent writes: use row-level locking (e.g., ON CONFLICT DO UPDATE takes a lock on the conflicting row) and choose an appropriate isolation level (e.g., READ COMMITTED). Discuss potential race conditions and how to avoid lost updates.

4. Ensure idempotency and error handling

Make the operation idempotent so that retries are safe. Describe how to handle unique violation errors and deadlocks with retry logic. Mention the importance of using transactions to group multiple upserts if needed.

5. Validate and test

Propose testing the solution with concurrent sessions to verify correctness and performance. Suggest monitoring for lock contention and tuning batch sizes if necessary.

Key Points to Mention

  • Use of database-native upsert (INSERT ... ON CONFLICT or MERGE) to atomically insert or update.
  • Deduplication of input rows before upsert to collapse duplicate SKUs into one row.
  • Concurrency control: row-level locking, transaction isolation levels, and handling of unique constraint violations.
  • Idempotency and retry logic to handle transient errors like deadlocks.
  • Performance considerations: batch size, indexing on SKU, and avoiding full table scans.
  • Testing strategy: simulate concurrent writes to ensure correctness and no lost updates.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q7

Define appropriate primary key, foreign key, and unique constraints for all four tables given the sample data. Justify any composite keys and discuss trade-offs between surrogate and natural keys for Customers and Orders.

Data ModelingTechnical Trade-offs
Author's notes

OrderItems is the interesting one since neither order_id nor line_no alone is unique, you need the composite.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by examining the sample data to identify candidate keys and relationships, then propose primary keys (natural or surrogate) for each table, foreign keys to enforce referential integrity, and unique constraints on alternate keys. Justify composite keys where a single column is insufficient, and discuss trade-offs between surrogate and natural keys for Customers and Orders, considering performance, stability, and business meaning.

Pro tip: Emphasize that surrogate keys are often preferred in data warehousing for stability and performance, but natural keys can be valuable for integration and business logic; align your recommendation with Freddie Mac's data governance and scalability needs.

1. Analyze sample data and identify candidate keys

Examine each table's columns and data to determine which columns or combinations uniquely identify rows. Note any natural keys (e.g., email, order number) and potential composite keys.

2. Define primary keys for each table

Choose a primary key for each table, either natural or surrogate. For composite keys, explain why a single column is insufficient (e.g., order line items).

3. Define foreign keys and unique constraints

Identify relationships between tables and specify foreign keys to enforce referential integrity. Add unique constraints on alternate keys (e.g., email) to prevent duplicates.

4. Justify composite keys and discuss surrogate vs. natural trade-offs

Explain the rationale for any composite keys, and compare surrogate vs. natural keys for Customers and Orders, covering pros and cons like stability, performance, and business meaning.

5. Summarize and align with business context

Conclude with a recommendation that balances technical best practices with Freddie Mac's data needs, such as scalability, integration, and governance.

Key Points to Mention

  • Surrogate keys (e.g., auto-increment integers) provide stability and performance benefits, especially for joins and indexing.
  • Natural keys (e.g., email, order number) carry business meaning and simplify data integration but can change over time.
  • Composite keys are necessary when no single column uniquely identifies a row, such as in order line items (OrderID + ProductID).
  • Unique constraints enforce alternate keys and prevent data duplication, supporting data quality.
  • Foreign keys maintain referential integrity and define relationships between tables.
  • Trade-offs include storage overhead, join complexity, and impact on ETL processes; consider Freddie Mac's data volume and regulatory requirements.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q8

Rate your SQL proficiency from 1 to 10 and justify it with two concrete examples from the tasks above, such as a window-function-based deduplication and a concurrency-safe upsert. Include how you would test and optimize those queries.

Technical Trade-offsData Modeling
Author's notes

I said 7.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Give a calibrated rating (e.g., 8/10) that reflects strong proficiency without claiming perfection, then justify it with two concrete examples: one using window functions for deduplication and one implementing a concurrency-safe upsert. For each example, briefly describe the query logic, how you tested it (e.g., unit tests, edge cases, concurrency simulations), and how you optimized it (e.g., indexing, partitioning, query plan analysis).

Pro tip: Avoid claiming a 10; instead, show self-awareness by mentioning areas for growth (e.g., advanced query tuning for distributed systems) and how you stay current. This demonstrates humility and a learning mindset, which is highly valued in data science roles.

1. State your rating and rationale

Give a specific number (e.g., 8/10) and briefly explain why—highlighting strengths in complex queries, optimization, and testing, while acknowledging any gaps.

2. Example 1: Window-function-based deduplication

Describe a scenario where you used ROW_NUMBER() or RANK() to deduplicate records, explain the query structure, and mention how you tested it with duplicate data and optimized it using indexes or partitioning.

3. Example 2: Concurrency-safe upsert

Explain how you implemented an upsert (e.g., using INSERT ... ON CONFLICT or MERGE) that handles concurrent writes safely, and discuss testing with concurrent transactions and optimizing with proper locking or isolation levels.

4. Testing methodology

Summarize your approach to testing SQL queries: unit tests for logic, edge cases (nulls, duplicates), and concurrency tests using tools like pgbench or custom scripts.

5. Optimization techniques

Highlight specific optimizations: analyzing query plans, adding indexes, partitioning large tables, and rewriting subqueries as joins or CTEs for performance.

Key Points to Mention

  • Use of window functions (ROW_NUMBER, RANK) for deduplication with PARTITION BY and ORDER BY
  • Concurrency-safe upsert patterns (e.g., INSERT ... ON CONFLICT, MERGE) and handling race conditions
  • Testing strategies: unit tests, edge cases, and concurrency simulations
  • Optimization techniques: indexing, query plan analysis, partitioning, and avoiding SELECT *
  • Awareness of database-specific features (e.g., PostgreSQL vs. SQL Server) and trade-offs
  • Self-awareness of skill level and areas for improvement, with a growth mindset

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.