Core Transformations⏱️ ~10 mins
17. Stream Deduplication
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
Clickstream events often produce duplicates due to network retries from mobile clients. Pipelines deduplicate events before downstream ingestion.
### Problem Statement
Write a function `distinct_elements(input_pcoll)` that eliminates duplicate elements across a PCollection using `beam.Distinct()`.
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:
[1, 1, 2, 2, 3]
Expected Output:
[1, 2, 3]
Sample Example 2
Input Stream:
['A', 'A', 'B']
Expected Output:
['A', 'B']
Topics:#Distinct#Fundamentals
solution.pyPython 3.11 (Apache Beam)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Input PCollection5 elements
| # | Element / Payload |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |
| 5 | 3 |
Expected Output PCollection3 elements
| # | Output Element |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
Core Transformations⏱️ ~10 mins
17. Stream Deduplication
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
Clickstream events often produce duplicates due to network retries from mobile clients. Pipelines deduplicate events before downstream ingestion.
### Problem Statement
Write a function `distinct_elements(input_pcoll)` that eliminates duplicate elements across a PCollection using `beam.Distinct()`.
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:
[1, 1, 2, 2, 3]
Expected Output:
[1, 2, 3]
Sample Example 2
Input Stream:
['A', 'A', 'B']
Expected Output:
['A', 'B']
Topics:#Distinct#Fundamentals