Real-Time Data Reporting Platform

E-commerce Recommendation System

A unified platform to collect, process, analyze recommendation events and power business + engineering dashboards at 2B+ events/day scale.


1. System Overview

Core Objectives


2. High-Level Architecture

flowchart TD A[User Clicks / Impressions] --> B[Event Collector SDK] B --> C[Kafka — Raw Events] C --> D[Flink Stream Processor] C --> E[Spark Batch Processor] D --> F[Real-Time Metrics Store\nRedis / Druid] E --> G[Data Warehouse\nSnowflake / BigQuery] F --> H[Engineering Dashboard\nGrafana] G --> I[BI Dashboard\nTableau / Superset] D --> J[Data Quality Engine] E --> J J --> K[Alert Manager\nPagerDuty / Slack] G --> L[ML Feature Store\nFeast / Tecton] L --> M[Recommendation Model]

3. Data Ingestion Layer

3.1 Event Schema

Recommendation Event — Required Fields

FieldTypeDescriptionRequired
event_idUUIDUnique event identifierYes
user_idSTRINGHashed user identifierYes
item_idSTRINGRecommended item SKUYes
event_typeENUMimpression / click / add_to_cart / purchaseYes
timestampINT64Unix epoch msYes
session_idSTRINGBrowser/app sessionYes
rec_model_verSTRINGModel version that served the resultYes
positionINTRank position in recommendation listYes
revenueFLOATTransaction value (purchase only)No
page_contextSTRINGHomepage / PDP / CartNo

3.2 Ingestion Pipeline

flowchart LR A[Mobile SDK] --> D[API Gateway\nKong] B[Web SDK] --> D C[Server Events] --> D D --> E[Kafka\n32 partitions\n3x replication] E --> F[Schema Registry\nAvro]

Kafka Config

ParameterValue
Topicsraw.events / validated.events / dlq.events
Partitions32 per topic
Retention7 days
Throughput target2.5M events/min peak
Replication3x

Throughput Estimate

Peak Events/sec
28000
Avg Event Size
~800B
Daily Volume
~1.8TB raw
Kafka Capacity Used (peak)68%

4. Stream Processing — Real-Time Pipeline

flowchart LR A[Kafka\nraw.events] --> B[Flink Job 1\nValidation & Enrichment] B --> C[Kafka\nvalidated.events] B --> D[Kafka\ndlq.events] C --> E[Flink Job 2\nMetric Aggregation] E --> F[Druid\nOLAP Store] E --> G[Redis\nLive Counters]

4.1 Flink Job: Validation & Enrichment

Validation Rules Applied Per Event

4.2 Flink Job: Real-Time Metric Aggregation

MetricWindowSinkUse Case
CTR (clicks/impressions)1min / 5min tumblingDruid + RedisLive dashboard
CVR (purchases/clicks)5min / 15min tumblingDruidConversion monitoring
Revenue per model5min tumblingDruidA/B experiment tracking
DLQ rate1min tumblingRedis + AlertData quality alerting
P99 event latency30s slidingRedisEng health monitoring
Feature freshness lag1min tumblingRedisML model health

5. Batch Processing — Historical Pipeline

flowchart LR A[Kafka\nraw.events] --> B[S3 / GCS\nRaw Data Lake\nParquet/day] B --> C[Spark ETL\nHourly + Daily] C --> D[Data Warehouse\nSnowflake / BigQuery] D --> E[dbt Models\nBusiness Layer] E --> F[BI Dashboard\nTableau / Superset] E --> G[ML Feature Store\nFeast / Tecton]

5.1 Spark Batch Jobs Schedule

T+00 — 05: Hourly micro-batch — Spark reads S3 partition, validates schema, writes to DW staging
T+01 — 00: Hourly aggregation — CTR/CVR/revenue rolled up per hour per model version
T+06 — 00: Daily full refresh — Recompute 30-day cohort metrics, funnel analysis
T+07 — 00: ML feature batch — Recompute collaborative-filtering features, write to Feature Store
T+08 — 00: dbt run — Refresh business-layer models for BI dashboards

5.2 Data Warehouse Schema (Star Schema)

Core Tables

TableTypeGrainRetention
fact_rec_eventsFact1 row per event2 years
fact_rec_dailyFact (agg)model × date × category3 years
dim_itemDimension1 row per itemCurrent
dim_user_segmentDimension1 row per user tierCurrent
dim_model_versionDimension1 row per model deployPermanent
dim_dateDimension1 row per datePermanent

6. Data Quality & Alerting

6.1 Data Quality Engine

