KatInterview

Build a PII Detection System for Large-Scale Databases

Machine LearningModel answer
HardModel answerMachine Learningml-system-designprivacydata-pipeline

Last updated

Design an ML-powered pipeline to automatically discover and classify personal information across billions of records in structured tables and unstructured text.

You're building a system for a large company that stores petabytes of user data across multiple databases, data lakes, and logging systems. The data includes structured database tables, semi-structured JSON logs, and unstructured text documents.

Your task is to design an automated system that:

  1. Discovers records containing personally identifiable information (PII) and sensitive data across all sources
  2. Classifies the type of sensitive information found (email addresses, phone numbers, government IDs, health records, financial data, etc.)
  3. Assesses risk by identifying not just obvious identifiers but also subtle patterns—like combinations of fields that together can identify individuals
  4. Scales to handle billions of existing records plus millions of new records daily

The system should use a combination of approaches: rule-based detection, machine learning models, and large language models where appropriate.

Your design should cover:

  • What are the functional and non-functional requirements? What trade-offs matter most?
  • What is the overall architecture? Draw out the main components and data flow.
  • How does the detection work? Describe your multi-tiered approach and when you'd use rules vs. ML vs. LLMs.
  • How do you handle scale—both the initial scan of existing data and continuous monitoring of new data?
  • How do you measure success? What metrics matter and how do you improve the system over time?
  • What are the privacy and security risks of the detection system itself?

Assume you're dealing with roughly 10 billion existing records (20-50 TB) and 100 million new records per day across heterogeneous schemas.

Hints

Hint 1

For structured data, think about profiling entire columns rather than scanning individual rows—most tables have millions of rows but only dozens of columns

Hint 2

Build a cascade: cheap methods filter the bulk of data, expensive models only run on ambiguous cases where simpler approaches aren't confident

Hint 3

Consider that '45-year-old female in ZIP 02138' might be identifying even without a name—you need table-level analysis, not just field-level pattern matching