Cohort 4Register

Chapter One

What a Data Engineer Actually Does

Free to readPages 26 to 40 of 244, by Durgesh Yadav

There is a week every October when Flipkart's data platform stops behaving like a normal system. On an ordinary day it takes in roughly 300 terabytes. During Big Billion Days that climbs to about a petabyte a day.1 The traffic does not arrive politely. It arrives in a spike, on a date announced months in advance, watched by the entire company.

Somebody has to make sure that during that week the numbers still come out right. Not approximately right, and not right eventually — right by the morning meeting, every morning, while the volume is three times normal and half the pipelines are running behind. That work has a name, and this book is about how to do it.

You are not going to start at a petabyte a day. Almost nobody does. Your first pipeline will move a few hundred megabytes and it will break for reasons that have nothing to do with scale. What is worth knowing early is that the problems at both ends are the same problems. A file that arrived twice causes double-counted revenue whether the file is 4 MB or 4 TB. A source system that quietly changed a column name breaks a small pipeline exactly as thoroughly as a large one. Scale changes which tool you reach for. It does not change what you have to think about.

1.1The question the whole job is built around

Sooner or later, in an interview or on your first week at work, someone will ask you a version of this:

Walk me through what happens between a customer tapping Place Order and that order appearing as a number on a dashboard.

It sounds like a warm-up question. It is not. Almost everything a data engineer knows can be located somewhere on the path between those two events, and the way a candidate answers reveals within ninety seconds whether they have built systems or watched videos. People who have only studied tools answer with a list of tools. People who have built something answer with a path, and mention what could go wrong at each step.

By the end of this chapter you will be able to give a rough version of that answer. By the end of the book you will be able to give a good one.

To make the path concrete, this book follows one company from beginning to end. It is called ShopKart, it sells things online in India, and it does not exist. It is fictional on purpose: a real company’s internals are either confidential or out of date, and a made-up one lets us be specific without pretending to knowledge we do not have. Where ShopKart’s numbers matter, they are scaled down from figures that real Indian companies have published about themselves, and those real figures are cited so you can go and read them.

Here is what ShopKart looks like, in the shape of the questions a data engineer would ask on the first day:

QuestionShopKart
How many orders a day?About 1.2 million, rising sharply during festival sales
How many customers?22 million registered
What is the largest data source?Clickstream — app and web events, far larger than orders
Roughly how much new data a day?About 12 TB, of which orders are under 5 GB
Where does the data live now?Six different systems that do not talk to each other

Notice the fourth row, because it is the first thing that surprises people. The orders are the important data and they are nowhere near the big data. A million orders at two kilobytes each is a couple of gigabytes, which fits comfortably on a laptop. The volume is in behaviour: every scroll, search, filter, product view and abandoned cart. This matters because it decides your architecture. You size your systems for the biggest thing you must move, and you design your models around the most important thing you must get right, and those are usually two different datasets.

1.2What data is, precisely enough to be useful

A definition that is short enough to be worth memorising: data is a recorded fact about something at a moment in time.

Three parts of that sentence do work. A fact is about a subject — order 90412771. It records an attribute of that subject — the total amount. And it was true at a time — 21:14:52 on 17 March.

The third part is the one beginners drop, and dropping it causes more production incidents than anything else in this book. Data without a reliable time attached cannot be corrected, cannot be replayed after a failure, cannot be audited, and cannot settle an argument between two systems that disagree. When you eventually read about watermarks, late-arriving data, slowly changing dimensions and event-time processing, you are reading about five different consequences of that one idea.

Data arrives in three shapes, and the shape determines how much work happens before anyone can ask a question of it.

Structured data has a fixed schema that is known in advance. Rows and columns, every value in a column the same type. A database table is structured; so is a well-formed CSV. The structure is a promise, and the promise is what lets you write SUM(total_amount) without checking every row first.

Semi-structured data carries its structure inside itself but promises nothing about consistency. JSON is the common case:

