KatInterview

Designing a Scalable Event Data Analytics Warehouse

SQL & DataModel answer
MediumModel answerSQL & Datadata-warehousingschema-designsql

Last updated

Architect an end-to-end data warehouse for high-throughput event logs, detailing schema design, idempotent deduplication, metric modeling, and performance optimization.

You are tasked with designing an enterprise analytics data warehouse and ingestion framework to analyze user retention, ARPU (Average Revenue Per User), and regional product usage at a scale of approximately 50 million daily events. The system runs on a modern cloud data platform such as Snowflake or BigQuery.

Address the following four technical dimensions:

1. Data Modeling & Schema Strategy

Propose a multi-tier data architecture containing raw landing, core facts/dimensions, and analytical marts.

  • Define explicit DDL for core tables (e.g., event facts, financial orders, user dimensions, regional dimensions).
  • Specify table partitioning, clustering/sorting strategies, and key definitions.
  • Detail your approach to Slowly Changing Dimensions (SCD Type 2) for tracking dynamic user attributes (e.g., user region, app version). Explain how event facts are linked to historical state.

2. Idempotency, Late-Arriving Data & Deduplication

Events can arrive out of order, up to 14 days late, and may contain duplicates with identical natural keys (user_id, event_ts, event_type).

  • Define your deduplication key logic and data merging strategy.
  • Detail an ingestion procedure that guarantees idempotent processing under retries.
  • Explain how to handle late-arriving records without distorting cohort retention figures.
  • Outline a historical backfill plan for schema updates or logic adjustments that minimizes resource consumption and query cost.

3. Metric Marts & Data Quality Control

Design the schema and logic for derived reporting tables (specifically, weekly cohort retention and cumulative ARPU).

  • Provide the SQL logic required to build these cohort metrics, explaining windowing mechanics and date bucketing.
  • Define automated data quality and integrity tests to validate cohort stability and metric boundaries over time.

4. Performance Tuning & Cost Optimization

  • Calculate baseline data volume estimates for raw and compressed storage over a 1-year window.
  • Justify your choice of partition granularity and clustering keys based on query patterns (e.g., 8-week top regional usage, rolling DAU/WAU/MAU).
  • Detail cost reduction strategies using partition pruning, result caching, and approximate aggregation techniques (e.g., HyperLogLog).

Hints

Hint 1

Consider how point-in-time joins between fact tables and dynamic dimension tables (SCD Type 2) prevent backdating bias when processing late-arriving events.

Hint 2

When designing incremental metric builds, recomputing entire affected date buckets is significantly more robust against out-of-order data than trying to maintain running counters.

Hint 3

Ensure cohort retention calculations handle non-active weeks gracefully and clearly distinguish between ARPU (total cohort size denominator) and ARPPU (paying users only).