We closed Module 1 with two awkward questions: where is data stored when it does not fit on any disk? And what happens if the machine holding it breaks down? The practice files in ~/novamarket/data/ take up 38 MB and live on a single disk in your laptop, but NovaMarket generates around 7.6 GB a day in web events alone. Within a few years that is tens of terabytes, and nobody wants the company's entire history to depend on a single disk.
The answer is the distributed file system: a system that spreads each file across many machines and keeps several copies of every piece, applying the ideas of partitioning and replication from lesson 01-04. In this lesson you will see how the most influential of them all, HDFS, works, along with its practical successor on most platforms today: cloud object storage. This is the foundation on which the rest of the module rests: file formats, data lakes and the lakehouse are all built on top of one of these two pieces.
What a distributed file system is and what problem it solves
The file system on your laptop is the part of the operating system that organises the disk into folders and files. When you type ls data/, it is the file system that knows which files are there and in which areas of the disk their bytes sit.
A distributed file system does the same thing, but across the disks of many machines at once. To whoever uses it, it still looks like a single tree of folders and files; underneath, the data is spread across the cluster.
It solves three problems that a single disk cannot:
| Problem | With a single disk | With a distributed file system |
|---|---|---|
| Capacity | The limit is the size of the disk | You add nodes and capacity grows (horizontal scaling, lesson 01-01) |
| Availability | If the disk fails, the data is lost | Each piece is copied onto several nodes: a failure loses nothing |
| Performance | A single disk reads at a limited speed | Many machines read different pieces of the same file at once |
The third point is less obvious, and it is key to Module 3: if a 100 GB file is spread across 50 machines, 50 processes can read it simultaneously, each taking its own part. Distributed storage is what makes distributed processing possible.
The origin: Google File System
In the early 2000s, Google needed to store a copy of the web in order to build its search engine. No commercial hardware offered that capacity at a reasonable price, so it went for an idea that was bold at the time: use thousands of cheap, ordinary computers, accept that one of them would always be broken, and let the software make sure nothing was lost.
In 2003 it published a paper describing the result, the Google File System (GFS). Its design decisions shaped everything that came afterwards:
- Hardware failures are the norm, not the exception: the system must detect them and repair itself.
- Files are huge (GB or TB), and there are relatively few of them.
- Files are written once, nearly always by appending data at the end, and are then read many times from start to finish.
- Throughput (how many MB per second are processed in total) matters more than how quickly an individual request is answered.
Taking its inspiration from that paper, the open-source Apache Hadoop project created HDFS (Hadoop Distributed File System), which for more than a decade was the standard storage for Big Data. Hadoop has more parts (you will see them in lessons 03-01 and 06-01); here we are only interested in its file system.
Inside HDFS: blocks, NameNode and DataNodes
Blocks
HDFS does not store a file as a single piece. It cuts it into fixed-size chunks called blocks, 128 MB by default, and distributes those blocks across the nodes. This is exactly the partitioning from lesson 01-04, applied to files.
A 300 MB file, for example, is split into three blocks: two of 128 MB and one of 44 MB. The last block takes up only what it needs; it is not padded out to 128 MB.
Why such large blocks, when the file system on your laptop uses blocks of a few kB? Because that way there are few blocks to manage per file, and because reading one large chunk straight through is far more efficient than jumping between millions of tiny ones.
NameNode and DataNodes
An HDFS cluster has two kinds of node, with very different roles:
| NameNode | DataNode | |
|---|---|---|
| How many there are | One active (plus a standby in production) | Many: tens, hundreds or thousands |
| What it stores | The metadata: the folder tree, permissions, which blocks make up each file and which DataNodes hold each block | The data: the contents of the blocks |
| Where it stores it | In RAM, so it can answer instantly (with a copy on disk) | On its local disks |
| Analogy | A library's catalogue | The shelves holding the books |
The DataNodes periodically send the NameNode a sign of life (a heartbeat) and a report of the blocks they hold. If a DataNode goes quiet, the NameNode writes it off and orders its blocks to be copied again, from the surviving replicas, onto other nodes. Nobody has to step in: the cluster repairs itself.
flowchart TB
C[Client] -- "1. Where is the file?" --> NN[NameNode<br/>metadata in memory]
NN -- "2. List of blocks and DataNodes" --> C
C -- "3. Reads or writes the blocks" --> DN1
C --> DN2
C --> DN3
subgraph Cluster
DN1[DataNode 1<br/>B1 B2]
DN2[DataNode 2<br/>B1 B3]
DN3[DataNode 3<br/>B2 B3]
DN4[DataNode 4<br/>B1 B2 B3]
end
DN1 -. heartbeat .-> NN
DN4 -. heartbeat .-> NN
Notice one important detail in the diagram: the data never passes through the NameNode. The client asks it where the blocks are and then talks directly to the DataNodes. If all the traffic went through a single node, that node would be a bottleneck.
Because the NameNode is indispensable (without the catalogue, the blocks are meaningless fragments), in production it is configured for high availability: a second, standby NameNode keeps an up-to-date copy of the metadata and takes over if the active one fails.
Replication and rack awareness
Each block is stored on several DataNodes. The number of copies is the replication factor, which is 3 by default. With three copies, the cluster can lose two nodes at the same time without losing a single block.
The price is obvious: every GB of data takes up 3 GB of disk. We will come back to that sum at the end of the lesson.
Which nodes do the three copies go on? Not random ones. In a data centre, servers are mounted in cabinets called racks, and all the servers in a rack share a power supply and a network connection. If a rack's network switch fails, all its nodes vanish at a stroke. That is why HDFS applies a rack awareness policy:
- The first replica goes to the node where the write is taking place (or to any node).
- The second goes to a node in another rack.
- The third goes to a different node in that same second rack.
The copies therefore end up spread across two racks: losing an entire rack does not lose any block, and at the same time traffic between racks, which is the most expensive kind, is kept down.
Note: modern versions of HDFS also offer erasure coding, a technique that protects data with parity information instead of full copies and cuts the storage overhead from 200% to around 50%, in exchange for more computation. It is mostly used for old data that is rarely read.
How a file is written and read
Let's see what happens when Laura uploads web_events.json to the cluster.
sequenceDiagram
participant C as Client
participant NN as NameNode
participant D1 as DataNode 1
participant D2 as DataNode 2
participant D3 as DataNode 3
C->>NN: I want to create /novamarket/data/web_events.json
NN-->>C: Agreed. Block 1: DataNodes 1, 2 and 3
C->>D1: Data for block 1
D1->>D2: Forwards the data
D2->>D3: Forwards the data
D3-->>D2: Received
D2-->>D1: Received
D1-->>C: Block 1 confirmed
C->>NN: File complete
Writing, step by step:
- The client asks the NameNode to create the file. The NameNode checks the permissions and that the file does not already exist.
- For each block, the NameNode chooses the target DataNodes (applying rack awareness).
- The client sends the data only to the first DataNode; that one forwards it to the second, and the second to the third. It is a replication chain (a pipeline).
- The acknowledgements travel back along the chain in the opposite direction. When they reach the client, the block is safe on three nodes.
- This is repeated for the following blocks and, at the end, the client tells the NameNode that the file is complete.
Reading: the client asks the NameNode which blocks make up the file and where they are; for each block, the NameNode returns the list of DataNodes that hold it, sorted by proximity to the client. The client reads each block from the nearest DataNode and, if that one fails, tries the next on the list. Each block also carries a checksum: if the data read is corrupt, this is detected and another replica is used instead.
"Write once, read many" and the small files problem
Write once, read many
HDFS follows the WORM model (write once, read many): a file is written, closed and from then on never modified. You can append content at the end or delete the whole file, but you cannot swap byte 5,000 for another.
It sounds like a serious limitation, but it fits the nature of analytical data: a web event that happened on 15 June never changes. And it simplifies the system enormously, because replicating data that does not change is easy; replicating data that is being modified from several places at once is very hard (remember the CAP theorem).
The practical consequence is that "updating" a piece of data means rewriting the file that contains it. Hold on to this idea: it is the root of the data lake limitations we will resolve in lesson 02-05.
The small files problem
The NameNode keeps one entry in memory for every file and for every block. As a rule of thumb, each one takes up about 150 bytes of RAM. Whether a file is 1 kB or 128 MB makes no difference: it costs the NameNode the same.
Compare two ways of storing the same GB of data:
| 8 files of 128 MB | 10,000 files of 100 kB | |
|---|---|---|
| Entries in the NameNode (file + block) | 16 | 20,000 |
| Approximate memory in the NameNode | 2.4 kB | 3 MB |
| Open operations needed to read it all | 8 | 10,000 |
Multiplied by thousands of GB, the second way exhausts the NameNode's memory and slows down every job, which wastes more time opening files than reading data. This is the small files problem, one of the most common on real platforms. The solution is always the same: group the data into large files, of the order of the block size. It will come up again when we talk about partitioning in lesson 02-04.
Basic hdfs dfs commands
HDFS is operated from the terminal with the hdfs dfs command, whose options mimic the Linux commands you already know.
This exercise is optional. The commands need a running Hadoop cluster, and setting one up is not trivial. If you want to try them, the simplest route is a Docker container with the official
apache/hadoopimage, following the instructions in its documentation. It is not needed for the rest of the course: the expected output of each command on a cluster with a replication factor of 3 is shown here, so that you can follow the explanation by reading. The outputs are illustrative (the user, dates and group name will vary).
There are two worlds you must not confuse: the local disk of the machine you are typing on and the HDFS namespace, which is a separate tree of folders starting at /.
# 1. Create a folder in HDFS (-p creates the intermediate ones)
hdfs dfs -mkdir -p /novamarket/data
# 2. Upload files from the local disk to HDFS
hdfs dfs -put ~/novamarket/data/web_events.json /novamarket/data/
hdfs dfs -put ~/novamarket/data/orders.csv /novamarket/data/
# 3. List the contents of the folder
hdfs dfs -ls /novamarket/dataFound 2 items -rw-r--r-- 3 laura supergroup 37766058 2026-07-01 09:15 /novamarket/data/web_events.json -rw-r--r-- 3 laura supergroup 1038238 2026-07-01 09:15 /novamarket/data/orders.csv
The output resembles that of ls -l, with one difference: the second column (3) is each file's replication factor. Sizes are shown in bytes and are those of the original file, not counting the replicas.
# 4. View the start of a file (cat dumps all of it: head cuts it short)
hdfs dfs -cat /novamarket/data/orders.csv | head -n 3order_id,customer_id,order_date,total_amount,status,channel 1,799,2026-01-01 00:02:39,1353.13,delivered,app 2,86,2026-01-01 00:09:59,601.58,shipped,web
-du shows two sizes: that of the file and the space it actually consumes on the cluster counting the replicas, which is three times as much. (HDFS uses binary units, which is why the file's 37.8 MB appear as 36.0 M.) Neither of these files reaches 128 MB, so each one occupies a single block.
-setrep changes the number of copies of a specific file; with -w, the command waits until the cluster has finished adjusting them. Lowering replication saves space on data that is unimportant or easy to regenerate; raising it gives critical data more protection.
| Command | What it does | Local equivalent |
|---|---|---|
hdfs dfs -mkdir -p path |
Creates a folder | mkdir -p |
hdfs dfs -put source destination |
Uploads a local file to HDFS | cp |
hdfs dfs -get source destination |
Downloads a file from HDFS to the local disk | cp |
hdfs dfs -ls path |
Lists a folder | ls -l |
hdfs dfs -cat path |
Dumps the contents of a file | cat |
hdfs dfs -du -h path |
Shows the space used | du -h |
hdfs dfs -setrep n path |
Changes the replication factor | None |
hdfs dfs -rm path |
Deletes a file | rm |
Object storage: today's dominant alternative
HDFS means maintaining a cluster: machines switched on, disks that fail, a NameNode to keep an eye on. Cloud providers offer another way of storing practically unlimited amounts of data without managing a single machine: object storage.
| Provider | Service |
|---|---|
| Amazon Web Services | Amazon S3 |
| Microsoft Azure | Azure Blob Storage and its analytics variant, ADLS Gen2 |
| Google Cloud | Google Cloud Storage (GCS) |
The details of each cloud are covered in lesson 06-04. There are also implementations compatible with the S3 interface that can be installed on your own servers (MinIO or Ceph, for example); that interface has become a de facto standard.
Objects versus files
In an object store there are no visible folders or blocks. There are buckets and, inside them, objects. Each object is:
- a key: a piece of text that identifies it, such as
data/web_events/2026-06-15.json; - its content: the bytes;
- some metadata: size, date, type, tags.
They are accessed through web (HTTP) requests: "store this object under this key", "give me the object with this key". Paths are written as URLs: s3://novamarket-lake/data/web_events/2026-06-15.json.
Three differences from a file system deserve attention:
- Folders are an illusion. The key above is not "inside the
data/folder": it simply begins with that text. Tools display folders by grouping keys by their prefix. As a result, "renaming a folder" holding a million objects can mean copying and deleting a million objects, rather than being an instant operation as in HDFS. (Some services, such as ADLS Gen2, do offer real folders to avoid this.) - Objects are immutable. You cannot modify a piece or append to the end: the whole object is replaced. It is the same "write once, read many" model, taken to the extreme.
- Replication is invisible. The provider keeps several copies in different data centres and guarantees extremely high durability, without you having to choose a replication factor or pay separately for the copies: you pay per GB stored and per request.
Separation of compute and storage
In a classic HDFS cluster, the same machines store the data and process it. This has one advantage, data locality (the computation runs on the node that already holds the block, without moving it over the network), and one serious drawback: storage and computing capacity grow together. If NovaMarket needs to store twice as much data but process it just as before, it has to buy complete machines, with processors it does not need.
With object storage, the data lives in one service and the computation in another. This is the separation of compute and storage:
- You store as much as you need at the very low price of storage.
- Compute clusters are switched on when there is work and switched off when it is done. The data is still there.
- Several different engines (Spark, a data warehouse, an ML tool) can read the same data.
That elasticity is the main reason why most new platforms today are built on object storage, with HDFS remaining mostly in installations in companies' own data centres (on-premises).
HDFS versus object storage
| Aspect | HDFS | Object storage |
|---|---|---|
| Where it runs | Your own (or a rented) cluster that has to be administered | A service managed by the provider |
| Unit stored | A file split into 128 MB blocks | A whole object identified by a key |
| Folders | Real; renaming is instant | Simulated with prefixes (with exceptions) |
| Fault tolerance | Configurable replication factor (3 by default) | Handled by the provider, transparent |
| Capacity | That of the cluster's disks | Practically unlimited |
| Compute and storage | Coupled: same machines | Separate: they scale independently |
| Data locality | Yes | No: the data travels over the network |
| Cost model | Investment in hardware and operations staff | Pay-as-you-go: GB stored and requests |
| Small files | A serious problem (NameNode memory) | No NameNode, but many slow, billable requests |
| Typical fit | Own data centres, requirements for total control | Cloud platforms and most new projects |
Most important of all: for processing tools, the difference is almost invisible. In Spark, reading from one place or the other only changes the prefix of the path:
spark.read.json("file:///home/laura/novamarket/data/web_events.json") # local disk
spark.read.json("hdfs://namenode:8020/novamarket/data/web_events.json") # HDFS
spark.read.json("s3a://novamarket-lake/data/web_events.json") # Amazon S3That is why in this course you will work with your computer's local disk: everything you learn about formats, partitioning and processing applies equally to HDFS or the cloud.
How much space NovaMarket needs
Let's finish with the calculation Laura would make if NovaMarket decided to keep web_events on its own HDFS cluster. We start from the figures in lesson 01-01: 40 million events a day, around 191 bytes per event.
| Step | Calculation | Result |
|---|---|---|
| Data per day | 40,000,000 × 191 bytes | 7.64 GB |
| Blocks per day | 7,640 MB ÷ 128 MB | 60 blocks |
| Block replicas per day | 60 × 3 | 180 |
| Data per year | 7.64 GB × 365 | 2.79 TB |
| With replication 3 | 2.79 TB × 3 | 8.37 TB |
| With 25% free headroom | 8.37 TB ÷ 0.75 | 11.2 TB of raw disk |
The headroom in the last step is no luxury: a cluster needs free space for the temporary files of its jobs and for re-replicating blocks when a node fails. A cluster that is 95% full is a cluster about to cause trouble.
So a year of events that "take up" 2.79 TB demands around 11 TB of disk: four times as much. And that is just one dataset, in its original format. Two conclusions:
- Replication is expensive. When sizing, the figure that matters is the raw space, not the size of the files.
- Shrinking the data before replicating it saves three times over. That is exactly what the file formats and compression in the next lesson achieve.
With object storage the sum is different: you would pay for the 2.79 TB (replication is included in the price per GB), with no headroom to set aside. Cost control is covered in lesson 05-03.
Common Mistakes and Tips
- Confusing replication with backup. Replication protects against hardware failures. If someone deletes a folder by mistake, the deletion is applied to all three replicas. Backups and data versioning are a different matter.
- Generating thousands of tiny files. A job that writes one file per minute or per customer creates the small files problem without anyone noticing until it is serious. Always group.
- Treating HDFS or S3 like an ordinary disk. They are no good for editing files in place, nor as the store for a transactional database, nor for answering in milliseconds. They are designed for large, sequential reads.
- Confusing the local path with the HDFS one.
~/novamarket/data/and/novamarket/dataare different places: the first is on your disk and the second on the cluster. Both appear in-putand-get. - Thinking that folders exist in the cloud. Renaming or moving large "folders" in an object store can be slow and costly. Design your paths well from the outset.
- Sizing by logical size. Multiply by the replication factor and add headroom.
- Tip: if you are starting a new project with no constraints that force you to use your own data centre, object storage is almost always the simplest and cheapest starting point.
Exercises
Exercise 1: blocks and replicas
Laura uploads a 500 MB file containing the catalogue of product images to an HDFS cluster (128 MB blocks, replication factor 3).
- How many blocks is it split into, and how big is each one?
- How many block replicas are stored in total?
- How much disk space does it take up on the cluster?
- If the cluster has two racks, can the file be lost if one of them goes down completely?
Exercise 2: small files
A badly designed job stores NovaMarket's events in one file per session. Over a year, 500 million files of a few kB each pile up. Using the rule of 150 bytes per entry in the NameNode, estimate how much RAM it needs just to keep track of those files. What would you do to avoid this?
Exercise 3: sizing the cluster
Irene wants to keep three years of web_events in HDFS with replication 3 and 25% free headroom. Each available data node has 4 disks of 8 TB.
- How much raw disk is needed?
- How many data nodes are needed for capacity? Is that number enough?
- How much would be paid for, in data volume, with object storage?
Solutions
Exercise 1
- 500 ÷ 128 = 3.9 → 4 blocks: three of 128 MB (384 MB) and one of 116 MB.
- 4 blocks × 3 = 12 replicas.
- 500 MB × 3 = 1,500 MB. The last block only takes up 116 MB, not 128.
- No. Rack awareness guarantees that every block has replicas in both racks, so when one goes down at least one copy of each block remains in the other.
Common mistake: calculating 4 blocks × 128 MB × 3 = 1,536 MB. Blocks are not padded.
Exercise 2
Each small file generates two entries (the file and its single block): 500,000,000 × 2 × 150 bytes = 150,000,000,000 bytes = 150 GB of RAM in the NameNode, for metadata alone. In practice this is unworkable.
The solution is to group: for example, a job that gathers each day's events into a few large files. The daily 7.64 GB fit into about 60 block-sized files; over a year, about 22,000 files instead of 500 million.
Exercise 3
- Three years: 2.79 TB × 3 = 8.37 TB logical. With replication 3: 25.1 TB. With headroom: 25.1 ÷ 0.75 = 33.5 TB of raw disk.
- Each node provides 4 × 8 = 32 TB, so for capacity 2 nodes (64 TB) would be needed. But that is not enough: with a replication factor of 3 you need at least 3 DataNodes so that the three copies are on different machines, and in practice a few more so that the cluster can restore full replication when a node fails. A reasonable design would start from 4 or 5 data nodes, in addition to the NameNodes.
- You would pay for the 8.37 TB logical: the redundancy is borne by the provider.
Tip: capacity is never the only criterion for sizing. Fault tolerance and the computing power required count too.
Conclusion
A distributed file system makes it possible to store files larger than any disk, survive hardware failures and read in parallel. HDFS, heir to the ideas of Google File System, achieves this by splitting files into 128 MB blocks, distributing them across DataNodes with a replication factor of 3 and keeping the catalogue in a NameNode. Its model is "write once, read many", and its weak point is small files. Object storage (S3, Azure Blob Storage/ADLS, GCS) offers the same thing today as a service, with unlimited capacity and separating compute from storage, which is why it is the dominant option for new projects.
In both cases, what is stored is immutable files, and their size is paid for several times over: in disk, in replicas and in read time. We have seen that a year of NovaMarket events in JSON demands around 11 TB of raw disk. What if the same data could take up ten times less and, on top of that, be read much faster? That depends on how the bytes are organised inside each file. In the next lesson, File Formats and Compression, you will compare CSV and JSON with Avro, Parquet and ORC, and convert NovaMarket's files to measure the difference with your own data.