JSON
{
  "order_id": 90412771,
  "customer": { "id": 5583201, "tier": "gold" },
  "items": [ { "sku": "SHO-4471", "qty": 1, "price": 3499.00 } ],
  "coupon": "RUNFAST20"
}

You can read that without a schema, because the keys are present. What you cannot do is assume tomorrow’s message will have the same keys. The coupon field will be missing when nobody used a coupon. Some upstream service will one day send "qty": "1" as a string, and your sum will fail or, worse, silently concatenate. Most data arriving from APIs and event streams looks like this, and a large part of the pipelines chapter is about surviving it.

Unstructured data has no queryable internal structure: product photographs, support-call recordings, review text, supplier invoices as PDFs. You cannot filter a JPEG. Before unstructured data can be analysed, something has to extract structure from it — image labels, a transcript, a sentiment score — and it is that extracted output, not the original, that enters your pipeline.

A useful rough rule is that most of what a company stores is unstructured, while most of what it analyses is structured, and a good deal of a data engineer’s work consists of moving things from the first category into the second.

1.3Why the application’s own database cannot answer the business’s questions

ShopKart already has a database. It has the orders in it. Why not simply query it and put the result on a dashboard?

This is the right question to ask, and working through the answer properly is the fastest way to understand why this entire profession exists. There are four reasons, and they arrive in roughly this order as a company grows.

The first is that you will hurt customers. The orders database exists to serve checkout. Its resources are budgeted for thousands of small, fast operations per second. An analytical query that scans three years of orders and groups them by city can consume enough CPU, memory and disk bandwidth that live checkouts start timing out. You will have traded a report for revenue, and you will not get a second chance to make that mistake.

The second is that the data is in the wrong shape. Application databases are designed to write small amounts of data quickly without duplicating anything. That design scatters information across many narrow tables. A question as ordinary as “revenue by product category, by city, by month” might require joining eight of them. Analytical systems store the same information in a shape built for exactly that kind of question, which is the subject of Chapter 5.

The third is that the answer is not in one system. ShopKart’s orders sit in PostgreSQL. Clicks are in an event stream. Payment settlements are in the payment provider’s API. Support tickets are in a third-party tool. Advertising spend is inside Google Ads. The question “did the Diwali campaign actually make money?” cannot be answered from any one of them, and answering it requires deciding what counts as the same customer across five systems that each identify people differently.

The fourth is that production databases forget. This one is subtle and it catches almost everyone. Application tables are usually mutable: when an order ships, the status column is overwritten from PLACED to SHIPPED, and the previous value is gone. Now ask “how many orders were still sitting in PLACED at 6 p.m. last Tuesday?” The production database cannot tell you, because it only knows the present. Preserving history is a deliberate design decision that someone has to make on purpose, and the person who makes it is you.

Figure 1.1: No single system holds the answer. Bringing five sources together, and deciding what counts as the same customer across all of them, is the work.
Figure 1.1.   No single system holds the answer. Bringing five sources together, and deciding what counts as the same customer across all of them, is the work. In the diagram: Orders Clicks Payments Tickets Ad spend Did the campaign make money?

1.4OLTP and OLAP: a physical difference, not a naming convention

The split described above has a formal name, and it is one of the highest-frequency interview topics in the field. A weak answer recites the acronyms. A strong answer explains why the two kinds of system are built differently at the level of bytes on disk.

OLTP, online transaction processing, describes systems that run the business one transaction at a time. Place an order, update an address, deduct stock. Enormous numbers of tiny operations, each touching a handful of rows, each expected to finish in milliseconds, each required to be exactly correct. PostgreSQL, MySQL, Oracle and SQL Server are built for this.

OLAP, online analytical processing, describes systems that analyse the business. Comparatively few queries, but each one reads millions or billions of rows across long stretches of history while touching only a few columns. Seconds or minutes are acceptable. Snowflake, BigQuery, Redshift and Databricks SQL are built for this.

The reason these cannot be the same system is physical. A row-oriented store keeps all the values of one row next to each other on disk, so fetching a complete order is a single read of one contiguous region. A column-oriented store keeps all the values of one column together, so summing total_amount across two billion orders reads only that column and never touches the other forty. Column storage also compresses dramatically better, because a column holds values of one type with heavy repetition; a city column across a million Indian orders contains a few thousand distinct strings, and that repetition compresses to a small fraction of its raw size.

Figure 1.2: The same four rows, laid out two ways. Row storage is fast at "give me this whole order". Column storage is fast at "sum this one column across everything".
Figure 1.2.   The same four rows, laid out two ways. Row storage is fast at "give me this whole order". Column storage is fast at "sum this one column across everything". In the diagram: Row store Column store order 1 all 40 columns order_id 1, 2, 3, 4 ... order 2 all 40 columns amount 3499, 1250, 899 ...

This is why the answer to “can’t we just add an index?” is no. An index helps when you want a small number of rows out of a large table. Analytical queries typically read a large fraction of the table, at which point the planner will often judge a full scan cheaper than the index, and you are still paying to read forty columns to use two.

OLTPOLAP
PurposeRun the businessUnderstand the business
Typical queryFetch or update one orderAggregate millions of orders
Rows touched1 to 100Millions to billions
Expected latencySingle-digit millisecondsSeconds to minutes
Storage layoutRow-orientedColumn-oriented
Table designNormalised, many narrow tablesDenormalised, fewer wide tables
WritesConstant, small, concurrentBulk loads on a schedule
HistoryUsually overwrittenDeliberately preserved
ExamplesPostgreSQL, MySQL, OracleSnowflake, BigQuery, Redshift

1.5The two clocks

The second great division in this field is not where data is processed but when.

Batch processing collects data over a period and processes it in one go. Every night at two o’clock, take yesterday’s orders, transform them, load them into the warehouse. It is simple to reason about, cheap because the compute runs and then stops, and straightforward to re-run when something goes wrong. It is the correct default for most analytics, and a majority of the pipelines you will build in your career will be batch.

Stream processing handles each event as it arrives. An order is placed and within a second the fraud model has scored it. Streaming is much harder to run. The system runs continuously, so it must survive restarts without losing its place; events arrive out of order, so “the last five minutes” is not a simple idea; and re-running yesterday is not a matter of re-executing a script.

Swiggy is a good illustration of why a company ends up needing both. A public write-up of its platform describes order volume swinging from around a hundred orders a minute to roughly fifteen thousand at lunch and dinner peaks, with real-time event streams funnelled through Kafka and then splitting into two paths: a low-latency path through Flink for anything needing sub-second response, and a lakehouse path for analytics.2 Confluent’s account of the same platform notes that the estimated delivery time shown when a customer opens the app is served from that streaming layer.3 The delivery estimate cannot wait for tonight’s batch job. The weekly report on which restaurants are underperforming can.

That is the decision rule, and it is worth writing down somewhere you will see it again:

Ask what decision changes if this data is five hours old instead of five minutes old. If nothing changes, streaming is a permanent operational cost buying you nothing.

Plenty of teams have built a streaming pipeline to feed a dashboard that one human looks at twice a day. The middle option, and the one most companies actually run, is micro-batch: small batches processed frequently, every minute or every thirty seconds. It gives most of the freshness of streaming with most of the simplicity of batch, and it is how Spark Structured Streaming works by default.

BatchStreaming
Triggered byA scheduleAn event arriving
FreshnessMinutes to hoursMilliseconds to seconds
Cost profileCompute runs, then stopsAlways on
Re-runningRun yesterday againRequires replay and state handling
SuitsReports, finance, ML training setsFraud, alerts, live estimates, personalisation

1.6The map

Here is the shape almost every data platform takes. Do not try to absorb the boxes; each one has a chapter later. What matters now is the direction of travel and the reason for each stage.

Figure 1.3: The canonical data platform. Every chapter after this one is a zoom into one of these zones.
Figure 1.3.   The canonical data platform. Every chapter after this one is a zoom into one of these zones. In the diagram: S O U R C E S apps, databases, APIs, files Application Vendor API Partner files I N G E S T get it out without hurting production CDC Event stream Scheduled pulls S T O R A G E keep everything, cheaply, unchanged Bronze Silver Gold P R O C E S S clean, join, aggregate Transformations Orchestration S E R V E where a decision gets made Dashboards ML features Data products

Read it as a sentence. Get the data out of the systems that created it, keep an untouched copy somewhere cheap, reshape it into something meaningful, put the result where it can be queried quickly, and hand it to whoever has to decide something.

Two of those stages deserve a word now because beginners routinely skip them.

Keep the raw copy. It is tempting to transform on the way in and store only the clean result. Six months from now you will find a bug in a transformation you wrote today. If the raw data still exists, you fix the code and reprocess. If it does not, that history is gone permanently. Object storage is cheap enough that this is rarely the right thing to economise on.

Separate ingestion from processing. When ingestion writes files and processing reads files, neither needs to know anything about the other’s schedule or health. If the processing cluster is down for two hours, ingestion keeps running and processing catches up. Systems that are wired directly together fail together.

This layering is not a theory. Swiggy’s platform is described as using a layered model over open formats specifically to standardise data and avoid silos,2 and the same pattern under the names bronze, silver and gold appears across the industry. Chapter 6 covers it properly.

1.7The work itself

Job descriptions describe an idealised version of this role. What follows is closer to what the weeks look like.

You will spend a large share of your time building pipelines — writing the code that extracts data from a source, reshapes it and lands it somewhere useful. Everyone imagines the job is this part, and it is a smaller fraction of it than you would think.

You will spend at least as much time repairing pipelines that used to work. A vendor changes a date format without telling anyone. A partner uploads yesterday’s file twice. A job that ran in twenty minutes now takes six hours because a marketing campaign doubled the volume. None of this appears on a syllabus and all of it happens every week.

You will spend real time deciding how tables should be structured so that questions are answerable and two people asking the same question get the same number. Chapter 5 is about this, and it is the work that most separates engineers who are trusted from engineers who are merely busy.

You will spend a surprising amount of time explaining why a number looks wrong. An analyst reports that revenue is down twelve per cent. Most of the time the pipeline is fine and the two of you are counting different things — their query includes cancelled orders and yours does not. Some of the time it is a real defect and you have a few hours to find it.

And you will spend the remainder on the things that surround engineering anywhere: reviews, documentation, access requests, controlling cloud spend, and explaining to a stakeholder why “just add one column” is a two-week piece of work because four dashboards depend on the current shape of that table.

1.8The neighbouring jobs

This comparison comes up in nearly every interview. The weak answer lists job titles. The strong answer says what each role owns and what each role takes on trust from someone else.

A data analyst asks questions of data and communicates the answers. They consume tables. You guarantee tables — that they exist, are fresh, are complete and did not quietly lose a day. When a table is missing yesterday’s rows, the analyst notices; you are the one whose phone rings.

A data scientist builds statistical and machine-learning models to predict or explain, and needs clean, historical, feature-rich data to do it. You supply it. The volume of preparation work involved is precisely why data platforms are built.

A machine learning engineer takes a model that works in a notebook and makes it work in production — serving it, monitoring it for drift, retraining it. There is real overlap with data engineering, since both care about pipelines and reproducibility, but the ML engineer’s deliverable is a functioning model and yours is trustworthy data. At a small company the same person often does both.

A software engineer builds the application that creates data in the first place. The deepest difference is not the technology but how failure behaves. When an application breaks it usually breaks loudly: requests error, users complain, alerts fire. When a data pipeline breaks it very often breaks silently. The job succeeds, the dashboard renders, the number is simply wrong, and nobody finds out for eleven days. Designing for silent failure is a distinct discipline, and it is why Chapter 12 exists.

Data engineerData analystData scientistML engineer
DeliverableReliable data systemsInsight and reportingModels and experimentsModels in production
Core questionIs the data there and correct?What does the data say?What will happen next?Does the model hold up at scale?
Main toolsSQL, Python, Spark, Airflow, cloudSQL, BI tools, spreadsheetsPython, statistics, ML librariesPython, serving infrastructure
Optimises forReliability, freshness, costClarity and speed of answerPredictive accuracyLatency and stability
Fails whenData is late, wrong or missingThe question is misreadThe model does not generaliseThe model degrades unnoticed

1.9The failure mode that defines the discipline

It is worth ending the first chapter on the thing that makes this job different from the jobs around it.

Consider what happens when a partner uploads the same file twice. Nothing errors. The ingestion job reads both files exactly as designed. The transformation runs and succeeds. The load into the warehouse succeeds. Every monitor is green, every job shows as completed, and yesterday’s revenue is exactly double what it should be. Somebody in finance may notice within a day. If the duplicated file is a smaller partner, nobody notices for a month, and by then it is in a report that has already been shown to the board.

Now consider the same class of problem in other forms. A join key that has duplicates on both sides, so a fact table quietly multiplies. A source that sends sixty per cent of its usual volume because an upstream service was degraded, producing a number that looks plausible. A timezone difference between two systems that shifts a day boundary by five and a half hours, so every daily total is a mixture of two days.

None of these throw an exception. All of them produce a dashboard that renders. This is why mature data teams monitor the data and not only the job, why pipelines are designed so that running them twice produces the same result as running them once, and why the phrase “the pipeline ran successfully” is not the same claim as “the numbers are right”. Every technique in Chapter 12 — freshness checks, row-count reconciliation, referential integrity tests, idempotent writes, quarantine tables — is a response to this single property of data systems.

Summary

  • Data is a recorded fact about a subject at a moment in time. The moment is the part beginners drop, and most of the hard machinery later in this book exists to handle it.
  • The application’s own database cannot serve analytics, for four separate reasons: it competes with customer traffic, the shape is wrong, the answer spans several systems, and it does not remember history.
  • OLTP and OLAP differ physically, in how bytes are laid out on disk. That is why an index does not rescue an analytical query.
  • Batch is the sensible default. Streaming is justified when a decision genuinely changes with freshness, and micro-batch covers most of the middle ground.
  • The platform’s direction is always the same: sources, ingestion, raw storage, processing, modelled tables, serving. Keep the raw copy, and keep ingestion decoupled from processing.
  • The failure mode that defines this discipline is the pipeline that succeeds while producing wrong data.

In the interview

What does a data engineer do?

SHORT ANSWER

I build and operate the systems that move data from where it is created — applications, databases, APIs, event streams — into a place where it can be analysed, in a modelled and trustworthy form. In practice that means ingestion, transformation, storage design, orchestration, and the quality checks and monitoring that keep it correct as the sources change.

DEEPER ANSWER

The constraint that makes it engineering rather than scripting is that everything upstream changes underneath you and nobody tells you. Schemas change, files arrive twice, an API starts rate-limiting, volume doubles after a campaign. So the work is designing for those conditions: jobs that can safely re-run, incremental loads that know where they stopped, validation that catches bad data before it reaches a dashboard, and alerting on data freshness rather than only on job crashes.

FOLLOW-UP: WHAT IS THE HARDEST PART?

Silent failure. A job that crashes is easy, because you get an alert. The dangerous case is a job that succeeds while producing wrong data — a join that duplicated rows, a source that sent partial volume, a timezone shift at a day boundary. That is why mature teams monitor the data itself, not just the pipeline.

SENIOR-LEVEL ANSWER

Frame it as owning a contract rather than a codebase. My deliverable is a set of guarantees about tables: this table is complete for day D by six in the morning, one row means exactly one order line, revenue reconciles to source within a defined tolerance, and late-arriving data is corrected within twenty-four hours. Every technical decision — incremental against full load, batch against streaming, how aggressively to partition — follows from which guarantee I have promised and what the business is willing to pay for it.

The other 12 chapters are in the free PDF

This is one of 3 chapters you can read here. The whole book is 244 pages and 15 chapters, and it is free: downloading the PDF takes one Google sign-in.

See all 15 chapters

Also free to read here: Chapter Three, SQL to Interview Level and Chapter Six, Where Data Lives.