Cloud & Infrastructure · Paper 01 / 05

The Google File System

Sanjay Ghemawat, Howard Gobioff, Shun-Tak Leung

2003 · SOSP · ~12 min read

Read the original paper

GFS stores huge, append-heavy files on thousands of unreliable machines with one metadata master and three copies of every chunk. Read it to see a system designed from a written list of workload assumptions, and what a weaker consistency model buys.

In the early 2000s Google was storing its crawl of the web on a few thousand cheap Linux PCs. On a fleet that size something is always broken: a disk has died, a machine is rebooting after a kernel bug, a power supply has failed, and now and then a drive returns bytes that are not the bytes it was given. The files themselves were unlike anything a workstation file system expected. A day’s crawl might be a handful of files, each many gigabytes long, which hundreds of MapReduce workers append to at the same time and the next job then reads from start to finish.

NFS and the file systems before it were built for the opposite case: reliable disks, many small files, and one user doing small reads and writes at random offsets. The GFS paper describes what Google built instead, and it is unusually frank about what it gave up. By the end of this page you should be able to trace one append through a master and three replicas, say what a reader sees when one replica fails halfway through, and explain why HDFS looks the way it does and why Google later replaced GFS with Colossus.

We will follow one example. A crawler worker wants to append a 1 MB record of fetched pages to a shared file called /crawl/day-17. Forty other workers are appending to the same file at the same moment.

Start from the workload, not from POSIX

Section 2.1 of the paper lists assumptions before it describes any mechanism, and every later decision traces back to one of them. Component failure is the normal state, so detection and repair have to be automatic. Files are large, so a few million of them is plenty and per-file metadata can be generous. Most mutations append to the end of a file and almost nothing overwrites the middle, so random writes can be supported without being fast. Workloads care about sustained bandwidth more than the latency of any single operation, because a MapReduce job is measured in hours.

The last assumption is the one that makes GFS possible at all: the file system and the applications were written by the same company. GFS does not implement the POSIX interface. It offers create, delete, open, close, read and write, plus two operations POSIX lacks, snapshot and record append. When the authors could make the file system simpler by asking applications to do a little more work, they did, and they could ask because they knew every application.

A common reading is that GFS is a general-purpose distributed file system that happened to be built at Google. It is not. The paper says small files are supported but not optimised, and later Google teams found out exactly how expensive that sentence was. Keep the workload in mind when a design choice looks strange; it usually stops looking strange.

One master that never touches the bytes

A GFS cluster has one master and many chunkservers. Every file is cut into fixed 64 MB chunks, each named by a 64-bit chunk handle and stored as an ordinary Linux file on three chunkservers by default. The master holds all metadata in memory: the namespace, the list of chunk handles that make up each file, and which chunkservers currently hold each chunk.

Holding everything in memory sounds reckless until you do the arithmetic. The paper says the master keeps less than 64 bytes of metadata per 64 MB chunk. A petabyte of data is about sixteen million chunks, and sixteen million times 64 bytes is roughly a gigabyte of RAM. That fit comfortably on one machine in 2003, and it means every placement decision can be made with a complete, global view and no disk seek.

Now a reader of our crawl file asks for the bytes at offset 200,000,000. The client library divides by 64 MB and gets chunk index 2. It sends the master the file name and that index, and the master replies with the chunk handle and the three chunkservers that hold it. The client caches the answer and reads the bytes straight from the nearest replica. The next read in the same chunk does not involve the master at all.

clientmasterchunkserver 1chunkserver 2chunkserver 3① file, chunk index② chunk handle + 3 locations (cached)③ read 64 MB directlythe master touches bytes of metadata per operation, never the data
A read. The client asks the master which chunk and which servers, caches the reply, then fetches the data directly from a chunkserver. The master handles a few dozen bytes per lookup and none of the file data.

The master does not store chunk locations on disk. At startup, and in every heartbeat after that, it asks each chunkserver what it holds. The reasoning is that the chunkserver has the final word on what is actually on its disks, since disks fail and operators rename machines, so a persistent copy on the master would only be a second, staler opinion to reconcile. What the master does persist, through an operation log, is the namespace and the file-to-chunk mapping, because nothing else knows those.

The 64 MB chunk size is the other big bet. Large chunks mean fewer master lookups, fewer metadata entries, and long-lived TCP connections to one chunkserver for a whole sequential read. The cost shows up with small files. The paper describes an executable stored in GFS as a single-chunk file and then started on hundreds of machines at once; the few chunkservers holding it were overwhelmed. The fix was a higher replication factor for that file and staggered start times, which is a workaround, not a design.

