Prepare and test your skills
Prepare and test your skills
Cloud Dataflow (opens in a new tab) is the fully managed service for running Apache Beam pipelines that perform distributed batch and streaming preprocessing for machine learning. Data flows from sources such as Pub/Sub, Apache Kafka (opens in a new tab), Cloud Storage, or databases through Beam transforms that run in parallel across Dataflow workers to sinks such as BigQuery. Dataflow provides autoscaling, ML-component integration, and GPU and right-fitting support, which makes it the choice when preprocessing needs distributed scale, low-latency streaming, and transformation logic beyond SQL.
Unified batch and streaming pipelines with Apache Beam on Dataflow let teams run the same pipeline code in batch or streaming mode. A Beam pipeline is built from a pipeline definition, PCollections, transforms, and a runner, where PCollections carry distributed data and transforms apply parallel processing that the runner executes on Dataflow workers. This unification lets one feature pipeline process historical backfill and live events with identical logic, so training features stay consistent with serving features across the production lifecycle.
Teams can start from predefined pipelines or build custom logic. Built-in Dataflow templates are predefined Beam pipelines deployable through a code-free job wizard, including templates for exporting Kafka data and the Java Database Connectivity (JDBC) to BigQuery template. Choose a custom Apache Beam pipeline for maximum flexibility when templates do not meet requirements, such as integrating an unsupported source or sink or performing transformations, normalizations, or mutations on records. For reuse and consistency, create libraries of reusable transforms that are shared between batch and streaming paths.
Beam pipelines are also portable across runners. A pipeline designed for Dataflow can run on other runners, such as the Apache Spark Runner on a local on-premises Spark cluster for backup or disaster recovery. Check the Beam Capability Matrix to confirm whether a specific runner supports a pipeline operation, since not every runner implements every Beam operation.
Complex transformations for feature engineering are high-volume operations for cleaning, enrichment, joining, and aggregation that go beyond per-message modification. Data flows from the source through cleaning, enrichment, joining, and aggregation steps before reaching the target system. For example, clone the JDBC to BigQuery template code and modify the template to add Apache Beam transforms that transform data before writing to BigQuery.
This capability differentiates Dataflow from Kafka Connect. Kafka Connect, including MirrorMaker 2.0, is the typical choice for transferring data between Kafka clusters for cluster migration, backup, disaster recovery, or basic transformations. Kafka Connect supports record-at-a-time transformations for basic, per-message modifications. Choose Dataflow when migration requires complex transformations with data cleaning, enrichment, and aggregation before data reaches the target Managed Service for Apache Kafka cluster.
Dataflow also supports change data capture (CDC) inputs for feature pipelines. Use DebeziumIO for relational databases such as Cloud SQL, MySQL, Postgres, and SQL Server, use Spanner Change Streams for Spanner, and use Bigtable Change Streams for Bigtable. Dataflow provides connectors to read from Apache Kafka to Dataflow and to write from Dataflow to Apache Kafka, plus code samples for Kafka integration.
Exam tip: Choose Kafka Connect for Kafka-to-Kafka transfer with per-message changes, and choose Dataflow when you must join multiple streams with windowing, alignment, cleaning, enrichment, or aggregation.
Custom windowing and stream correlation is the grouping and alignment logic that joins multiple streaming inputs into features. Windowing groups unbounded streaming elements by event time into bounded collections, and alignment logic correlates elements from different streams that arrive at different times. The pipeline then applies aggregation and correlation across each window to produce features such as counts, averages, session activity, or joined entity views.
Pub/Sub provides the scalable and durable event ingestion service that delivers messages to and from streaming Dataflow pipelines. For an event-driven architecture, combine Dataflow with Eventarc to efficiently trigger processing for ML. Because windows and triggers define when results are emitted, the same Beam pipeline can produce early speculative results and later refined results as late data arrives, which is essential for complex data correlation and aggregation in production.
Consistent preprocessing means the transformations applied during training are identical to those applied during serving. Dataflow supports this pattern by running the same Beam transforms and reusable transform libraries in offline batch jobs that generate training data and in streaming jobs that generate serving features. Integration with TensorFlow Transform (tf.Transform) extends this pattern by embedding the full-pass analysis and per-example transformation graph into both the training pipeline and the serving graph, so training-serving skew does not occur when vocabularies, means, or scaling factors change.
Validation is part of the same lifecycle. Use TensorFlow Data Validation (TFDV) to validate schemas and detect anomalies in features before training or serving. Where applicable, take advantage of automated data quality scans in BigQuery to check staged and production tables. Together, standardized Dataflow collection and processing plus TFDV checks reduce duplicated engineering, lower retraining cost, and keep model inputs aligned with business requirements.
Preprocessing framework selection depends on scale, latency, and complexity. Dataflow fits distributed batch and streaming workloads, Managed Service for Apache Spark fits existing Spark pipelines, and BigQuery fits SQL-based set transformations. The following comparison summarizes when each engine controls cost and complexity.
| Framework | Processing model | Choose when |
|---|---|---|
| Cloud Dataflow for Apache Beam | Unified batch and streaming with parallel workers | Work needs complex transformations, custom windowing, stream joins, or unified training-serving pipelines |
| Managed Service for Apache Spark | Managed Spark batch and Spark Streaming | Team has existing Spark pipelines or Spark Kafka integration to migrate |
| BigQuery with SQL | Extract, load, and transform (ELT) with SQL queries | Transformation is SQL-expressible on a staging table that writes to a final production table |
In the ELT pattern, load data into a staging table with an extract and load tool, then transform data in the staging table using SQL queries that write output into the final production table. Choose BigQuery when an SQL-based process is appropriate, and choose Dataflow when the work requires custom Beam logic, streaming windowing, or ML-component integration.
A Dataflow pipeline reads data from sources and writes data to sinks, and it might call external systems for enrichment, filtering, or business logic within a processing step. Dataflow runs pipeline stages in parallel across multiple workers that are Compute Engine virtual machine (VM) instances, so sufficient Compute Engine quota is required or autoscaling is hindered and jobs may not start. Factors outside pipeline code also bound scalability and must be planned explicitly:
Calling external services incurs per-call overhead and quota risk. Many native Beam I/O transforms automatically batch requests, including BigQueryIO for streaming inserts. Because Dataflow parallelizes work, too much traffic can overwhelm an external service or exhaust daily quotas or per-second rate limits, and autoscaling can add workers to a slow external-call step and add further pressure. Batch multiple elements into single requests where possible and limit batch sizes and concurrent calls to sustainable levels.
Using Google Cloud managed sources and sinks removes much capacity planning with built-in scalability and consistent performance. Pub/Sub quotas and limits are designed around project-level usage, where publishers and subscribers in different projects receive independent data-throughput quotas. If multiple pipelines publish or subscribe to a single topic, deploy each pipeline into its own project to obtain maximum allowable throughput on that topic, and request a quota increase if any single pipeline exceeds per-project quotas and limits.
Tabular feature engineering on Google Cloud is a choice between moving data to computation and moving computation to data. Single-node in-memory Python frameworks pull a dataset into the memory of one notebook or virtual machine for flexible prototyping, while BigQuery (opens in a new tab) runs SQL transformations where enterprise-scale structured data already lives. Dataset size, computation location, and latency determine which approach controls cost and performance.
In-memory Python prototyping uses single-node libraries such as pandas that load an entire dataset into memory on one machine for exploration and feature prototyping. Data flows from the storage layer in BigQuery storage or Cloud Storage to a Vertex AI Workbench notebook instance, where one-off Python scripts apply cleaning, scaling, encoding, and new-feature logic. This pattern fits smaller datasets that fit into memory and supports fast iteration on samples before committing to production pipelines.
Because the notebook must hold the full working set, large tables increase memory pressure, transfer time, and outbound data-transfer cost. The penalty grows when computation runs in a different zone than storage, since data must travel between zones for every load and write. Use this pattern for sampling and rapid iteration, then move repeatable logic to a distributed or in-warehouse engine.
Scalable in-warehouse transformation with BigQuery SQL keeps unprocessed structured and semi-structured tabular data in BigQuery tables and transforms it where it is stored. BigQuery is a serverless SQL data warehouse that combines managed storage with on-demand computation, so no computation layer has to be deployed. SQL transformations for filtering, joins, feature scaling, encoding categorical variables, and creating new features run directly against that stored data.
When the model is built with BigQuery ML, the transformations built into BigQuery ML handle preprocessing, and when the model uses AutoML, the transformations built into AutoML handle preprocessing. For custom models, using the BigQuery transformations is often the most cost-effective method because data does not move to an external cluster and compute scales automatically with bytes scanned. BigQuery controls enterprise-scale cost and latency with physical design that keeps computation close to storage.
Partitioning divides a table by a TIMESTAMP or DATE column or by ingestion time so queries scan only a subset of data, which improves performance and reduces bytes read. Clustering sorts data by frequently filtered columns and colocates similar values in optimally sized blocks so queries skip unnecessary scans and aggregate faster without indexes. Together with nested and repeated fields, partitioning and clustering let in-warehouse feature queries scale to huge datasets that would not fit on a single node.
Selection between in-memory Python and BigQuery SQL depends on where the data lives, how large it is, and whether the work is exploratory or repeatable. Use one-off Python scripts for smaller in-memory samples and notebook experimentation, and use BigQuery SQL when the table is large, frequently accessed, or already centralized for reuse. Transformations that are not expressible in SQL or that require streaming use a combination of Dataflow and pandas, where Dataflow handles distributed batch or streaming execution and pandas handles the custom logic.
| Option | Where computation runs | Dataset fit | Choose when |
|---|---|---|---|
| In-memory Python frameworks | Single notebook or virtual machine memory after data is extracted from BigQuery or Cloud Storage | Smaller datasets that fit into memory | Work is exploratory prototyping, sampling, and rapid iteration on features |
| BigQuery SQL and BigQuery ML | Serverless warehouse where the table is stored, with no cluster to deploy | Enterprise-scale structured datasets that exceed single-node memory | Work is scalable, repeatable in-warehouse transformation with cost and latency control |
Store data in the same zone that processes it to reduce communication time, latency, outbound transfer cost, and I/O operations between storage and computation. After preprocessing, managed datasets can link the resulting features to custom-trained models with descriptive statistics and train, test, and validation splits, preserving lineage from warehouse transformation to training.
Exam tip: Use one-off Python scripts only for smaller datasets that fit into memory; use BigQuery transformations for large tabular datasets to keep computation where the data lives.
Managed Service for Apache Spark (opens in a new tab) is a managed Apache Hadoop environment for distributed preprocessing, while BigQuery and Dataflow are serverless alternatives with no clusters to manage. Managed Service for Apache Spark runs any workload compatible with the Hadoop framework, including Apache Spark, Apache Flink, and Apache Hive, which makes it the direct landing zone for existing PySpark and Hadoop code. BigQuery (opens in a new tab) provides serverless SQL transformation without a computation layer to deploy, and Dataflow provides a Google-managed processing engine for parameterized batch and streaming pipelines.
Storage and compute separation is the design where the data storage layer, where bytes are saved, is independent from the data computation layer that loads, processes, and saves results. The storage layer on Google Cloud is typically Cloud Storage, BigQuery storage, Cloud SQL, Spanner, or Bigtable, while the computation layer is Managed Service for Apache Spark, Dataflow, BigQuery, or custom workloads on Google Kubernetes Engine (GKE) or Compute Engine. Keeping storage outside the cluster in Cloud Storage or BigQuery is the design that makes clusters disposable and portable across regions. When storage lives inside the cluster, most commonly as Hadoop Distributed File System (HDFS) data, compute and data cannot migrate independently.
Managed Service for Apache Spark favors many short-lived ephemeral clusters over one monolithic long-lived cluster. An ephemeral cluster is built to run one job or group of jobs and then destroyed, which also destroys its HDFS layer and any other cluster state:
Long-living clusters stay up even with no running jobs. Long-living clusters with external data keep data on Cloud Storage or BigQuery, so data and compute are separate and migration resembles the ephemeral model. This model fits continuous job arrivals where teardown and setup overhead is wasteful. Long-living clusters with data in the cluster keep state and data inside, which complicates migration with high risk of inconsistency and should be refactored to external storage before migration.
Migration of existing PySpark and Hadoop codebases to Managed Service for Apache Spark works best with an incremental approach that isolates each job from a mature on-premises environment. Each job is examined in isolation to evaluate its needs and determine the best migration path. Unexpected problems are then handled without delaying dependent tasks, and a proof of concept can be built for each complex process without affecting production. The result is a deliberate move to the ephemeral model rather than a lift of a monolithic cluster.
Dependency and environment parity determines how much work each job needs. First, check that job dependencies are covered by the supported Managed Service for Apache Spark versions, since frameworks, versions, and configurations vary widely and require thorough testing before migration. When custom software is required, the supported paths are creating a custom image, using initialization actions, and specifying Python dependencies:
Portability also depends on removing hardcoded environment assumptions. Inputs and outputs must not be hardcoded in source code; jobs should receive Cloud Storage paths, table names, and database connection strings as arguments or parameters. Provisioning of the Managed Service for Apache Spark environment, including framework configurations, should be automated so the same definition recreates the cluster in a new region.
Serverless batch preprocessing with BigQuery and Dataflow engines removes cluster sizing and management from preprocessing. BigQuery is a serverless SQL data warehouse for preprocessing data where SQL is sufficient, and no computation layer is deployed or sized. Data is stored as BigQuery tables, where BigQuery manages the data files, or as BigQuery external tables, where data lives outside BigQuery in systems like Cloud Storage. Migration across regions is therefore a data problem rather than a cluster problem: managed datasets are copied, external tables are recreated at the new destination after data moves, and any clients that specify processing regions must be adjusted.
Dataflow is a Google-managed data processing engine for batch preprocessing that must run in any region without cluster management. Jobs should inject all inputs and outputs as parameters instead of writing Cloud Storage paths and connection strings into source code. Passing paths and connection strings as arguments lets the same job deploy to source and target regions without code changes. Choose BigQuery when transformation logic can be expressed in SQL and operational overhead must be near zero, and choose Dataflow when the pipeline is new or can be rewritten from Spark to a portable Beam-style pipeline where unified batch handling with autoscaling matters more than Spark compatibility.
Movement of processed data from Spark to BigQuery uses the Spark-BigQuery connector to bridge distributed computation and warehouse storage. The Spark-BigQuery connector lets Spark applications read from and write to BigQuery by using abstracted versions of the Hadoop InputFormat and OutputFormat classes. On Managed Service for Apache Spark clusters with image version 2.1 or later, the connector is pre-installed and streamlines loading processed data from Cloud Storage into a BigQuery table. A typical PySpark job reads Parquet from a Cloud Storage path such as gs://BUCKET_NAME/processed/processed_data, performs aggregations with groupBy and ordering, and then writes with format bigquery to a target such as PROJECT_ID.DATASET.corpus_word_counts in append mode.
The job is submitted with gcloud dataproc jobs submit pyspark, where workers fetch the script from Cloud Storage and execute it on the cluster. The connector uses an indirect write method that decouples Spark computation from BigQuery ingestion for high performance:
spark.hadoop.google.cloud.bigdata.connector.temporary.gcs.bucket.The decision framework for Managed Spark versus serverless engines turns on code reuse, library control, and who manages compute. Managed Service for Apache Spark keeps Spark APIs and custom environments, while Dataflow and BigQuery remove cluster operations at the cost of rewriting logic. The following comparison preserves those tradeoffs for migration planning.
| Engine | Operational model | Choose when |
|---|---|---|
| Managed Service for Apache Spark | Managed Hadoop clusters you configure per job, ephemeral or long-living | Existing PySpark, Hadoop, Hive, or Flink code must run with minimal rewrite and specialized libraries or initialization actions are required |
| Dataflow | Google-managed processing engine with no clusters | Batch preprocessing can be parameterized and ported, and regional portability and autoscaling matter more than Spark APIs |
| BigQuery | Serverless SQL warehouse with no computation layer to deploy | Preprocessing is SQL-based aggregation and filtering on managed or external tables, and lowest operational overhead is required |
Exam tip: Keep state out of Managed Service for Apache Spark clusters by storing data on Cloud Storage or BigQuery and passing paths as parameters; clusters that retain HDFS data inside cannot migrate compute separately from data.
Choose Cloud Dataflow for Apache Beam when work needs complex transformations, custom windowing, stream joins, or unified training-serving pipelines with parallel workers. Choose Managed Service for Apache Spark when the team has existing Spark pipelines or Spark Kafka integration to migrate. Choose BigQuery with SQL when transformation is SQL-expressible on a staging table that writes to a final production table.
Use one-off Python scripts with in-memory Python frameworks such as pandas only for smaller datasets that fit into single-node memory for exploratory prototyping, sampling, and rapid iteration. Use BigQuery SQL and BigQuery ML for enterprise-scale structured datasets that exceed single-node memory because transformations run where the table is stored with no cluster to deploy. BigQuery controls scan cost and latency with partitioning by TIMESTAMP, DATE, or ingestion time and clustering that colocates similar values to skip unnecessary scans.
Choose Kafka Connect, including MirrorMaker 2.0, for transferring data between Apache Kafka clusters for cluster migration, backup, disaster recovery, or basic per-message modifications. Choose Cloud Dataflow when migration requires complex transformations with data cleaning, enrichment, joining, windowing, alignment, or aggregation before data reaches the target cluster.
Last updated