Skip to main content

14. Distributed Average Sensor ReadingMedium

Aggregations & Grouping⏱️ ~12 mins

14. Distributed Average Sensor Reading

Enterprise Architecture Context

In production stream-processing architectures (Google Cloud Dataflow / Flink), pipeline stages must handle parallel transformations without data loss, managing schema mutations and aggregations across distributed worker workers.

Problem Statement

### Business Context Environmental monitoring stations calculate the arithmetic mean temperature across hundreds of remote geographic sensors. ### Problem Statement Write a function `mean_reading(input_pcoll)` that calculates the global arithmetic mean across all numeric elements in a PCollection using `beam.combiners.Mean.Globally()`.

Key Learning Objectives

  • Understand distributed Apache Beam execution DAG stages and pipeline lifecycle.
  • Apply idiomatic functional Python transforms using the pipe operator |.
  • Ensure data consistency and idempotency across distributed stream workers.

Sample Data Fixtures

Sample Example 1
Input Stream:
[10, 20, 30]
Expected Output:
20.0
Sample Example 2
Input Stream:
[5, 5, 5]
Expected Output:
5.0
Topics:#CombineGlobally#Aggregations
Support