professional-cloud-data-engineer
Prepare and test your skills
Prepare and test your skills
Worked example. The correct answer is already marked and every option is explained below, so there is nothing to select here. To answer questions yourself, start the free trial.
An ecommerce company runs an Apache Beam streaming pipeline on Google Cloud Dataflow to track product inventory updates from high-throughput retail transactions. The pipeline performs stateful aggregations using Combine.perKey within fixed temporal windows configured with early and late triggers to handle incremental updates and late-arriving data.
The resulting inventory totals must be written to Cloud Spanner. Because streaming Dataflow pipelines retry failed worker tasks indefinitely, the write mechanism must be fully idempotent, prevent primary key collision errors during retries or multiple trigger firings for the same window key, and maintain exactly-once sink semantics without pipeline stalls.
Which approach should you implement to write the aggregated inventory totals to Cloud Spanner?
INSERT_OR_UPDATE with SpannerIO.write() IsIn Apache Beam and Google Cloud Dataflow, writing to Cloud Spanner is typically handled via the native SpannerIO.write() transform using mutation objects. The INSERT_OR_UPDATE (or upsert) mutation type instructs Cloud Spanner to insert a new row if the primary key does not exist or update the existing row's column values if the record is already present.
INSERT_OR_UPDATE mutations can be applied multiple times without throwing unique key constraint or duplicate record exceptions, re-executing a bundle following a transient network glitch or worker crash is completely safe.INSERT_OR_UPDATE updates the stored state in Spanner in-place with the latest accumulated values without failing on duplicate keys.ALREADY_EXISTS mutation errors that cause streaming pipelines to crash or stall in infinite retry loops.SpannerIO.write() automatically batches incoming mutations to maximize throughput across Spanner splits.Using INSERT_OR_UPDATE mutations natively within SpannerIO.write() provides the highest write throughput and the required idempotency. It cleanly accommodates the non-deterministic arrival of late data and Dataflow worker retries without requiring complex external locking or manual duplicate checking.
Keep the momentum going with these hand-picked practice scenarios
Want more questions like this?
Get a free certification question every week.