Following one append through the replicas

Our worker’s 1 MB record goes to the last chunk of /crawl/day-17. Section 3.1 of the paper walks the steps, and they separate two flows that most designs mix together: the flow of data and the flow of control.

First the client asks the master which replica holds the lease for the last chunk. A lease is a grant of authority over one chunk, with an initial timeout of 60 seconds that the primary renews by piggybacking requests on its heartbeats. If no replica holds one, the master grants it to one of the three, which becomes the primary. The master replies with the primary and the two secondaries.

Second, the client pushes the 1 MB of data, not to all three replicas from its own network link, but to the nearest one, which forwards it to the next nearest while it is still receiving. Each replica buffers the bytes without applying them. The paper computes the payoff: with 100 Mbps links, pushing 1 MB takes about 80 ms along a pipelined chain, because each link carries the data once. Sending three separate copies from the client’s link would take three times as long.

Third, once every replica has acknowledged the data, the client sends the primary a short control message: append the buffered record. For a record append, the primary picks the offset itself, at the current end of the chunk, applies the bytes there, and tells both secondaries to apply them at the same offset. When all three reply, the primary tells the client the offset where its record landed. The forty other workers are doing the same thing, and the primary serialises all of them. One machine decides the order for one chunk for a few seconds at a time, and no global agreement is needed.

clientreplica Aprimary · leasereplica Cdata: pushed to the nearest replica, forwardedalong the chain, buffered, not yet appliedcontrol: “write it” goes to the primary only;it picks a serial order and tells the othersnetwork bandwidth is used once per hop; one machine decides the order
A write. The data travels along a chain of replicas, each forwarding as it receives, so every link is used once. The command to apply it goes only to the primary, which chooses the order and tells the other two.

Change one variable. Suppose the last chunk has only 0.5 MB of space left. The primary sees that a 1 MB record will not fit, pads the rest of the chunk, tells the secondaries to pad as well, and replies to the client with an instruction to retry. The master allocates a new chunk and the record lands at its start. To keep the waste bounded, GFS limits a record append to a quarter of the chunk size, so at most 16 MB of any chunk can be padding, and in practice much less.

Predict first

Now suppose the first attempt reached the primary and secondary A but secondary C’s disk write failed. The client retries and the second attempt succeeds everywhere. How many copies of the record does a reader of replica A find, and what does a reader of replica C find at the first offset?

Show the worked answer

Replica A holds the record twice: once at the first offset, from the attempt that failed on C, and again at the new offset the primary assigned on the retry. Replica C holds the record once, at the second offset, and at the first offset it holds whatever was there: partial bytes or padding.

GFS reports the first attempt as a failure and does not roll it back on the replicas that succeeded. The only promise is that the record is written at least once, atomically, at the same offset on every replica, at the offset the client was told. Everything around that offset is the application’s problem.

What the consistency model actually promises

Section 2.7 gives the vocabulary. A file region is consistent if every client sees the same bytes whichever replica it reads, and defined if it is consistent and also reflects one mutation in its entirety. The table below is the paper’s model restated with what an application has to do about each case.

What happenedState of the regionWhat the reader must do
a single write or append succeededdefinednothing
concurrent writes to overlapping ranges all succeededconsistent but undefined: every replica agrees, but the bytes may be fragments of several writesavoid overlapping writes, or treat the region as untrustworthy
a record append succeeded after retriesdefined at the returned offset, possibly inconsistent around itskip padding and partial records, drop duplicates
a mutation failedinconsistent: replicas disagreedo not use; the writer will retry elsewhere

Google’s applications coped by writing what the paper calls “self-validating, self-identifying records”: each record carries a checksum, so a reader can skip padding and fragments, and a unique id, so a reader can drop the duplicate copy our worker’s retry produced. This logic lived in a shared library, so individual teams did not reinvent it.

Why accept such a weak promise? Exactly-once appends would need a commit protocol across the replicas on every append. The primary would have to hold the record until all three agreed, and roll back the replicas that applied it when one failed. That costs a round trip per append, and it means a single slow secondary blocks forty writers. GFS made retries cheap and pushed duplicate removal to the reader, who was usually a MapReduce job reading the whole file sequentially anyway. For that workload it was a good trade. For a bank ledger it would not be.

Failure is a background job

The second half of the design is a set of mechanisms that keep running while machines fail around them. The master exchanges heartbeats with every chunkserver. When one goes silent, every chunk it held drops below three copies, and the master queues those chunks for re-replication. The queue has a priority order: a chunk with one live copy goes ahead of a chunk with two, chunks of live files go ahead of chunks of recently deleted ones, and any chunk that is blocking a client’s progress jumps the queue. The master also throttles cloning so that repair traffic does not swamp the clients.

