Event-Driven Data Ingestion to BigQuery with Cloud Run

ADP By islever Editorial Last updated

Short answer

C Create a Cloud Run function to load the data into BigQuery that is triggered when data arrives in Cloud Storage, providing low-latency, serverless ingestion with minimal maintenance.

Question

You are developing a data ingestion pipeline to load small CSV files into BigQuery from Cloud Storage. You want to load these files upon arrival to minimize data latency. You want to accomplish this with minimal cost and maintenance. What should you do?
  1. Use the bq command-line tool within a Cloud Shell instance to load the data into BigQuery.
  2. Create a Cloud Composer pipeline to load new files from Cloud Storage to BigQuery and schedule it to run every 10 minutes.
  3. Create a Cloud Run function to load the data into BigQuery that is triggered when data arrives in Cloud Storage. Correct Answer
  4. Create a Dataproc cluster to pull CSV files from Cloud Storage, process them using Spark, and write the results to BigQuery.

Key Takeaways

Using a Cloud Run function triggered by Cloud Storage events enables immediate, serverless ingestion of small CSV files into BigQuery, ensuring minimal latency and operational overhead compared to scheduled or cluster-based approaches.

Expert Analysis

C. BigQuery Storage Write API with default stream provides high-throughput streaming for batch loads of small files to BigQuery with exactly-once semantics.

To determine the optimal architecture for loading small CSV files from Cloud Storage into BigQuery upon arrival while minimizing cost and maintenance, we must evaluate the event-driven nature of the requirement against the operational overhead of each proposed solution. The core constraint is "upon arrival," which implies an event-driven trigger rather than a polling mechanism, and "minimal cost and maintenance" which strongly favors serverless or managed services that eliminate cluster management and complex orchestration logic.

Option C proposes using a Cloud Run function triggered by data arrival in Cloud Storage. This aligns perfectly with the event-driven paradigm. Google Cloud offers native integration where a Cloud Storage object creation event can automatically invoke a Cloud Run service. Inside this lightweight container, you can utilize the BigQuery Storage Write API (specifically the default stream) or the standard bq command-line tool within the container to ingest the data. This approach eliminates the need for a scheduler, reduces idle costs since resources scale to zero when not processing, and significantly lowers maintenance compared to managing virtual machines or clusters. It directly addresses the latency requirement by acting immediately on the storage event.

Option A suggests using the bq command-line tool within a Cloud Shell instance. While technically capable of performing the load, this is operationally unsound for automated ingestion. Cloud Shell is designed for interactive administrative tasks, not as a persistent, scalable execution environment for pipeline triggers. Implementing a mechanism to detect new files and then spin up or connect to Cloud Shell introduces significant complexity, security risks, and potential latency issues. It fails the "minimal maintenance" criterion because it requires custom scripting to manage state and authentication outside of a managed service context.

Option B recommends creating a Cloud Composer pipeline scheduled to run every 10 minutes. Cloud Composer is a powerful orchestration tool based on Apache Airflow, ideal for complex DAGs with dependencies. However, scheduling it to run periodically introduces inherent latency (up to 10 minutes) between file arrival and processing, violating the "minimize data latency" goal. Furthermore, maintaining a Composer environment involves managing Airflow metadata databases, workers, and web servers, which represents higher cost and operational burden than a simple serverless function for a straightforward ingest task.

Option D proposes using a Dataproc cluster. Dataproc is designed for large-scale data processing using Spark or Hadoop. For small CSV files, spinning up a Dataproc cluster incurs significant startup time and resource overhead. Even if optimized, the cost per job for small data volumes is disproportionately high compared to serverless alternatives. Additionally, managing cluster lifecycle policies adds maintenance complexity. Dataproc is overkill for simple ingestion and does not natively support event-driven triggers without additional infrastructure like Pub/Sub and complex worker configurations, increasing both cost and maintenance.

The reference explanation highlights that the BigQuery Storage Write API with the default stream is suitable for high-throughput streaming of small files with exactly-once semantics. By leveraging Cloud Run as the trigger mechanism, you combine the low-latency, cost-effective, and low-maintenance benefits of serverless compute with the robust ingestion capabilities of BigQuery's modern write APIs. This combination ensures that each file is processed immediately upon upload, with no idle resources and minimal operational overhead.

Official Reference

Exam Strategy

When evaluating data ingestion architectures, prioritize serverless, event-driven patterns (like Cloud Run + Cloud Storage triggers) for small-to-medium datasets requiring low latency. Avoid orchestrators like Cloud Composer or clusters like Dataproc for simple, frequent ingestions unless complex dependency management is required, as their setup costs and scaling latencies often outweigh benefits for straightforward tasks.

Practice All ADP Questions

Access 65 questions with complete answers and detailed explanations.

View Full ADP Practice Test →

← Back to ADP Study Guide