Optimizing resources and costs
Professional Data Engineer · Lesson 20 of 23 · 2:30:59
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Google Cloud Professional Data Engineer exam, on the official exam guide. In this lesson: cost per business need with billing export, labels, budgets, and custom quotas, on-demand and capacity pricing in BigQuery, editions, baseline and autoscaling slots, reservations for business-critical work, and ephemeral or persistent Spark clusters, Dataflow autoscaling, and FlexRS. Includes three original practice questions, with Cymbal Mobility, a fictional ride-hailing and scooter company, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
A bill that doubled
Cymbal Mobility's data bill has doubled in a year. The nightly finance pipeline sometimes waits behind ad hoc queries, and a Spark cluster runs all week for a job of two hours. The data engineer must cut waste, while keeping enough capacity for the work that matters.
Cost per business need
Start from the business need: how fresh the data must be, how fast queries must answer, and how long data must be kept. A report read once a day does not need a streaming pipeline, and a monthly archive does not need hot storage. Measure before cutting: the billing export to BigQuery, labels on resources, and budgets with alerts show where the money goes. Then set guardrails: a dry run gives an estimate of the data that a query will process, and custom quotas cap the data processed each day, by project or by user.
BigQuery capacity models
BigQuery offers two compute models, and projects can mix them. On-demand pricing charges for the data that each query processes, with nothing to configure, which suits small or irregular workloads. Capacity-based pricing charges for slots, the virtual compute units of BigQuery, through reservations in one of three editions: Standard, Enterprise, and Enterprise Plus. A reservation can have baseline slots, always allocated, and autoscaling slots, added when needed, and commitments for one or three years lower the cost of steady workloads. Choose the edition by features: Standard has no baseline or BI Engine, Enterprise adds idle capacity sharing and BI Engine, and Enterprise Plus adds managed disaster recovery and compliance controls.
Reservations for critical work
Assignments connect a project, a folder, or the whole organization to a reservation, so separate reservations can serve pipelines, dashboards, and data science. Give the business-critical workload its own reservation, with enough baseline slots, so it never waits behind other jobs. Idle slots are shared with other reservations, and reclaimed in milliseconds when the owner needs them, while a reservation set to ignore idle slots no longer borrows any. Autoscaling covers peaks, up to a maximum that you set. And on-demand projects share a limit on concurrent slots, so critical work should not rely on them.
Right-sizing Spark and Dataflow
For Spark, a job-based, or ephemeral, cluster is created for a workflow, and deleted when its jobs finish, so it costs nothing between runs, with the data kept in Cloud Storage. A persistent cluster suits constant, interactive use, and scheduled deletion can remove it after an idle period. Autoscaling adds and removes workers, but delete an idle cluster rather than shrink it, since creating a cluster is as fast as resizing one. For Dataflow, horizontal autoscaling adjusts the number of workers, and a maximum number of workers caps the cost. And Flexible Resource Scheduling lowers the cost of batch jobs, by mixing preemptible and regular machines, with a start delayed by up to six hours.
Recap
Let's recap. Match cost to the business need, measure with billing export and labels, and cap usage with quotas. On-demand suits irregular use, and reservations suit steady work, in the Standard, Enterprise, or Enterprise Plus edition. Baseline slots and separate reservations protect critical workloads, and idle slots are shared. Ephemeral clusters cost nothing between runs, and idle clusters are deleted, not shrunk. And Dataflow caps workers, and Flexible Resource Scheduling lowers the cost of batch jobs.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
The marketing team runs a few unpredictable queries each week, and wants nothing to configure. The finance team runs heavy pipelines around the clock, with steady demand, and needs predictable costs. Which models fit?
- On-demand pricing for both teams
- A Standard edition reservation for both teams
- Marketing on-demand; finance on a committed reservation
- Marketing on a committed reservation; finance on-demand
Show the answer
Marketing on-demand; finance on a committed reservation
On-demand suits small, irregular use, and a reservation with baseline slots and a commitment makes steady costs predictable. “On-demand pricing for both teams” would leave finance with variable costs that follow every byte processed. “A Standard edition reservation for both teams” would make marketing pay for capacity it rarely uses. And “Marketing on a committed reservation; finance on-demand” reverses the two needs.
The finance pipeline must finish by six in the morning, but it sometimes waits for slots behind ad hoc queries, in the same reservation. What should the data engineer do?
- Give finance its own reservation, with baseline slots
- Run the finance queries with batch priority instead
- Add a dry run before each of the finance queries
- Set custom quotas on the finance project, per day
Show the answer
Give finance its own reservation, with baseline slots
A separate reservation, with enough baseline slots, guarantees capacity to the finance project. “Run the finance queries with batch priority instead” would make the pipeline wait even longer for free slots. “Add a dry run before each of the finance queries” only gives an estimate of the data processed, and frees no capacity. And “Set custom quotas on the finance project, per day” would cap the work of finance, not speed it up.
A nightly Spark job runs for two hours, on a cluster that stays on all week, and its data is in Cloud Storage. What should the data engineer do to cut costs?
- Enable autoscaling, down to two workers when idle
- Move the data onto the cluster’s own disks
- Add secondary workers to finish the job faster
- Create a cluster for each run, delete it afterward
Show the answer
Create a cluster for each run, delete it afterward
An ephemeral cluster exists only while the job runs, and the data stays in Cloud Storage. “Enable autoscaling, down to two workers when idle” would keep paying for a cluster that sits idle most of the week. “Move the data onto the cluster’s own disks” would tie the data to a cluster that should be temporary. And “Add secondary workers to finish the job faster” adds workers to the job, but leaves the idle hours untouched.