Try itLose a chunkserver, keep the file

A file is a list of 64 MB chunks; each chunk lives on three chunkservers. The master only knows where things are.

master · metadatachunk 1 → CS1 CS2 CS3chunk 2 → CS3 CS4 CS5chunk 3 → CS5 CS1 CS2chunk 4 → CS2 CS3 CS4CS1chunk 1chunk 3CS2chunk 1chunk 3chunk 4CS3chunk 1chunk 2chunk 4CS4chunk 2chunk 4CS5chunk 2chunk 3
chunks4× 3 copies
under-replicated0every chunk has three live copies
servers up5of 5
The master holds only metadata: file → chunks → which servers. Clients never stream data through it.

Failure is not an exception here, it is the steady state: the master expects servers to vanish and treats a missing replica as routine work. Because clients fetch data directly from chunkservers, a single master can coordinate thousands of them without becoming the bottleneck.

A chunkserver that was down during a mutation comes back holding an old copy. GFS catches this with a chunk version number: the master increments it every time it grants a new lease, and the up-to-date replicas record the new number. When the returning server reports an older version, the master treats that replica as stale, leaves it out of replies to clients, and garbage-collects it later.

Disks that lie are handled by the chunkservers themselves. Each chunk is divided into 64 KB blocks, each with a 32-bit checksum kept in memory and logged. A chunkserver verifies the checksum of every block it returns. On a mismatch it returns an error to the reader, tells the master, and the master clones a good replica over the bad one. Corruption is caught at the server that holds it and does not spread to other replicas through a copy.

Deletion is lazy. A deleted file is renamed to a hidden name with a timestamp, and the master removes it during a regular namespace scan once it is older than three days by default. Chunks that no file references are dropped when chunkservers report them in heartbeats. This is slower than deleting eagerly, but it gives users an undelete window and it makes partial failures harmless: a chunkserver that missed a delete message will simply be told in a later heartbeat.

The master itself is protected by its operation log, which is replicated on several machines, and by periodic checkpoints of its state. If the master process dies, a new one starts, loads the latest checkpoint, replays the log, and polls the chunkservers for locations. Read-only shadow masters trail the log and can serve lookups while the primary is down. The paper’s measurements show the repair side working: after killing a chunkserver holding roughly 600 GB, the cluster restored full replication in a little over twenty minutes, and when two servers were killed, the chunks left with a single copy were raised to two within a couple of minutes.

What the single master cost, and what replaced it

The design aged in exactly the places its assumptions did. In a 2009 ACM Queue interview, Sean Quinlan, who led GFS for years, described the pressures. The number of files grew far past what the workload section had predicted, and the master’s memory and the time it took to recover from a crash grew with it. Teams worked around the limit by running many GFS cells and splitting their data between them. New applications such as Gmail were latency-sensitive and full of small files, which suited neither the 64 MB chunk nor the at-least-once append.

Google’s successor, Colossus, kept the separation of metadata from data but spread the metadata across many servers backed by a database (Google has said publicly that Colossus stores its file system metadata in Bigtable), and replaced three full copies with Reed-Solomon erasure coding, which survives similar failures with much less extra storage. Outside Google, HDFS copied GFS almost line for line: the NameNode is the master, DataNodes are chunkservers, and blocks are chunks. HDFS spent the following decade adding standby NameNodes and federation to address the same single-master limits.

If you are choosing a storage design today, the GFS shape fits when files are large, writes are appends, readers scan, and you control the applications. It fits badly when you need POSIX semantics, many small files, low-latency random reads, or overwrites in place. Those are the conditions that would make you revisit it, and they are the conditions Colossus and modern object stores were built for.

How to read the original

Read section 2 slowly, especially 2.1 (assumptions) and 2.7 (the consistency model). Then read section 3 with figure 2 open next to it; trace the numbered steps for a write and then for a record append. In section 4, skim namespace locking and read replica placement, re-replication and garbage collection closely. Section 5 on fault tolerance is short and worth reading in full.

In section 6, the micro-benchmarks show where reads and writes fall short of the network limit, and the authors explain why. The real-cluster numbers are more interesting for what they show about the master: its operation rate is modest, which supports the claim that a single master is not the bottleneck at their scale. Section 7, on experiences, describes bugs in Linux disk drivers and the cost of fsync on large logs. It is a good reminder that a distributed system inherits the faults of every layer under it.

The next paper, Dapper, starts where GFS’s users ended up: with a request that crosses many services and machines, and no way to see where the time went.