How Should You Route Failed Dataflow Messages for Alerting?

Your car factory is pushing machine measurements as messages into a Pub/Sub topic in your Google Cloud project. A Dataflow streaming job, that you wrote with the Apache Beam SDK, reads these messages, sends acknowledgment to Pub/Sub, applies some custom business logic in a DoFn instance, and writes the result to BigQuery. You want to ensure that if your business logic fails on a message, the message will be sent to a Pub/Sub topic that you want to monitor for alerting purposes. What should you do?

  1. Enable retaining of acknowledged messages in your Pub/Sub pull subscription. Use Cloud Monitoring to monitor the subscription/num_retained_acked_messages metric on this subscription.
  2. Use an exception handling block in your Dataflow’s DoFn code to push the messages that failed to be transformed through a side output and to a new Pub/Sub topic. Use Cloud Monitoring to monitor the topic/num_unacked_messages_by_region metric on this new topic. Source Reference Answer
  3. Enable dead lettering in your Pub/Sub pull subscription, and specify a new Pub/Sub topic as the dead letter topic. Use Cloud Monitoring to monitor the subscription/dead_letter_message_count metric on your pull subscription.
  4. Create a snapshot of your Pub/Sub pull subscription. Use Cloud Monitoring to monitor the snapshot/num_messages metric on this snapshot.

Community Votes

B
100%

100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

This question tests your knowledge of Apache Beam error handling patterns, with the common trap being the assumption that managed Pub/Sub features like dead-letter topics integrate directly with Dataflow.

When processing Pub/Sub messages in Apache Beam pipelines, failed records must be routed using DoFn side outputs rather than relying on native Pub/Sub dead-letter topics. The community and official guidance consistently validate this pipeline-native approach for reliable monitoring and production alerting.

Option C is frequently chosen because candidates assume Pub/Sub dead-letter topics work seamlessly with Dataflow, but this configuration is officially unsupported and requires explicit pipeline implementation instead.

Community Discussion (9 comments)

raaad 👍 14 Selected: B
  • Exception Handling in DoFn: Implementing an exception handling block within DoFn in Dataflow to catch failures during processing is a direct way to manage errors. - Side Output to New Topic: Using a side output to redirect failed messages to a new Pub/Sub topic is an effective way to isolate and manage these messages. - Monitoring: Monitoring the num_unacked_messages_by_region on the new topic can alert you to the presence of failed messages.
chrissamharris 👍 2
Option C - dead letter topic is built in and requires no changes https://cloud.google.com/pubsub/docs/handling-failures Enable dead lettering in your Pub/Sub pull subscription, and specify a new Pub/Sub topic as the dead letter topic. Use Cloud Monitoring to monitor the subscription/dead_letter_message_count metric on your pull subscription.
7787de3 👍 1 Selected: B
See here: https://cloud.google.com/dataflow/docs/concepts/streaming-with-cloud-pubsub#unsupported-features It's not recommended to use Pub/Sub dead-letter topics with Dataflow (...) Instead, implement the dead-letter pattern explicitly in the pipeline
Jeyaraj 👍 1
Option B. Here's why: Side Output for Failed Messages: Dataflow allows you to use side outputs to handle messages that fail processing. In your DoFn , you can catch exceptions and write the failed messages to a separate PCollection . This PCollection can then be written to a new Pub/Sub topic. New Pub/Sub Topic for Monitoring: Creating a dedicated Pub/Sub topic for failed messages allows you to monitor it specifically for alerting purposes. This provides a clear view of any issues with your business logic. topic/num_unacked_messages_by_region Metric: This Cloud Monitoring metric tracks the number of unacknowledged messages in a Pub/Sub topic. By monitoring this metric on your new topic, you can identify when messages are failing to be processed correctly.
joao_01 👍 1
I would like to know why isn't anyone considering the option C.
hanoverquay 👍 1 Selected: B
option B
JyoGCP 👍 1 Selected: B
Option B
Matt_108 👍 1 Selected: B
Option B - Raaad explanation is complete
scaenruy 👍 1 Selected: B
B. Use an exception handling block in your Dataflow’s DoFn code to push the messages that failed to be transformed through a side output and to a new Pub/Sub topic. Use Cloud Monitoring to monitor the topic/num_unacked_messages_by_region metric on this new topic.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Using an exception handling block inside the DoFn allows you to catch transformation failures and route problematic messages via a side output to a dedicated Pub/Sub topic. This pipeline-native pattern aligns with Apache Beam best practices and enables precise Cloud Monitoring alerts on unacked message counts. By isolating errors at the processing stage, you maintain data integrity while ensuring real-time observability.

Why the Other Options Are Wrong

Option A monitors retained acknowledged messages, which does not isolate processing failures or trigger targeted failure alerts. Option C attempts to use Pub/Sub dead-letter topics, but Dataflow explicitly recommends against this due to architectural incompatibilities with its distributed execution model. Option D relies on snapshots, which are designed for state replay and debugging rather than real-time failure monitoring workflows.

Community Comment Notes

Community discussions heavily favor Option B, with users noting that explicit DoFn exception handling and side outputs effectively isolate failed messages for monitoring [1][4]. Several candidates questioned Option C until referencing official documentation that clarifies Pub/Sub dead-letter topics are unsupported with Dataflow pipelines [3]. The unanimous voting pattern confirms that examiners expect pipeline-level error management over external service configurations.

Official Reference

Exam Strategy

Always differentiate between platform-managed features and SDK-level implementations when questions combine multiple Google Cloud services. For Dataflow scenarios, default to pipeline-native constructs like side outputs and explicit error handling unless the documentation explicitly confirms cross-service integration.

Related Analysis

← Back to PDE Study Guide