Pipeline Operations: Advanced
The line spend should stay under
Spend and headcount both grow, and the number worth watching is their ratio. Track spend per data engineer every month. If the team grows 20% and spend grows 20%, each engineer's pipelines cost what they did a year ago. If spend grows 60% over the same year, new work is paying for old waste, and the gap compounds.
| Metric | Last October | This October | Growth |
|---|---|---|---|
| Data engineers | 40 | 48 | 20% |
| Monthly data spend | $100,000 | $160,000 | 60% |
| Spend per engineer | $2,500 | $3,333 | 33% |
Last October the team had 40 engineers and spent $100,000 a month on data. This October it has 50 engineers. What is the highest monthly spend that stays at or under the headcount-growth trend?
The 5 levers and their order
| Lever | Term it shrinks | Typical move | What can break |
|---|---|---|---|
| Stop doing it | The whole term | Retire tables and refreshes with no reads in 90 days | A hidden reader that lineage missed |
| Run less often | Runs per month | Hourly to daily where every reader looks daily | A reader with a real freshness SLA |
| Recompute less | Data per run | Full rebuild to incremental with a late-data window | Late rows outside the window |
| Scan less | Data per run | Partition filters, fewer columns, sampled dev data | A query that loses its partition filter |
| Pay less per unit | Price per unit | Right-sized clusters, cheaper compute for retryable batch | Slower runs that miss an SLA |
The monthly cost rhythm
- Week 1: RankCost-by-pipeline rollupPull spend by pipeline tag. List the top 10 by dollars and the top 10 by month-over-month growth.
- Week 2: AssignOwner teamsEach listed pipeline's owner team names 1 lever and an expected saving, or records why the spend is worth it.
- Week 3: ShipNormal review and CIMake 1 change at a time, so a number that regresses has 1 cause to look at.
- Week 4: VerifyAgainst the baselineCompare cost per run with the baseline, confirm last cycle's savings still hold, and plot spend per engineer.
Ranking by growth_usd puts a pipeline that jumped from $500 to $9,000 above a steady $20,000 one. The growth list catches new waste while its author still remembers why it exists. The dollar list catches the old giants nobody has questioned in a year, and a saving from last cycle that has crept back shows up in both.
A pipeline costs $18,000 a month. It rebuilds 4 years of order history every hour on a 32-node cluster. Its 3 consumers each read once a day, and 1 has had no queries in 120 days. Which change comes first?
| Environment | Data shape | Catches | Misses |
|---|---|---|---|
| Dev | A 1% key sample of prod, last 30 days, PII masked | Logic errors and wrong joins on realistic values | Skew, rare values, full-volume runtime |
| CI | Repo fixtures; slim CI builds only changed models, on small inputs | Regressions, contract breaks, edge cases someone wrote down | Any case nobody wrote a fixture for |
| Staging | Snapshot clone of prod at full volume | Runtime, memory, skew, migration behaviour | Data that lands after the snapshot |
| Prod | Live data | Everything, after consumers are exposed | Nothing |
Sampling dev data by key
Sampling each table at random breaks joins. Take 1% of orders and, separately, 1% of customers: only 1% of the sampled orders find their customer, so every dev join comes back nearly empty and looks like a bug. Sample by a shared key instead. Keep every row for customers in a fixed bucket, in every table that carries customer_id, and the same customers exist everywhere.
Bucket 7 is arbitrary. What matters is that dev.customers, dev.payments and every other table keyed on customer_id filter on mod(customer_id, 100) = 7. The email goes through hmac_sha256 with a key only prod can read. The same address always yields the same hash, so the column stays unique and joinable, and without the key nobody can hash a list of known emails to match it. A plain sha256 would let them.
A team builds dev by keeping 1% of rows from each table with an independent random filter. Their dev join of orders to customers returns around 1% of the sampled orders. What fixes it?
Staging at full volume
- Runs in seconds to minutes
- Shaped by fixtures or key sampling
- Answers: is the logic right?
- Cheap to rebuild nightly
- Same volume and distribution as prod
- Cloned from a prod snapshot
- Answers: will it run at scale?
- Pays a full run each release
- ▸Dev queries take 20 minutes: the slice is too large to iterate on.
- ▸Prod incidents are mostly skew or timeouts: staging is below full volume.
- ▸CI passes and prod fails on a null: no fixture has nulls in that column.
- ▸Staging costs as much as prod: it runs on a schedule instead of per release.
A change adds a join on merchant_id. In prod, 1 merchant accounts for 35% of transactions, and the new join runs out of memory on that key. Which environment is set up to catch this before release?
2 workloads, 2 models
The YAML never says what order to build in or which partitions to rewrite. The engine reads the order from depends_on, rewrites the last 3 partitions because of lookback_days, and can print a plan before it runs. The Python owns each of those decisions: the page loop, the stop condition, and delete_partition before insert so a rerun replaces the partition instead of doubling it.
Trade-offs of each model
- Plan before apply: the engine lists what will rebuild
- Drift detection when prod stops matching the code
- Build order inferred from references
- Reruns replace by default
- Control flow the format cannot express needs an escape hatch
- Any control flow: loops, retries, branches on runtime data
- Fits APIs, pagination, per-tenant fan-out, model training
- Debuggable line by line in a general-purpose language
- Idempotency, ordering and cleanup are the author's job
- No plan: the only preview is a run
| Workload | Fits | Why |
|---|---|---|
| Set-based SQL transforms in a curated layer | Declarative | Output is a function of inputs, so the engine can plan and order it |
| Ingesting a paginated API | Imperative | The stop condition depends on each response |
| Per-tenant jobs over a tenant list that changes daily | Either, with dynamic partitions on the declarative side | Fan-out depends on runtime data |
| Buckets, permissions, schedules | Declarative | Desired state is stable and drift matters |
| Training a model with early stopping | Imperative | Branches on intermediate results |
| A shared layer where 200 analysts add tables | Declarative | Reviewers read a diff of end states |
An ingestion node pulls from a partner API that returns 500 records per page with a next-page cursor, and it must stop when the cursor is empty. Which model fits the node?
A team builds 140 curated tables with a Python script that runs CREATE TABLE statements in a hand-kept order. Last month a new table was placed before its parent and read yesterday's data. Which change prevents this class of bug?
An ownership record tooling can read
- Owner team: a team, so the record survives people moving.
- On-call rotation: who gets paged. A team without one cannot own a tier 1 pipeline.
- Tier: 1 pages at night, 2 pages in working hours, 3 opens a ticket.
- Business sponsor: the person who can say the output is still worth its cost.
- Review-by date: yearly, the owner confirms or starts deprecation. A lapsed date flags the pipeline.
- Consumers: who to tell before a change. Lineage and query logs fill the gaps.
A tier 2 pipeline's owner team was dissolved last week. Its output has 2 registered consumers, and the larger one belongs to the growth team. What does the ownership model do?
Deprecation in 5 phases
| Phase | When | What happens | Exit condition |
|---|---|---|---|
| Phase 1: Announce | Week 1 | Find every reader from lineage and 90 days of query logs; publish the removal date and the replacement | Every reader notified by name |
| Phase 2: Freeze | Week 1 to deletion | No new consumers or columns; metadata marks the table deprecated | Freeze enforced in access rules |
| Phase 3: Migrate | Weeks 2 to 10 | Owner helps each reader move and tracks who remains | Remaining list empty or escalated |
| Phase 4: Brownout | Weeks 10 to 12 | Revoke read access for set windows: 1 hour, then 1 day | No new complaints in the last window |
| Phase 5: Delete | Week 13 | Stop the schedule, keep a final snapshot for the retention period, remove the code, drop the data | Schedule, code and storage gone |
Brownouts exist because some readers never see announcements. A 1-hour revocation on a Tuesday afternoon makes a hidden reader's job fail while the table still exists and restoring access takes a minute. Found during a brownout, a hidden reader costs an hour. Found after deletion, it costs a restore from the final snapshot, if the retention period has not run out.
- Name the replacement in the announcement, or say why there is none
- Count readers from query logs as well as lineage
- Brown out in growing windows before deleting
- Keep a final snapshot through the retention period
- Delete on the announced date while readers remain
- Record an individual as the owner
- Let a deprecated table pick up new consumers
- Skip the brownout because lineage shows no readers
The phase 1 query-log check found 4 readers. The rerun before brownout finds 5, and the fifth started reading in week 6. Which phase failed?
analytics.sessions_enriched builds user sessions from raw click events. At $40,000 a month it tops the cost rollup, and its spend grew 40% in 6 months while the team grew 10%. The owner team runs a cost pass in 3 stages: read lineage, pull the levers in order, and verify each change against the observability pillars before the next.
| Component | How it runs | Monthly cost |
|---|---|---|
| Transform | Full rebuild of 36 months, hourly: 720 runs at $40 | $28,800 |
| Consumer queries | Six readers query a 140-column unpartitioned table | $7,200 |
| Storage | Raw events for 36 months plus 30 kept copies of the output | $2,800 |
| Dev and CI | Full-volume clones rebuilt nightly | $1,200 |
| Total | $40,000 |
Stage 1: read lineage before changing anything
| Reader | Reads | Needs data by | Queries in 90 days, excluding auto-refresh |
|---|---|---|---|
| Exec revenue dashboard | Daily | 06:00 UTC | 2,100 |
| Marketing attribution job | Daily | 06:00 UTC | 90 |
| ML feature job | Daily | 05:00 UTC | 90 |
| Ops live dashboard | Hourly | Today, within 1 hour | 8,400 |
| Legacy funnel dashboard | Every 15 minutes | No SLA | 0 |
| Retention test dashboard | Every 15 minutes | No SLA | 0 |
Stage 2: pull the levers in order
| Lever | Change | Monthly total after |
|---|---|---|
| Stop doing it | Retire the 2 unread dashboards, saving $4,800 in queries; delete the 30 output copies, saving $1,200, since snapshots already keep 7 days | $34,000 |
| Run less often | Full build moves to daily at 04:00 UTC; a small hourly job writes only today's partition, at $1.50 a run | $7,480 |
| Recompute less | The daily build rewrites the last 3 days, the late-data window, instead of 36 months: $40 a run becomes $12 | $6,640 |
| Scan less | Output partitioned by event date; builds and readers select 22 of 140 columns; dev and CI use a 1% key sample | $4,020 |
| Pay less per unit | Cluster shrinks from 32 to 8 nodes; runs take longer but cost $8 daily and $0.75 hourly | $3,780 |
Another team copies this pass for a pipeline whose only reader is a fraud model that scores each payment within 2 minutes of the event. Which lever is ruled out by the reader's needs before any cost data is pulled?
After the pass: raw click events feed an hourly job that overwrites today's partition and a daily build that rewrites the last 3 days. Both publish through pillar checks into the partitioned table the 4 remaining readers query.
Stage 3: verify with the 5 pillars
Each lever shipped as a shadow build first: the new logic wrote analytics.sessions_enriched_v2 for 7 days beside the old table, and readers switched only after the comparison passed. A cost cut that changes the numbers is a data incident with a smaller bill.
| Pillar | What was checked | Pass condition |
|---|---|---|
| Freshness | Daily build finish time; lag of today's partition | Daily done by 04:30 UTC; today under 1 hour behind |
| Volume | Sessions per event date, old versus v2 | Exact match for days older than 3 days |
| Schema | Names and types of the 22 columns readers select | No change |
| Distribution | Median session length, null rate of `user_id`, sessions by country | Within 1% of the old table each day |
| Lineage | Query log on retired tables; reader job status | Zero reads of retired tables, zero reader failures |
On the last shadow day the query returned 2 rows, the 2 most recent days. That is expected: the old table rebuilt every hour and had already absorbed late events that v2 picks up at its next 04:00 run. A mismatch on any day older than 3 days would mean events arriving outside the late-data window, and the switch would have waited until the window was widened and the run cost recalculated.
The rollup shows sessions_enriched at $9,300 a month, 6 weeks after the switch. It ran 1,440 times last month, and each kind of run costs what it did after the pass. What happened, and where does it surface first?
> A food-delivery marketplace closes its annual plan: the data team grows from 30 to 36 engineers, and finance holds data spend growth to the same 20%. The cost rollup shows 3 pipelines carrying 45% of spend. The largest is a legacy order-events table whose owner team was folded into another group. A pricing notebook still reads it nightly, and a script rebuilds it in full every hour by running 60 statements in a hand-kept order.
Run pipelines for years: cut cost on a monthly rhythm, test in the right environment, and retire what nobody reads.
- Category
- Pipeline Architecture
- Difficulty
- advanced
- Duration
- 40 minutes
- Challenges
- 11 hands-on challenges
Topics covered: Cost Optimization as Ongoing Work, Environment Management, Declarative vs Imperative Pipeline, Deprecation and Ownership, Worked Example: 10x Cost Cut
Lesson Sections
- Cost Optimization as Ongoing Work (concepts: Pipeline Monitoring)
A pipeline's cost moves every month without anyone deciding to move it. Source tables grow, a new dashboard queries the output every 15 minutes, a backfill leaves a full copy behind, and a cluster sized for last year's peak keeps running at that size. A one-time cleanup removes this month's waste and leaves those forces in place, so cost work has to recur on a schedule. The line spend should stay under The 5 levers and their order A pipeline's monthly bill is runs per month, times data processed
- Environment Management (concepts: Environment Management)
Each environment exists to catch 1 class of failure, and only the failures its data can produce will show up there. A fixture of 12 hand-written rows catches a wrong join condition in seconds and can never show that 1 customer key holds 40% of the rows. A full copy of prod shows that skew and costs as much as prod to run. Choose each environment's data from the failure it is there to catch. Sampling dev data by key Staging at full volume Staging runs at prod volume because performance failures o
- Declarative vs Imperative Pipeline (concepts: DAG Orchestration)
Pipeline-as-code comes in 2 models. Imperative code lists the steps: fetch a page, loop until the cursor is empty, delete a partition, insert the rows. Declarative code describes the end state: this table equals this query, depends on those tables, and is fresh by 06:00. An engine compares the description with what exists and works out the steps. 2 workloads, 2 models Trade-offs of each model Many teams settle on a hybrid: a declarative graph of assets in which a few nodes are imperative functio
- Deprecation and Ownership (concepts: Pipeline Monitoring)
A pipeline without an owner keeps running and keeps costing, and nobody has the authority to change or stop it. Ownership by a named person ends the day that person changes teams. Assign each pipeline to a team, and record it where tooling can read it, so lineage, alert routing and the cost rollup all point at the same name. An ownership record tooling can read When a team dissolves, its pipelines move to the team that owns the largest consumer. With no consumer team to take them, they go to the
- Worked Example: 10x Cost Cut (concepts: Pipeline Monitoring)
Stage 1: read lineage before changing anything Of the 6 readers, 2 dashboards refresh every 15 minutes and have had no human queries in 90 days, and 3 readers look once a day. Only the ops dashboard needs data within the hour, and only for today. An hourly rebuild of 36 months exists to serve 1 reader's need for 1 day of data. Stage 2: pull the levers in order Run less often removed $26,520, the largest share, because no reader needed what hourly full rebuilds produced. Scan less shrank each dai