flowchart TD A[Validated Events Stream] --> B[Quality Rule Engine\nFlink / Great Expectations] B --> C{Pass?} C -- Yes --> D[Metrics Store] C -- No --> E[DLQ + Quality Event] E --> F[Alert Manager] F --> G[PagerDuty\nP1 — Data Outage] F --> H[Slack\nP2 — Quality Degradation] F --> I[Dashboard Warning\nP3 — Anomaly]

6.2 Quality Rules Catalog

RuleThresholdAction
Null event_id rate>0.01%P1 Alert + pause ingestion
Null user_id rate>0.5%P2 Alert
Invalid event_type>0.1%P2 Alert + route to DLQ
Timestamp drift >10min>1%P2 Alert
Missing revenue on purchase>0.01%P1 Alert
⚠️
Alert Routing Policy
P1 alerts page on-call engineer immediately via PagerDuty. P2 alerts post to #data-quality Slack channel. P3 anomalies surface as dashboard warning banners only. All alerts auto-attach a runbook link.

7. Dashboards

7.1 Business Dashboard (BI — Tableau / Superset)

Key Business KPIs

Overall CTR
4.2%▲ +0.3%
Target: 4.5%
CVR
2.1%▲ +0.1%
Target: 2.5%
Revenue via Rec
$1.8M/day▲ +8%
Target: $2M/day
Rec Coverage
72%▲ +2%
Target: 80%

Model Performance

7.2 Engineering Dashboard (Grafana)

Pipeline Health

Kafka Consumer Lag
<5K msgs
Flink Checkpoint Interval
30s
Spark Job P99 Duration
22min
DLQ Rate (live)
0.04%

Infrastructure

Kafka Disk Usage61%
Flink TM Memory74%
Druid Query Cache Hit88%
Redis Memory55%

8. ML Feature Freshness Monitoring

Feature Store Design

flowchart LR A[Batch Features\nSpark — daily] --> C[Feature Store\nFeast / Tecton] B[Stream Features\nFlink — 1min] --> C C --> D[Online Store\nRedis — serving] C --> E[Offline Store\nS3 + DW — training] D --> F[Recommendation\nModel Server]

8.1 Feature Freshness SLAs

Feature GroupUpdate FreqMax Allowed StalenessAlert Threshold
User interaction history1 min stream5 min>3 min lag
Item popularity scores5 min stream15 min>10 min lag
User-item affinity matrixHourly batch2 hrs>90 min lag
Collaborative filter embDaily batch26 hrs>25 hr lag
User demographic featuresDaily batch26 hrs>25 hr lag
ℹ️ Feature freshness metrics are published to Grafana and compared against a rolling 7-day baseline. Any staleness breach automatically blocks model promotion in the CI/CD pipeline.

9. Technology Stack

ComponentTechnologyPurpose
Event SDKCustom JS/iOS/AndroidClient-side event capture
API GatewayKongRate limiting, auth, routing
Message BrokerApache KafkaDurable event streaming
Schema RegistryConfluent SR (Avro)Schema enforcement and evolution

10. Scalability & SLA Summary

Throughput Targets

Daily Events
2B+▲ +5%
Target: 2B
Peak Throughput
28K/sec▲ +8%
Target: 30K/sec
Stream End-to-End
<500ms▼ 0%
Target: <500ms
Batch SLA
<30min▼ -5%
Target: <30min

Reliability Targets

Ingestion Uptime
99.99%▼ 0%
Target: 99.99%
Data Completeness
>99.9%▲ +0.02%
Target: 99.9%
DLQ Rate
<0.1%▼ -0.02%
Target: <0.1%
Feature Freshness SLA
99.7%▲ +0.2%
Target: 99.5%

Key Design Decisions

  1. Lambda Architecture — Flink for speed layer (real-time), Spark for batch layer (accuracy), Druid/DW as serving layer satisfies both latency and historical query needs
  2. Schema Registry with Avro — Enforces schema evolution contracts at ingestion time, preventing downstream breakage from producer changes
  3. DLQ-first validation — Invalid events are never silently dropped; they're routed to dlq.events for replay after fixes, ensuring no data loss
  4. Feature freshness gating — Model promotion in CI/CD is blocked if any feature group breaches its freshness SLA, preventing stale-feature degradation in production
  5. Tiered alerting (P1/P2/P3) — Reduces alert fatigue by separating actionable outages (P1) from quality degradation (P2) and monitoring anomalies (P3)
🚀
Next Steps
Phase 1: Deploy Kafka + Flink stream pipeline with validation. Phase 2: Build Spark batch ETL and DW models. Phase 3: Launch BI + Grafana dashboards. Phase 4: Integrate Feature Store with ML model CI/CD.