Analytics Platform for Page Traffic and User Conversion
System DesignModel answerLast updated
Build a metrics pipeline that tracks popular pages and calculates signup conversion rates with clear event semantics and late-arrival handling.
You're building an analytics platform for a content website that needs to answer two key questions:
- Which pages attract the most traffic?
- What percentage of visitors convert to paid subscribers?
Design the system architecture and define the metric semantics to support these queries reliably.
Requirements
Traffic Rankings
Your system must identify the top pages by activity over arbitrary time ranges. Consider what constitutes a distinct "page" and a countable "visit."
Conversion Metrics
Calculate the rate at which users move from initial engagement to paid subscription. Define which users belong in your measurement cohort and how you attribute subscriptions to prior activity.
Key Design Questions
- Event identity: How do you distinguish unique pages when URLs contain tracking tokens, language codes, or session IDs?
- Visitor counting: Should metrics reflect total hits, unique sessions, or distinct users?
- Conversion attribution: When a user subscribes three days after their first visit, which cohort owns that conversion?
- Data integrity: How do you handle bot traffic, duplicate events, network retries, and events that arrive hours late?
- Query flexibility: Users want rankings for "last 7 days" or "this month"—how does your aggregation strategy support this?
Deliverables
Describe your event schema, storage architecture, aggregation logic, and how analysts would query and interpret results. Address accuracy versus performance trade-offs and common misinterpretation risks.
Hints
Hint 1
Start by defining canonical event types with timestamps, user identifiers, and context. Separate raw event ingestion from computed metrics.
Hint 2
For URL rankings, normalize away irrelevant parameters early. Precompute counts at multiple granularities (hourly, daily) to serve queries efficiently.
Hint 3
Conversion requires joining two event types across time. Use windowed lookups or materialized user timelines, and decide whether late conversions update past cohorts or only future reports.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This problem tests your ability to translate vague business questions into precise technical definitions, then build a scalable pipeline that maintains those definitions under real-world data conditions.
1. Event Schema and Collection
Define two core event types:
PageView Event:
timestamp: event time (millisecond precision)user_id: persistent identifier (cookie or authenticated ID)session_id: groups related page viewsraw_url: full URL as receivedcanonical_url: normalized form (strip utm_*, sessionid, etc.)user_agent: for bot detectionclient_ip: additional abuse signal
Subscription Event:
timestamp: when subscription completeduser_id: same identifier space as page viewssubscription_id: deduplication keyplan_type: free-trial vs. paid distinction
Ingestion layer validates schemas, assigns processing timestamps, and writes to durable log (Kafka, Kinesis).
2. URL Normalization and Ranking
Normalization rules:
- Remove tracking parameters (
utm_source,fbclid) - Preserve content parameters (
article_id,page) - Lowercase hostnames, normalize trailing slashes
- Hash long URLs for storage efficiency
Aggregation strategy:
Use Lambda architecture:
Batch layer: Daily jobs scan all events, emit counts per canonical URL. Store in columnar format (Parquet) partitioned by date.
Speed layer: Streaming aggregator (Flink, Spark Streaming) maintains rolling windows in state (last hour, last 24h). Emit incremental updates to fast query store (Redis, DynamoDB).
Counting semantics:
Offer multiple metrics:
- Total views: raw event count
- Unique visitors:
COUNT(DISTINCT user_id)per URL per window - Unique sessions:
COUNT(DISTINCT session_id)
Top-K queries combine batch and speed layers: fetch top 1000 from batch store, merge with streaming updates, re-sort.
Complexity: Single-pass aggregation is O(n) in event count, O(k) space for top-k heap. With 1B events/day and k=1000, this is tractable. For exact distinct counts use HyperLogLog (1-2% error) to stay within memory.
3. Conversion Rate Calculation
Metric definition:
conversion_rate = subscribers / eligible_visitors
Eligible visitor: User who viewed at least one page in the measurement window AND had no active subscription at time of first view.
Attribution window: Count a subscription if it occurs within 30 days of first page view in the cohort period.
Implementation:
Step 1 - Cohort identification: For each day D, identify users with first-ever page view on D (new visitors). Exclude users with subscriptions before D.
Step 2 - Conversion tracking: For each cohort, monitor subscription events over next 30 days. Use LEFT JOIN between cohort table and subscription events filtered by user_id and timestamp range.
Step 3 - Incremental updates: Conversion rates for recent cohorts are provisional. Day-7 cohort's rate changes as subscriptions trickle in through day 37. Store time-series of rates: (cohort_date, as_of_date, rate).
Late arrivals:
Events may arrive out of order due to client buffering or network delays. Two strategies:
- Watermarks: After T hours, consider window closed and don't recompute (fast, slightly inaccurate)
- Versioned aggregates: Reprocess last N days on each batch run, emit corrected metrics (slower, accurate)
Hybrid: use watermarks for real-time dashboard, daily batch job corrects historical metrics.
4. Data Quality and Common Pitfalls
Bot filtering: Match user_agent against known bot patterns, rate-limit by IP, exclude user_ids with inhuman activity (100+ views/minute).
Deduplication:
- Page views: same user + URL + timestamp within 5s = duplicate
- Subscriptions: use subscription_id as idempotency key
Attribution errors to avoid:
- Counting trial signups as conversions (define "paid conversion" explicitly)
- Including existing subscribers in denominator (they can't convert again)
- Using page view date instead of cohort entry date (double-counts users with multi-day journeys)
Transparency in reporting: Show absolute numbers alongside rates:
- "7.2% conversion (3,241 subscribers / 45,012 new visitors)"
- "Provisional - cohort still in attribution window"
5. System Architecture
Events → Kafka →
├─ Streaming (Flink) → Redis (recent windows)
└─ Batch (Spark) → S3/Parquet → Presto (analytical queries)
↓
Materialized Views (daily aggregates)
↓
Dashboard API (caches + pre-joins)
Scale estimates:
- 10M page views/day = 115 events/sec average, 1K/sec peak
- 100K subscriptions/day
- Store 2 years history: ~7TB uncompressed, ~700GB Parquet
- Query latency: <1s for top URLs, <5s for conversion cohorts
6. Query Interface
-- Top URLs last 7 days
SELECT canonical_url, SUM(view_count) as views
FROM daily_url_stats
WHERE date >= CURRENT_DATE - 7
GROUP BY canonical_url
ORDER BY views DESC
LIMIT 100;
-- Conversion rate for Nov 1-7 cohort, as of today
SELECT
COUNT(DISTINCT c.user_id) as cohort_size,
COUNT(DISTINCT s.user_id) as subscribers,
COUNT(DISTINCT s.user_id)::float / COUNT(DISTINCT c.user_id) as rate
FROM new_visitor_cohorts c
LEFT JOIN subscriptions s
ON c.user_id = s.user_id
AND s.timestamp BETWEEN c.first_view AND c.first_view + INTERVAL '30 days'
WHERE c.cohort_date BETWEEN '2024-11-01' AND '2024-11-07';
Key Trade-offs
- Exactness vs. speed: HyperLogLog for unique counts trades 1-2% error for 100x memory savings
- Freshness vs. correctness: Real-time metrics are provisional; daily batch corrections lag by hours
- Flexibility vs. complexity: Supporting arbitrary time windows requires either expensive scans or many pre-aggregated materialized views
Strong candidates define metrics precisely, choose appropriate granularity for pre-aggregation, handle late data explicitly, and expose uncertainty in provisional results rather than presenting false precision.