The data lifecycle

Part of the free LogicWiz Data Engineering course, Module 1: The job and the map. The SQL and Python run in the app, on real Postgres and real Python in the browser.

It is 9:00 on Tuesday. Tess has added up 2 June in her own spreadsheet: $558.24. Your revenue table says $415.80. The gap is $142.44, to the cent the price of one order. Nora says: "Follow that order from Dana's database to the dashboard." And Tess has a second question: could the dashboard update every five minutes instead of once a night?

You'll learn to

  • Follow one order through source, ingest, store, transform and serve
  • Explain ELT, the medallion layers, lambda and kappa in plain words
  • Put a price on a refresh interval before you promise it
  • Name the four questions that run under every stage

Learn

Follow one order

The order is number 1012. On 2 June at 21:31, Freya Larsen in Oslo checks out a basket worth $142.44.

Her card is declined. Six minutes later she pays with her wallet instead, and that works. The order ships the next day.

One customer, one order, one payment that went through. Start where the data is born: Dana's database.

Order 1012, as the source stores it

SELECT o.order_id, o.status, p.method, p.status AS payment_status, p.amount
FROM orders o
JOIN payments p ON p.order_id = o.order_id
WHERE o.order_id = 1012;

Two payment rows of $142.44 for one order: a failed card, then a captured wallet. Add both and you get Tess's extra $142.44. Knowing quirks like this is part of working with a source you do not own.

Five stages between Dana and Tess

Every piece of data at SwiftKart makes the same trip, in five stages.

It is born in a system built for something else: here, the database that runs checkout. That is the source. A job copies it out: ingest. The copy is kept somewhere cheap and safe: store. It is cleaned, joined and added up: transform. And the result is handed to people and programs: serve.

Together the five stages are called the data lifecycle. Tap each box on the map to see what happens there and which tools do it.

The data lifecycle

The data lifecycle from left to right: source, ingest, store, transform and serve, with quality, orchestration, security and cost running underneath every stage.

Tap a stage to see what happens there, SwiftKart's example and the common tools. Leave the dashed band at the bottom for now: it comes back at the end of the lesson.

The five stages at SwiftKart

StageWhat happensAt SwiftKartTools you will hear
SourceData is born in systems built for something elseThe store's Postgres database, the payment provider, app eventsPostgres, MySQL, SaaS APIs, Kafka
IngestCopy it out, without hurting the sourceA nightly export of orders to data/orders.csvAzure Data Factory, Fivetran, Airbyte, Debezium, Python
StoreKeep it cheaply and safely: files in a lake or tables in a warehouseParquet files in cloud storageS3, ADLS, Delta Lake, Iceberg, Snowflake, BigQuery
TransformClean, join, deduplicate, add upDaily revenue from captured paymentsSQL, dbt, Spark, Databricks
ServeGive the result to people and programsThe finance dashboard, features for a modelPower BI, Tableau, Looker, APIs

Ingest copies. Transform changes. Keeping the two apart is what lets you rerun a transform next week without asking the source for the data again.

Never point heavy reports at the source database. A big report on the store's live Postgres competes with checkout: customers wait while finance gets its numbers. That is why the ingest stage exists. Copy the data out once (an export, or change data capture from the write-ahead log, Module 6), then query the copy as much as you like.

Stages 2 to 5 in one small program

import duckdb

# Ingest: read the raw export exactly as it arrived
duckdb.sql("CREATE TABLE raw_payments AS SELECT * FROM read_json_auto('data/payments.jsonl')")

# Store: keep a copy as a Parquet file
duckdb.sql("COPY raw_payments TO 'payments.parquet' (FORMAT PARQUET)")

# Transform: captured payments only, summed per day
daily = duckdb.sql("""
    SELECT CAST(paid_ts AS DATE) AS day, ROUND(SUM(amount), 2) AS revenue
    FROM 'payments.parquet'
    WHERE status = 'captured'
    GROUP BY day
    ORDER BY day
""").fetchall()

# Serve: hand the result over (here, print the first three days)
for day, revenue in daily[:3]:
    print(day, revenue)

In a company each stage is a separate job, often on a separate tool. The shape is the same. Look at the second line of output: 2 June is $415.80, not Tess's $558.24. Step through the next picture to see where order 1012 went.

Order 1012, from checkout to dashboard

