Brains4Cloud
ESEN
Practice

Topic 7 of 11

D2 · Planning and implementing a cloud solution

BigQuery, Pub/Sub, Dataflow, and Kafka

The other half of the exam guide's data products: the analytical warehouse (BigQuery), messaging (Pub/Sub and Google Cloud Managed Service for Apache Kafka), and stream processing (Dataflow). The exam guide also asks you to load data, including loading from Cloud Storage, and to maintain multi-region redundancy.

A fully managed, serverless data platform to manage and analyze data with SQL and Python, with no infrastructure. It queries terabytes in seconds and petabytes in minutes.

  • Separate storage and compute: each layer scales without affecting the other, thanks to Google's network.
  • Columnar storage optimized for analytical queries, with ACID transaction semantics.
  • Datasets are the top-level container for tables and views.
  • Query external data without loading it: external tables and federated queries over Cloud Storage, Bigtable, Spanner, or Google Sheets.
  • ANSI-standard SQL, BigQuery ML for models in SQL, BigQuery DataFrames (Python), notebooks in BigQuery Studio, and connections to Looker, Data Studio, Sheets, Tableau, or Power BI.
  • Interfaces: the console, the bq command-line tool, client libraries, REST and RPC APIs, and ODBC and JDBC drivers.

BigQuery locations and availability

Region

A specific place, such as London (europe-west2).

Multi-region

A large area, such as the United States (US) or Europe (EU). It can provide larger quotas.

A multi-region isn't cross-region redundancy

For either location type, BigQuery stores copies of your data in two zones within a single region. A multi-region doesn't add regional redundancy: data is stored in one region and compute is provided only there. For cross-region redundancy, BigQuery offers managed disaster recovery.

The location is chosen when you create the dataset and determines where data is stored and processed, as well as the price.

Loading data into BigQuery

MethodWhen
Batch loadLarge volumes from local files or Cloud Storage: Avro, Parquet, ORC, CSV, JSON, Datastore and Firestore exports. For scheduled or incremental loads, Google recommends BigQuery Data Transfer Service
StreamingNear real-time data: a BigQuery subscription in Pub/Sub or the Storage Write API
Change Data CaptureDatastream replicates row changes from a database to BigQuery
FederationQuery external data without loading it
# Load a CSV from Cloud Storage with a schema
bq load --source_format=CSV mydataset.mytable gs://mybucket/mydata.csv ./myschema.json

# Wildcards in the Cloud Storage URI
bq load --source_format=CSV --autodetect mydataset.mytable "gs://mybucket/fed-*/temp/*.csv"

Schema auto-detection doesn't detect headers if all columns are strings. Loading a local file also uses bq load.

BigQuery pricing models

On-demand (per TiB)

  • You pay for the data each query processes.
  • The first TiB processed each month is free.
  • Generally access to up to 2,000 concurrent slots shared by the project's queries.

Capacity (per slot-hour)

  • Used with BigQuery reservations.
  • Pay-as-you-go with autoscaling and optional one- or three-year commitments at a discount.

Storage is billed separately: the first 10 GiB each month are free, and tables or partitions not modified for 90 consecutive days move to cheaper long-term storage. Cost estimation is covered in domain D3.

An asynchronous, scalable messaging service that decouples services producing messages from services processing them, with typical latencies around 100 milliseconds. Publishers send messages to a topic and subscribers receive them through subscriptions.

Event ingestion

App or server events that Dataflow delivers to BigQuery, Bigtable, or Cloud Storage.

Real-time distribution

An enterprise event bus shared by several teams.

Replication between databases

Distributing a database's change events.

Parallel processing

Spreading tasks across many workers, for example resizing images.

  • It combines Kafka's horizontal scalability with middleware features such as dead-letter queues and filtering.
  • Per-message parallelism, not per partition: the number of concurrent clients isn't limited by partitions.
  • It is meant for service-to-service communication, not with mobile or IoT end clients.

Subscription types and delivery

TypeHow it works
PullThe subscriber client requests messages from the server
PushPub/Sub sends each message to the subscriber's HTTP endpoint (for example, Cloud Run)
ExportWrites messages straight to BigQuery, Cloud Storage, or Bigtable (the last in preview)
  • A subscription belongs to a single topic; a topic can have several. It only receives messages published after it was created.
  • The subscriber must acknowledge each message before the ackDeadline; otherwise it is redelivered.
  • Default: at-least-once delivery with no ordering. You can enable ordering by ordering key and exactly-once delivery. Subscribers should be idempotent.
  • Subscriptions expire after 31 days of inactivity unless you change the expiration policy.
  • Topic retention lets you seek back and replay messages already published.
