Design a Streaming Analytics Platform
A full Staff-level walkthrough of a streaming analytics platform that ingests 1M+ events/sec, runs windowed aggregations over continuous streams, and serves sub-5-second dashboards with anomaly alerting — trading processing latency against accuracy as it handles late events, exactly-once billing streams, and hot/warm/cold storage tiers. Follow it top to bottom, or jump to any step.
Requirements
Functional Requirements
- Event ingestion: Accept high-throughput events from IoT devices, mobile apps, web applications, and backend services
- Stream processing: Windowed aggregations (tumbling, hopping, sliding, session) on continuous event streams
- Real-time dashboards: Sub-5-second latency dashboards with drill-down from overview to individual events
- Anomaly alerting: Threshold-based and statistical anomaly detection with PagerDuty/Teams/email notification
- Data lake integration: Archive all raw events to Azure Data Lake for batch analytics and ML training
- Materialized views: Pre-computed aggregations queryable via REST API for downstream services
Non-Functional Requirements
- End-to-end latency: < 5 seconds from event emission to dashboard update
- Ingestion throughput: 1M+ events/sec sustained, 5M+ events/sec burst
- Processing guarantee: At-least-once for most pipelines; exactly-once for billing/financial streams
- Availability: 99.9% for processing; 99.99% for ingestion
- Retention: 7 days hot (Event Hubs), 90 days warm (Cosmos DB), 7 years cold (Data Lake)
Constraints
- Event ordering is per-partition only — no global ordering guarantee
- Late events from IoT devices with intermittent connectivity must be handled gracefully
- Multi-tenant: multiple teams share the platform with resource isolation
Back-of-envelope estimation
API design
Data model
Event Schema: Avro (in Event Hubs with Schema Registry)
Materialized Views: Cosmos DB
Cold Storage: Azure Data Lake Gen2 (Parquet)
Alert Rules: PostgreSQL
Technology Choices
- Event Hubs: Kafka-compatible, auto-inflate, native Azure integration
- Cosmos DB: Global distribution, single-digit-ms reads, partition key = source_id
- Data Lake Gen2: Hierarchical namespace, optimized for Parquet/ORC, cost-effective cold storage
- PostgreSQL: Alert rule configuration (low volume, relational queries)
High-level architecture
Data Flow: Real-Time Metric Dashboard
1. IoT device emits temperature reading → IoT Hub
2. IoT Hub routes event to Event Hubs topic (partitioned by source_id)
3. Azure Stream Analytics job applies 5-minute tumbling window aggregation
4. Aggregated result pushed to Power BI streaming dataset
5. Dashboard tile updates within 5 seconds of window close
6. If threshold breached (avg temp > 80°), alert pushed to Azure Monitor → PagerDuty
Data Flow: Late Event Correction
1. IoT device reconnects after connectivity outage, sends buffered events
2. Events arrive at Event Hubs with event_time before current watermark
3. Flink identifies events as late (event_time < watermark)
4. Late events routed to correction pipeline
5. Cosmos DB materialized view updated with corrected aggregation
6. Correction event published for downstream consumers to reconcile
Deep dives
WHERE STAFF IS WONDeep Dive 1: Event Hubs Partitioning and Ingestion
The challenge: Ingest 1M+ events/sec with ordering guarantees and replay capability.
Partition key strategy:
- IoT telemetry: partition by source_id (events from same device stay ordered)
- Multi-tenant: partition by tenant_id (isolation between teams)
- High-cardinality sources: hash-based partition assignment across 128+ partitions
Consumer group isolation: Each processing pipeline gets its own consumer group
- Stream Analytics: consumer group cg-asa
- Flink: consumer group cg-flink
- Archiver: consumer group cg-capture
- Each reads independently without interference
Auto-inflate: Starts at provisioned TUs, scales automatically to 40 TUs. For higher throughput, use Event Hubs Dedicated clusters (up to 100 CUs).
Capture: Auto-archive all events to Data Lake in Avro format
- Configurable: every 5 minutes or every 300 MB, whichever comes first
- Zero-code backup — enables full replay from Data Lake if reprocessing needed
Partition count tradeoffs:
Deep Dive 2: Windowed Aggregations and State Management
Azure Stream Analytics (SQL-like syntax for simple aggregations):
Window types:
Flink checkpointing (for complex stateful processing):
- Algorithm: Chandy-Lamport distributed snapshots
- Checkpoint interval: 30 seconds
- State backend: RocksDB on Azure Blob Storage (supports TBs of state)
- Exactly-once: checkpoint barriers align across operators; on failure, rewind to last checkpoint
Watermark algorithm:
Watermark tolerance tradeoffs:
Deep Dive 3: Materialized View Serving (Cosmos DB)
The challenge: Serve pre-computed aggregations with single-digit-ms latency for dashboards and APIs.
Partition key design: source_id as partition key
- Time-series queries: point-read by source_id, then range filter on window_end
- Cross-source queries: use Cosmos DB cross-partition queries (slower, for analytics only)
TTL: Auto-expire old aggregations — set TTL to 90 days (7,776,000 seconds)
- Old windows automatically deleted; no manual cleanup needed
Change feed: Cosmos DB change feed triggers downstream processing
- Alert evaluator subscribes to change feed → evaluates thresholds on each new aggregation
- Enables reactive alerting without polling
Consistency level tradeoffs:
Deep Dive 4: Alert Engine
Architecture:
Alert types:
1. Threshold: metric > static value (e.g., avg_temp > 80°)
2. Rate change: metric increased 5x over baseline in window
3. Anomaly detection: 7-day rolling baseline, z-score > 3 triggers alert
Deduplication: Don’t flood on-call with repeated alerts
- Group alerts by rule_id + source_id
- Configurable cooldown (default 15 minutes)
- State: last_triggered_at per (rule, source) in Cosmos DB
Fan-out: Azure Monitor → PagerDuty, Teams webhook, email
- Each channel independently configurable per alert rule
- Teams: rich card with metric graph + runbook link
Evaluation location tradeoffs:
Our choice: Change-feed-based evaluation — decoupled like sidecar but reactive like in-stream. Alert evaluator subscribes to Cosmos DB change feed, evaluates rules on each new aggregation.
Bottlenecks & tradeoffs
Bottlenecks
1. Event Hubs partition hot spots: Skewed partition key → one partition overloaded
- Mitigation: Hash-based partitioning; monitor per-partition throughput; split hot keys
1. Flink state growth for long windows: 15-minute windows with 10M sources = TBs of state
- Mitigation: RocksDB state backend with incremental checkpoints; TTL on state entries
1. Power BI push dataset rate limits: 1M rows/hour per dataset
- Mitigation: Pre-aggregate before pushing (send window results, not raw events); use DirectQuery for high-volume
1. Late event storm after connectivity restoration: Millions of buffered events arrive simultaneously
- Mitigation: Backpressure from Flink; rate-limit late correction pipeline; Event Hubs absorbs burst
Key Tradeoffs
Monitoring & Alerting
- Event Hubs throughput: Alert if > 80% of provisioned TUs
- Consumer lag: Alert if any consumer group > 30 seconds behind
- Late event rate: Alert if > 5% of events arrive late (indicates clock skew or connectivity issues)
- Flink checkpoint duration: Alert if > 60 seconds (risk of data loss on failure)
- Dashboard refresh latency: Alert if Power BI tile stale > 30 seconds
- Stream Analytics job failures: Auto-restart + alert after 3 consecutive failures
- Cosmos DB RU consumption: Alert if > 70% of provisioned RU/s
Failure Modes
- Event Hubs partition leader failover: Automatic rebalance, ~30s disruption; producers buffer locally
- Flink TaskManager crash: Job restarts from last checkpoint; exactly-once semantics preserved
- Cosmos DB throttling (429s): Retry with exponential backoff; autoscale RU/s kicks in within minutes
- Power BI push failure: Events queued in Cosmos DB; dashboard shows stale-data indicator
- IoT Hub regional outage: Devices buffer locally; reconnect to secondary region via Azure DPS (Device Provisioning Service)
Rubric — Senior vs Staff
Want more breakdowns like this?
Join free early access for upcoming RAG, LLM eval, agents, and AI infrastructure walkthroughs.