Prepare and test your skills

Prepare and test your skills

Free sample question, answered and explained below. The Professional Data Engineer practice bank has 1,353 more like it. Try 10 free: instant score, no account.
A data engineering team is designing a streaming pipeline using Apache Beam running on Cloud Dataflow to process financial transactions and sink transformed account balances into Google Cloud Spanner.
During disaster recovery and worker failure testing, the team observes that pipeline tasks retry and fail with com.google.cloud.spanner.SpannerException: ALREADY_EXISTS exceptions, causing the Dataflow job to crash.
Which mutation strategy should the team implement in their Apache Beam transformation logic to ensure resilient and idempotent writes to Cloud Spanner?
An Apache Beam Reshuffle transform reorganizes data across worker boundaries by preventing transform fusion and redistributing elements across worker threads or instances via an intermediate shuffle step.
Reshuffle alters data partitioning and prevents upstream/downstream fusion, it does not guarantee exactly-once external side-effects when writing to an external sink like Cloud Spanner.INSERT bundle to Spanner, Dataflow will retry the bundle. Because the primary key was committed on the first attempt, the retried newInsertBuilder mutation will throw ALREADY_EXISTS.Reshuffle is primarily used to balance workloads, prevent memory pressure, or break fusion across computationally heavy stages.You needed to redistribute skewed key distributions or prevent memory exhaustion caused by transform fusion before a CPU-intensive step.
In distributed stream processing, exactly-once processing guarantees within Beam internal state mechanisms do not automatically translate to exactly-once writes in external databases unless the target sink supports idempotent or two-phase commit mechanisms.
Apache Beam's Deduplicate transform maintains internal state to identify and drop duplicate records within a specified window or time duration before passing elements downstream.
Deduplicate filters duplicates present in the incoming data stream, but it cannot prevent duplicate write attempts caused by Dataflow worker crashes during the sink phase itself.Mutation.newInsertBuilder is strictly an insert operation, any sink-level bundle retry inevitably triggers ALREADY_EXISTS.You were trying to eliminate duplicate messages generated by upstream producers prior to windowed stateful aggregation, and your sink was already inherently idempotent.
To achieve true end-to-end fault tolerance, pipelines writing to external key-value or relational stores must use idempotent mutations (such as INSERT_OR_UPDATE) regardless of upstream deduplication logic.
The Mutation.newInsertOrUpdateBuilder (in the Java SDK) and SpannerInsertOrUpdate (in the Python SDK) are mutation factory methods used in Apache Beam pipelines to perform idempotent upserts into Google Cloud Spanner. When applied, this operation checks if a row with the specified primary key exists: if it exists, Spanner updates the matching column values; if it does not exist, Spanner inserts a new row.
INSERT_OR_UPDATE prevents Spanner from throwing ALREADY_EXISTS exceptions because reapplying an upsert mutation with identical key-value data is completely idempotent.SpannerIO.write(), which batches mutations automatically for high-performance ingestion.Mutation.newInsertOrUpdateBuilder) and Python SDK (SpannerInsertOrUpdate).Cloud Spanner's native INSERT_OR_UPDATE mutation is specifically designed for high-scale batch and streaming pipelines where distributed runners like Cloud Dataflow cannot guarantee exactly-once side-effects at external storage sinks without idempotent writes.
This approach attempts to manually enforce uniqueness by executing an interactive read-write SQL transaction (e.g., executing SELECT COUNT(1) followed by INSERT) inside a custom Beam DoFn using Cloud Spanner client libraries instead of the optimized SpannerIO connector.
DoFn transaction handling bypasses SpannerIO's built-in batching, automatic backoff, and optimized RPC mutation channels.The workload required strict multi-table relational invariants that depend on reading dynamic state within a short interactive transaction window outside of streaming ingestion sinks.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated