0% read
    ← All stories
    A Story for Data Engineers  ·  blog.niluniverse.com

    The Magician of Mahadata

    How a magician named Apache Spark learned to move mountains of data — and how a gurukul called Databricks made him unstoppable.

    ↓   B E G I N
    Chapter One

    The Village That Drowned in Its Own Ledgers

    There was once a village called Mahadata. It was a happy village. Every shop, every bullock cart, every phone call, every click — all of it was written down in big fat ledgers and kept safely in the village godown.

    In the beginning, one accountant was enough. His name was Single Machine. He was a good man, very sincere. Every night he would sit with one lamp, open one ledger, and add up the day's numbers. By morning, the report was ready. The village was happy.

    But the village grew. Then it grew again. Then it grew in a way nobody had planned for. Ledgers became a hundred. A hundred became a lakh. Soon the godown was so full that the doors would not close.

    Poor Single Machine kept sitting with his one lamp. He was not lazy — he was simply one. He could read only one page at a time. By the time he finished the morning report, it was already evening, and one more day of data was waiting outside the door, tapping its foot.

    "Give me a bigger table, a bigger lamp, a bigger chair," Single Machine begged.
    The village elders gave him all three. He was still one man. — The problem nobody could buy their way out of

    This is the first truth of our story, and please remember it, because everything else grows from here: when data grows faster than one machine can grow, you cannot go bigger. You have to go wider.

    Not one accountant with a bigger table. Many accountants, each with a small table, all working at the same time.

    Try it yourself. Below is the village godown. Move the slider and give Single Machine some company.

    Living Diagram 01

    One lamp, or many hands?

    HANDS 1 worker
    What you are seeing: 96 ledgers (data blocks) must be totalled. Each worker picks up one ledger at a time. Add workers and the same mountain finishes sooner — not because anyone became faster, but because the work got divided. This one idea is the foundation of every big data engine ever built. In Spark's language, each ledger is a partition and each worker is a core inside an executor.
    Chapter Two

    The Old Sage Who Wrote Everything Down

    The village found its first saviour in an old sage named MapReduce. He was, let me say clearly, a great man. He was the first person who taught Mahadata how to divide work across many hands. Whatever came after him stands on his shoulders. Never forget that.

    The sage's method was simple and very disciplined. He would take the mountain of ledgers, split them among many workers — this he called Map. Then he would collect all the small answers and add them into one big answer — this he called Reduce.

    It worked. The village was saved. But the sage had one habit, born of an old fear.

    After every single step, he wrote the answer back into the godown.

    Finished the Map? Write it to disk. Starting the Reduce? Read it back from disk. Second round of work? Write to disk again, read again. Every step, a trip to the godown and back.

    Why? Because the sage had seen workers fall sick and die in the middle of a job. If everything is written down on paper, nothing is ever lost. It was a very wise fear. It was also a very expensive habit.

    Why disk hurts so much: reading from memory (RAM) is like taking a book from the table in front of you. Reading from disk is like sending a boy on a cycle to the godown, two kilometres away. Even a fast cycle is no match for your own hand. In real numbers, memory is roughly a hundred times quicker than disk — and machine learning or interactive queries want the same data ten, twenty, fifty times in a row.

    So a job that needed ten steps made twenty trips to the godown. The workers spent more time cycling than counting. And the village — which now wanted answers in seconds, not overnight — began to grow restless again.

    Watch the two methods run the same ten-step job.

    Living Diagram 02

    The godown trip: disk at every step vs. keep it in hand

    Sage MapReduce: ready Magician Spark: ready
    What you are seeing: the same ten-stage job. The sage completes a stage, then makes the long trip to disk and back before the next stage may begin. The magician keeps the working data in memory and simply carries on. Nothing about the counting got faster — only the fetching. For iterative work like training a model, this single change was worth 10x to 100x.
    ✦ ✦ ✦
    Chapter Three

    Entry of the Magician

    He did not arrive on a chariot. He arrived from a university laboratory in Berkeley, in the year 2009, as a small research project with a strange promise: let the data stay in memory, and let the machines remember how it was made.

    The village called him Apache Spark.

    He was not a bigger accountant. He was not a faster cycle. He was something the village had not seen before — a magician who could stand in one place and command a thousand hands at once, and who never, ever forgot the steps of his own spell.

    The elders tested him, of course. They gave him the sage's hardest job and asked him to sort a mountain of records. He finished it in a fraction of the time, using a fraction of the machines. The village stopped arguing.

    But the elders asked the correct question, the question you should always ask when someone claims magic:

    "Bhai, where exactly does the superpower come from?" — The only question that matters

    The magician smiled and said: "I have four powers. Let me show you each one, one by one. There is no magic. There is only good design."

    Power One — I break the mountain before I lift it

    The magician never looks at a mountain and thinks "mountain". He looks at it and immediately sees partitions — hundreds of small, bite-sized pieces, each one small enough to fit comfortably in a worker's hands.

    Then he sends those pieces out to his workers, who are called executors. Each executor is a separate machine (or a separate slice of one) with its own memory and its own hands, sitting in a big hall called the cluster.

    The magician himself does not do the counting. He sits in the middle as the driver — the one who holds the plan, decides who does what, and collects the final answer. A good general does not fight; he directs.

    Remember the shape: One driver (the brain, holds the plan) → many executors (the hands, hold data and do work) → each executor has several cores (each core handles one partition at a time). Get this picture right and 80% of Spark stops feeling mysterious.

    Below, the magician is dividing a job. Change how finely he breaks the mountain and see what happens.

    Living Diagram 03

    Driver, executors, partitions — the magician's formation

    EXECUTORS 4
    PARTITIONS 24
    Play with it: Too few partitions and some executors sit idle with nothing to do — you paid for hands you did not use. Too many tiny partitions and the magician wastes his breath just giving instructions (scheduling overhead). The sweet spot is roughly 2 to 4 partitions per available core. This is the single most common reason a Spark job is slow, and it is not a mystery — it is arithmetic.

    Power Two — I remember the recipe, not just the dish

    This is the power that made everyone fall silent.

    When a worker fell sick in the sage's time, the whole job had to be restarted, or the sage had to go dig up the last paper he had written. That is why he wrote so much paper.

    The magician does something cleverer. He does not save copies of the data everywhere. Instead, he remembers exactly how every piece of data was made — which file it came from, which filter was applied, which column was added, in which order.

    This memory of steps is called lineage, and the picture it forms is called a DAG — a Directed Acyclic Graph. Say it simply: an arrow-diagram of steps that never goes backwards in a circle.

    So when a worker collapses and a piece of data is lost, the magician does not panic and does not restart everything. He looks at his DAG, finds the one branch that was destroyed, and recreates only that branch. Two seconds of work instead of two hours.

    Do not preserve the sweet. Preserve the recipe.
    Then any sweet can be made again, whenever you need it. — The heart of Spark's fault tolerance

    Try to break him. Click on any node in the tree below and destroy it.

    Living Diagram 04

    The lineage tree — click a node to destroy it

    Click any glowing node to destroy that piece of data
    What you are seeing: a real lineage graph — read a file, filter it, add a column, group it, and write the result. Destroy any node and Spark walks backwards along the arrows to the nearest surviving ancestor, then recomputes forward. It never needs a backup copy, because the recipe is the backup. This is why Spark can run happily on cheap, ordinary machines that fail all the time.

    Power Three — I listen to your whole wish before I lift a finger

    Now, the power that most people find strange the first time.

    You go to the magician and say: "Read this file." He nods. Nothing happens.

    You say: "Now filter only Maharashtra rows." He nods again. Still nothing happens.

    "Now add a column. Now join with this other table. Now group by district." He keeps nodding. Still nothing happens. You start getting irritated. Is this fellow even working?

    Then you finally say: "Now show me the answer." And in that instant — everything happens, all at once, beautifully.

    This is called lazy evaluation, and it is not laziness at all. It is patience with a purpose.

    Think of a tailor. If you tell him "cut the cloth" and he cuts immediately, then you say "actually make it smaller", the cloth is already wasted. A wise tailor listens to your full requirement, measures everything, plans every cut on the whole cloth, and only then picks up the scissors — once, correctly.

    In Spark's vocabulary: the instructions you give are transformations (lazy — they only add to the plan). The moment you ask for a result, that is an action (eager — it triggers the whole thing).

    Transformations (lazy, nothing runs): filter, select, withColumn, join, groupBy, map
    Actions (eager, everything runs): show, count, collect, write, take

    Give the magician some instructions and watch him do absolutely nothing about them.

    Living Diagram 05

    The patient magician — stack up spells, then cast

    What you are seeing: every transformation you add just gets written into the plan — notice the CPU stays completely idle. Only the action wakes the cluster. And because Spark saw the whole wish before starting, it could rearrange it into something smarter first. Which brings us to the magician's wisest advisor…

    Power Four — My minister rewrites my orders, and I let him

    Beside the magician sits a quiet, brilliant minister named Catalyst.

    When you hand over your wish, Catalyst does not run it. He first improves it — and he does this without ever changing your answer. Only the route changes, never the destination.

    His three favourite corrections are so simple you will laugh, and so powerful you will not:

    One — filter first, carry less. You wrote: "load the whole ten-crore-row table, join it with another table, then keep only Pune." Catalyst rewrites it to: "keep only Pune first, then join." Same answer. You just carried a suitcase instead of a truck. This is called predicate pushdown.

    Two — carry only what you asked for. Your table has 200 columns; your report needs 4. Catalyst reads only those 4 from the disk. In a columnar file format like Parquet or Delta, this is not a trick — the columns really are stored separately. This is column pruning.

    Three — if one side is small, don't move the big one. Joining ten crore sales rows with a 200-row list of city names? Do not drag the sales data across the network. Send the tiny city list to every machine instead. This is a broadcast join, and it turns hours into minutes.

    And there is one more thing, added later, which is genuinely the cleverest part: Adaptive Query Execution (AQE). Catalyst makes his plan, but then he watches the job while it runs. If the real data turns out different from what he assumed — one district has ten times more rows than expected — he changes the plan mid-flight. Very few planners in this world have the humility to do that.

    Living Diagram 06

    Catalyst rewrites your query in front of your eyes

    Rows carried: —
    What you are seeing: the same query as you wrote it (left) and as Catalyst decided to actually run it (right). Notice the filter climbing down towards the source and the small table turning into a broadcast. You did not write better code. Spark simply refused to run your code literally — and that is a feature.

    The one weakness — the river he must cross

    Every hero must have a weakness, otherwise the story is boring and, more importantly, untrue.

    The magician's workers are fast because each one works alone on its own piece. But some questions cannot be answered alone. "How many sales in each district?" — for that, every record of Pune must come together in one place, no matter which worker was holding it.

    So the data must cross the hall. Records fly from every machine to every other machine, over the network, through the disk. This crossing is called the shuffle, and it is the slowest, heaviest, most expensive thing Spark ever does.

    You cannot remove the shuffle — groupBy, join, distinct, orderBy all need it. But a good engineer learns to respect it: filter before you shuffle, broadcast the small side, and never shuffle the same data twice when you could cache it once.

    Living Diagram 07

    The shuffle — when every worker must talk to every worker

    Records crossing the network: —
    Compare the two buttons. Same final answer, hugely different amount of traffic. Filtering before a shuffle is the cheapest performance win in all of data engineering, and it costs you one line of code moved up.
    ✦ ✦ ✦
    Chapter Four

    The Gurukul That Raised Him

    Now, a magician alone in a forest is only a story. A magician with a school, a discipline and a stage becomes a civilisation.

    The same people who created Spark in that Berkeley lab — Matei Zaharia and his colleagues — did something unusual. They gave Spark away, free, to the whole world through the Apache Foundation. Then, in 2013, they founded a gurukul to raise him properly.

    That gurukul is Databricks.

    People often confuse the two, so let us settle it in one line, once and for all:

    Apache Spark is the engine — free, open source, yours to run anywhere. Databricks is the fully-built vehicle around that engine — the chassis, the gearbox, the air conditioning, the security guard and the service centre. You can absolutely build your own car around the engine. Most teams would simply rather drive.

    And in the gurukul, the magician learned four new disciplines that he could never have learned alone.

    Discipline one — Delta Lake, the honest ledger

    Spark was always brilliant at reading. But the godown itself — plain files sitting in cloud storage — was a lawless place. If a job crashed halfway through writing, you were left with half-written garbage. If one person was reading while another was writing, who knows what you got. And nobody could tell you what the data looked like last Tuesday.

    So the gurukul gave the village a proper ledger: Delta Lake. It sits on top of your ordinary files and adds three things every accountant has demanded since the beginning of time:

    ACID transactions — a write either fully happens or fully does not. No half-truths. Time travel — you can literally ask for the table as it stood twenty versions ago, which has saved more careers than any monitoring dashboard. Schema enforcement — if someone tries to push a string into a number column, the ledger refuses politely instead of quietly corrupting six months of reports.

    Discipline two — the Lakehouse and the three vessels

    For years the village kept two separate godowns and argued about them endlessly. A data lake — cheap, holds anything, messy. A data warehouse — clean, fast, structured, expensive, and refuses to hold your photos and logs.

    Databricks asked the obvious question that nobody had asked: why two? Keep the cheap open storage of the lake, and put warehouse-grade discipline on top of it. They called it the Lakehouse, and today it is simply how modern data platforms are built.

    Inside it, data flows through three vessels, and every data engineer in the world now speaks this language:

    Living Diagram 08

    The Medallion — Bronze, Silver, Gold

    Hover any layer to learn what happens there
    Bronze is raw truth — exactly as it arrived, nothing thrown away, so you can always go back. Silver is cleaned and joined — duplicates removed, types fixed, tables made sensible. Gold is the business answer — small, aggregated, ready for the dashboard your CEO opens at 9 AM. Each arrow is a Spark job. Each vessel is a Delta table.

    Discipline three — Photon, the second heart

    Here the gurukul did something that surprised even the magician.

    Spark's original body was built in Scala and runs on the JVM — flexible, portable, wonderful. But for pure number-crunching, a JVM has a ceiling. So Databricks quietly built the magician a second heart, written in C++, and named it Photon.

    Photon's trick is called vectorisation. The old way processed one row at a time — check this row, then the next, then the next. Photon takes a whole batch of values and applies the operation to all of them in a single stroke, using the SIMD instructions sitting unused inside every modern CPU.

    Think of it as the difference between stamping one envelope, then the next, then the next — versus a machine that stamps forty envelopes in one press.

    And the most beautiful part: you do not rewrite a single line of your code. Same SQL, same DataFrame. Photon simply takes over the parts it can handle and hands the rest back. The magician got faster without changing his spells.

    Living Diagram 09

    Row-by-row vs. Photon's vectorised batch

    Row-at-a-time: — Photon vectorised: —
    Same work, different rhythm. The top lane handles one value per beat. The bottom lane loads eight values into a vector register and applies the operation to all eight in one CPU instruction. On real query workloads this shows up as a several-times speed-up on scans, filters, joins and aggregations — with zero code change.

    Discipline four — Unity Catalog, the gatekeeper

    Power without control is a problem waiting for a Monday morning. The last discipline the gurukul taught was not about speed at all.

    Unity Catalog is the dwarpal — the gatekeeper — standing at the entrance of the whole lakehouse. One place that decides who may see which table, which column, even which row. One place that records where every piece of data came from and which dashboard it eventually fed. That last one is called lineage again — the same beautiful idea as the DAG, but now for your entire organisation instead of one job.

    And in 2026 this gatekeeper had to learn something new, because the visitors changed. It is no longer only humans and dashboards asking for data. It is AI agents — programs that decide for themselves which table to query and which tool to call. So governance quietly grew from "who can open this door" into "what is this agent allowed to actually do once inside, and what did it do last Tuesday at 3 AM."

    The magician who once only counted rows is now the one who feeds the machines that think.

    ✦ ✦ ✦
    Chapter Five

    Where the Magician Stands Today

    It is 2026. The small research project from Berkeley is now the engine underneath an enormous share of the world's data work — in banks, hospitals, telecom towers, e-commerce warehouses and, quite likely, in whatever app you opened this morning.

    Spark crossed into its fourth major age with Spark 4.0, and the line has kept moving steadily — 4.2.0 arrived in July 2026. The changes tell you exactly where the magician is walking.

    He became lighter. With Spark Connect, your code no longer has to sit inside the cluster shouting at it. A thin client — a mere 1.5 MB, and it does not even need Java installed anymore — talks to Spark over a proper protocol. Your laptop, your notebook, your web app, your agent: all can speak to the magician from a distance.

    He became stricter, in a good way. ANSI SQL mode is now the default. Earlier, a bad number would quietly become null and your report would be silently wrong. Now it raises its hand and says "this is an error." Loud failure is a kindness; silent wrongness is not.

    He learned to hold messy shapes. The new VARIANT type stores semi-structured JSON properly — flexible like a document store, but still fast to query, because half the world's data arrives as untidy JSON and pretending otherwise never worked.

    He became more Pythonic. A native plotting API, a Python Data Source API so you can teach Spark to read anything you like in pure Python, Python UDTFs, and a much friendlier profiler. Spark stopped asking Python people to learn Scala.

    Quick timeline: 2009 — born as a research project at UC Berkeley's AMPLab. 2010 — open sourced. 2013 — donated to the Apache Foundation; Databricks founded. 2014 — Spark 1.0, and it wins the Daytona GraySort record. 2016 — Spark 2.0 brings DataFrames, Catalyst and Structured Streaming. 2020 — Spark 3.0 brings Adaptive Query Execution. 2025 — Spark 4.0. 2026 — Spark 4.2, and the lakehouse becomes the ground floor of enterprise AI.

    So where does the superpower actually come from?

    Let us answer the elders' question properly, in one table. There is no magic anywhere in it.

    The powerThe real reason behind it
    SpeedData stays in memory between steps instead of running to disk after every stage
    ScaleWork is split into partitions and spread across many executors, all running at once
    Never loses dataIt remembers the recipe (lineage / DAG) and can rebuild any lost piece on demand
    Writes better code than youLazy evaluation lets Catalyst see the whole plan and rewrite it before a single row moves
    Adapts mid-flightAQE watches the real data at runtime and changes the plan when its assumptions were wrong
    One tool, many jobsSQL, DataFrames, streaming and ML all compile down to the same engine
    Extra gear (on Databricks)Photon's C++ vectorised execution, Delta Lake's transactions, Unity Catalog's governance

    The moral of the story

    If you take away only one thing from this whole tale, take this.

    Apache Spark did not win because it was clever in a thousand ways. It won because it was clever about three ordinary human ideas, and then absolutely refused to compromise on them.

    Divide the work, so no one hand carries the mountain.
    Remember how things were made, so nothing is ever truly lost.
    Listen to the whole request before you begin, so you begin correctly.

    A magician, in the end, is only someone who understood the problem better than everybody else in the room — and then had the patience to build for it.

    The mountain never became smaller.
    The magician simply stopped trying to lift it alone. — The Magician of Mahadata
    ← Back to all stories