Order 1012 moves through the five stages: two payment rows in the source, both copied out by ingest, both kept in the stored file, only the captured one counted by the transform, and 415.80 dollars served for 2 June.

  1. Source. Freya's card is declined at 21:33 and her wallet payment goes through at 21:39. The store's database keeps both rows, because the app needs both.

  2. Ingest. The nightly export copies every payment out exactly as it is: 85 rows, the failed one included. Nothing is cleaned yet.

  3. Store. The raw copy is kept as a Parquet file, a compact file format for tables (Module 4). It is cheap, and it means you never have to ask Dana for June again.

  4. Transform. Now the data changes. Keep only captured payments, 70 of the 85, and add them up per day. The failed card drops out, and 2 June comes to $415.80.

  5. Serve. The dashboard shows $415.80 for 2 June. Tess's spreadsheet skipped the filter and added the failed card too: $415.80 + $142.44 = $558.24.

Read it top to bottom. The blue box is where the order is now; the boxes above it show what each earlier stage left behind.

Copy first, change later

Tess's mistake sat in the transform, not in the data. The fix costs one line, WHERE status = 'captured', and a rerun. Nobody has to ask Dana for June again, because the raw copy is still there.

That order of work has a name. Load the raw data first, then transform it inside the place where it is stored: ELT (extract, load, transform). The older way, ETL, cleans the data on a separate server and loads only the result.

Cheap storage made ELT the default. Raw tables loaded into a warehouse such as Snowflake or BigQuery, then modelled with SQL, is the simplest design that scales. ETL still fits when personal data must be masked before it is stored at all.

Remember: ingest copies, transform changes. Keep the raw copy, and a wrong transform is a rerun, not a rescue.

Raw, clean, ready: three layers

Where does the raw copy live next to the clean one? Many teams keep three layers of the same data, each better than the last. Databricks named them like medals, so the pattern is called medallion.

Bronze is the data as it landed: nothing removed, rows only added, each with a note of which file it came from and when. Silver is cleaned, typed and deduplicated. Gold holds the tables people read, such as daily_revenue.

The layers describe quality, not a way to design tables: gold can be a star schema (Module 5). The gain is replay: any silver or gold table can be rebuilt from bronze. The price is three copies to store and more jobs to run.

SwiftKart's orders through the three layers

Five steps from left to right: the store database, bronze raw rows with load metadata, silver deduplicated typed orders, gold daily revenue, and the finance dashboard.

Read it left to right: the data gets cleaner at every arrow, and nothing to the left is thrown away. This layout is usual on a lakehouse: tables kept as files in cloud storage, in a format such as Delta Lake or Iceberg (Module 4).

Could it refresh every five minutes?

Now Tess's second question. Today the pipeline is a batch job: it runs on a schedule, once a night, so the dashboard shows data up to a day old.

The other way is streaming: handle each event within seconds of it happening. A fraud check needs that. So does live stock.

Streaming is not a faster batch, though. Events arrive late, out of order or twice, and something runs, and costs, all day. So the first question is never "how fast can it be?" It is "which decision needs data that fresh?"

Batch or streaming

BatchStreaming
Processes data on a schedule: nightly, hourlyProcesses each event within seconds
Simple to rerun, test and backfillLate, out-of-order and duplicate events; state to manage
Pays for compute only while it runsSomething runs, and costs, all day
Daily revenue, weekly reports, nightly model trainingFraud checks, live stock, delivery tracking

Two designs that reach seconds

Suppose finance really did need seconds. Two classic designs get there.

Lambda, from Nathan Marz, runs two paths over the same events. A batch layer recomputes everything from the full history: slow and exact. A speed layer streams the last few hours: fast. A serving layer merges the two. The catch: the same logic now lives in two codebases, and they drift apart.

Kappa, from Jay Kreps, keeps one streaming path over a log of events you can replay, such as Kafka. To fix a bug you start version 2 of the job from the earliest event the log still holds (its earliest retained offset), write a new table, and switch readers when it catches up.

Lambda against kappa, on one event log

Store events flow into a Kafka log. In lambda, a batch layer and a speed layer both read it and a serving layer merges their views. In kappa, one stream job writes the table, and a second version replays the log from the start into a new table that readers switch to.

Follow the violet boxes for lambda: two paths that must agree. Follow the teal boxes for kappa: one path, and a dashed replay when the logic changes. On a lakehouse, kappa shows up as streaming jobs that write Delta tables, with bronze as the log you replay.

Fresh data has a price

Speed is never free, so put a number on it before you promise it. Say the dashboard's query scans 200 GiB on BigQuery, a cloud warehouse that bills on demand: $6.25 for every TiB a query scans.

  • 200 GiB ÷ 1,024 = 0.195 TiB
  • One run: 0.195 × $6.25 = $1.22
  • Once a day for 30 days: $36.62 a month

Now run the same query every 5 minutes. That is 288 runs a day.

One 200 GiB query on BigQuery, per month

Bars show the monthly cost of refreshing one 200 GiB query: 36.62 dollars daily, 878.91 hourly, 3,515.63 every 15 minutes and 10,546.88 every 5 minutes.