gcloud pubsub topics create orders
gcloud pubsub subscriptions create orders-sub --topic=orders
gcloud pubsub topics publish orders --message="hello"
gcloud pubsub subscriptions pull orders-sub --auto-ack

Batch and streaming data processing with the same programming model. Pipelines read from one or more sources, transform the data, and write it to a destination.

  • Fully managed: it allocates a pool of worker VMs for each job and deletes them when it ends. It autoscales and rebalances work automatically.
  • Built on Apache Beam (Java, Python, and Go SDKs): the same pipeline can run on Flink or Spark without rewriting it.
  • Exactly-once processing by default; for streaming you can use at-least-once mode to cut cost and latency.
  • Ways to build pipelines: code with the Beam SDKs, templates (including Google's, no coding required), and JupyterLab notebooks.
  • Use cases: moving data, ETL into BigQuery, BI dashboard backends, real-time ML, processing logs and sensor data.
  • The console monitoring interface shows the pipeline graph and each stage's progress (job status is reviewed in domain D3).

Managed Service for Apache Kafka

A Google Cloud service to run secure, scalable open-source Apache Kafka clusters.

Sizing

You specify total vCPUs and memory; the service provisions brokers and rebalances partitions as you scale.

Tiered storage

Limited fast local disk plus cheap, effectively unlimited remote storage. You set each topic's retention.

Networking

Reachable from multiple VPCs, projects, and regions through Private Service Connect, with a single bootstrap URL.

Security

SASL authentication (with IAM identities) or mTLS, mandatory TLS, encryption at rest with Google keys or CMEK, automatic patching.

It doesn't allow unauthenticated or unencrypted connections. Authorization combines IAM (cluster management) and Kafka ACLs.

Pub/Sub or Kafka

Pub/SubManaged Service for Apache Kafka
ModelServerless, no cluster to sizeA Kafka cluster you size by vCPU and memory
ParallelismPer messagePer partition
WhenNative Google Cloud integration, events and streaming without managing infrastructureApplications and tools that already use the Kafka API

Exam scenarios

SituationAnswerWhy
Analyze petabytes with SQL without managing serversBigQueryA serverless data warehouse.
Load CSV files from a bucket into BigQuery every night on a scheduleBigQuery Data Transfer ServiceSchedules recurring load jobs.
Get a topic's events into BigQuery in near real timeBigQuery subscription in Pub/SubExports messages straight to a table.
Replicate changes from a MySQL database to BigQueryDatastream (CDC)Replicates row-level changes.
Decouple a service that produces orders from the one that processes themPub/SubAsynchronous messaging.
Transform and enrich an event stream before storing it in BigQueryDataflowBatch and streaming processing with Apache Beam.
Migrate applications that already use Apache Kafka clientsManaged Service for Apache KafkaManaged, compatible Kafka.
Predictable BigQuery query costs for a large teamCapacity pricing (slot reservations)Pay per slot-hour, with optional commitments.

Common exam traps

❓ Is a dataset in the US multi-region protected if a region fails?

No. Data is stored in two zones of a single region. For cross-region redundancy, use managed disaster recovery.

❓ Does a new subscription receive messages published before it was created?

No. Only later ones, unless you use topic retention and message replay.

❓ Does Pub/Sub guarantee ordering and exactly-once delivery by default?

No. The default is at-least-once with no ordering; both can be enabled.

❓ Do you manage VMs to run Dataflow?

No. Dataflow allocates the workers and deletes them when the job ends.

❓ Which SDK does Dataflow use?

Apache Beam, in Java, Python, or Go.

❓ When does a BigQuery table move to long-term storage?

When it isn't modified for 90 consecutive days.

Did you get this topic?

Test what you just learned

An app publishes millions of click events per hour. They must be cleaned, enriched with user data, and stored in BigQuery in near real time, without managing servers. Which architecture should you choose?

Ready to test "BigQuery, Pub/Sub, Dataflow, and Kafka"?

Original questions, each with a full explanation.

Start a mock exam