Each bar is $6.25 per TiB over 30 days, ignoring the free first TiB and the result cache (an unchanged query read again from the cache is not billed). Partitioning and clustering cut the bytes scanned, often by far more than any change of refresh interval.

Four designs side by side

DesignHow freshWhat it costsFits when
ELT on a warehouseminutes to a day, on a schedulecompute per query or per warehouse-secondmost analytics; SQL teams; data fits one warehouse
Medallion lakehouseminutes (streaming) to a daythree copies of storage, more jobsmany sources, SQL and ML on one copy, replay from bronze
Lambdaseconds, corrected by batchtwo codebases that must agreelow latency and exact recomputation are both required
Kappasecondslong log retention; replays reprocess everythingevent-first systems on Kafka with one code path

Start with the simplest design that meets the freshness target. Each row further down adds a system that must be run, watched and paid for all day. Many teams with a five-minute need end up with one streaming job into silver and a scheduled batch for gold, not a full lambda.

Four questions under every stage

Before you answer Tess, Nora points at the dashed band under the map. "Those four never stop," she says.

Under every stage, someone has to ask: is the data right (quality)? What runs when, and what happens when it fails (orchestration)? Who may see what (security)? What does each run cost (cost)? Together they are called the undercurrents of the lifecycle.

You have met two of them this morning. The missing captured filter was a quality problem. The five-minute refresh is a cost problem.

The undercurrents at SwiftKart

UndercurrentThe question it asksAt SwiftKart
QualityIs the data complete, correct and fresh?SLIs after every load; one captured payment per order
OrchestrationWhat runs when, in what order, and what happens on failure?Transform only after the 02:00 export lands; retry, then page
SecurityWho may see what?Analysts see revenue, not customer emails; no secrets in code
CostWhat does each run cost, and is it worth it?Read yesterday's file each night, not all of June again

These run underneath all five stages, which is why the map draws them as a band along the bottom.

Numbers to remember

WhatNumberGood to know
A nightly batchdata up to about a day oldan hourly batch: about an hour old
Spark Structured Streaming, micro-batchend-to-end latency "as low as 100 milliseconds"with exactly-once guarantees, per the Spark documentation
Spark Structured Streaming, continuous modeabout 1 mswith at-least-once guarantees
BigQuery on-demand$6.25 per TiB scannedthe first TiB each month is free
Snowflake, X-Small warehouse1 credit an houreach size up doubles it; billed per second, with a 60-second minimum each time it starts
Snowflake, Medium warehouse4 credits an hourif it never suspends: 96 credits a day
KappaJay Kreps, "Questioning the Lambda Architecture", 2014lambda came earlier, from Nathan Marz

What changed at SwiftKart

Tess gets two answers before lunch.

First, the $142.44. Her spreadsheet counted a declined card as money. Your table keeps only captured payments, so 2 June is $415.80, and you can show her order 1012 at every stage to prove it.

Second, the five minutes. The nightly batch is ready at 06:00 and finance reads it at 9. It already keeps its promise, for about $37 a month instead of $10,500. Tess withdraws the request.

You now have the map. The next lesson is about the people on it: who owns which part, what "senior" means, and what an interview loop for this job tests.

In one line

Data travels source, ingest, store, transform, serve: copy it raw first and change it later, add speed only when a decision needs it, and price every refresh before you promise it.

Interview corner

Compare lambda and kappa architectures. Which would you choose today?

Lambda runs a batch layer that recomputes from full history and a speed layer that streams recent data, merged at serving time: exact and fast, but two codebases that drift. Kappa keeps one streaming path over a replayable log and reprocesses by replaying from the earliest offset into a new table. Today I would rarely build lambda: either the SLO allows scheduled batch (much cheaper), or I stream into a lakehouse table with one code path and rebuild from bronze or the log when logic changes, which is kappa in practice.

Finance wants the dashboard every 5 minutes instead of daily. How do you respond?

I ask which decision needs five-minute data, then price it. A 200 GiB query on BigQuery on-demand at $6.25 per TiB is $1.22 a run: $36.62 a month daily and $10,546.88 a month every 5 minutes. Usually I cut bytes first (partition and cluster the table, pre-aggregate into a small gold table, let the result cache work) and stream only the few metrics that need it into a small table. The answer is an SLO and a cost, not "yes" or "no".

What is the medallion architecture, and is it a data model?

It is a layering of a lakehouse by quality: bronze holds raw data as it landed, append-only, with load metadata; silver is cleaned, typed, deduplicated and conformed; gold holds the business tables. It is not a data model: gold can be a star schema or wide tables. Its value is replay, because any silver or gold table can be rebuilt from bronze; its cost is three copies of storage and more jobs, so I do not create layers that add nothing.