Git, Docker, and IPFS All Hide the Same Beautiful Idea
Git (2005), Docker (2013), IPFS (2015) all lean on content-addressable storage: a substrate that trades mutable names for immutable identifiers. The address is ...
The Substrate Layer Nobody Talks About
Git (2005), Docker (2013), IPFS (2015) all lean on content-addressable storage: a substrate that trades mutable names for immutable identifiers. The address is the checksum, so integrity verification is free. Identical bytes collide to one blob, so deduplication needs no metadata. Any peer can serve any blob, so replication needs no ownership coordination. The cost: no random writes. Mutation is append-only. Change one byte, get a new address.
The three systems disagree on edge cases — tags, garbage collection, routing — but agree on the core invariant: content identifies content. What follows is how each inherits the primitive, where each breaks it, and what the deviations cost.
Git: A Content-Addressable Filesystem With Mutable Pointers
Git stores every file snapshot, directory tree, and commit as an opaque blob in .git/objects, addressed by H = SHA-1(content). Read a blob: compute H, find the file, decompress zlib. No separate verification pass — if bytes changed, H no longer matches the filename.
git hash-object -w README.md
# writes .git/objects/5d/4e8f7a9b2c1d3e4f5a6b7c8d9e0f1a2b3c4d5e
Four object types form a DAG:
- blob: raw file content
- tree: directory entries mapping names to type:hash pairs
- commit: root tree pointer + parent commits + author/timestamp/message
- tag: annotated signed reference
Pure CAS never mutates or deletes. Git bolts mutability on through refs — HEAD, branches, tags — which are text files holding a commit hash. Deletion happens in gc, which walks objects reachable from refs and prunes the rest after a grace period.
That grace period is load-bearing. Unreachable objects survive 14 days before hard GC. Packfiles complicate it further: once a blob is packed, loose references stop counting — only pack indices do. Git is "loosely" content-addressable: core objects are CAS, refs are mutable, GC is bounded-time rather than permanent.
This bites offline workflows. Clone from a USB stick, commit against a blob that only lives on a teammate's machine, run gc locally — the blob is unreachable from your refs, so it gets pruned and your commit dangles. Git's CAS guarantees hold within a complete clone, not across partial transfers. The operational rule: treat the object database as immutable-by-default, mutate only via refs, and never assume a blob survives unless a long-lived ref reaches it.
Docker: The Same Model With Runtime Mutability
A Docker layer is a tar archive where each path maps to a blob identified by SHA-256(path + content). The engine hashes before pushing, so rebuilding an image whose RUN produces identical output yields matching layer hashes and CI skips the push. That is Git's blob deduplication applied to filesystem diffs.
The union mount is where they diverge. OverlayFS stacks read-only lower layers under a read-write upper layer. A later layer's /etc/passwd shadows the base image's. The CAS invariant holds per-layer — push layer L with hash H and every puller gets identical bytes — but the merged filesystem is ephemeral. Destroy the container and the upper layer vanishes.
Docker then broke CAS where Git never did: layer immutability is enforced at runtime, not at schema time. docker commit snapshots a running container into a new layer, inheriting whatever mutations execution produced — PID files, sockets, cache directories. Git has no equivalent; git commit records staged state, never dynamic state.
Non-determinism also enters earlier, at build time. A RUN npm install line emits different bytes depending on ambient environment variables, install timestamps written into node_modules/.package-lock.json, and registry response ordering. Two machines building the same Dockerfile can produce different layer hashes for identical intent. Git sidesteps this by freezing time at commit (author.date) and requiring explicit staging before hashing — the hash covers content you chose, not content the environment chose for you.
docker build --no-cache --target production .
docker builder prune --filter "until=24h"
docker image inspect myapp:latest --format '{{.RepoDigests}}'
Multi-stage builds claw back some determinism: compile in one stage, copy artifacts into a minimal runtime stage. Intermediate stages become disposable build-layer objects that vanish after the image completes, so production containers only carry the runtime layers. That mirrors Git's separation of tree/blob storage from ref pointers — keep mutable build state isolated from the immutable artifact you distribute.
The production consequence: a Dockerfile-built image is reproducible — build it today or next month, hashes match. A docker commit image is not — the filesystem differs by what wrote to /tmp and what logs accumulated. Teams conflate the two and call the stack "containerized," but the commit path reintroduces exactly the non-determinism CAS was supposed to remove.
Docker's boundary decision was pragmatic: keep CAS for registry transport, allow mutable snapshots for developer ergonomics. Trust image hashes only for Dockerfile-built images. Treat committed layers as ephemeral artifacts. And verify layer hashes across builds in CI — SHA-256 collisions are impossible, but misconfiguration is routine.
One more boundary: layers are CAS within a constrained environment. A colleague pulling layer H from a shared registry mirror gets identical bytes, but if their Docker host ran a different glibc the binary behavior diverges anyway. CAS guarantees data integrity, not semantic compatibility. Pin platform variants explicitly (docker buildx build --platform linux/amd64,linux/arm64) instead of assuming a hash is a portability contract.
IPFS: SHA-1 Became a Liability
Git's hash choice aged badly. SHA-1 was designed for checksums, not collision resistance. The SHAttered attack (2017) produced two PDFs with identical SHA-1 hashes and different content. An attacker could craft evil.c colliding with benign.c and force a merge on matching hashes over divergent code.
Upstream Git adopted SHA-256 only in 2.39+ as an optional path, because switching means re-hashing every object in every repository — a 50 GB repo with 10 million blobs takes hours on one core. protocol.version=2 negotiates between hash formats during transit, but local clones rebuild from scratch. New repos at scale should opt into SHA-256; internal repos behind a closed contribution pipeline can defer and monitor NIST guidance. The threat model decides, not the algorithm's age.
git init --object-format=sha256 new-repo
git config extensions.objectFormat sha256
IPFS dodged the problem by addressing content with SHA-256 (or Blake2b) from the start. It chunks files into ~256 KB blocks, hashes each, and links them into a Merkle-DAG — Git's tree structure applied to streaming content. A large video becomes thousands of blocks under one root CID. Modify a block, recompute its parent, recurse upward.
echo "payload" | ipfs add -Q
# QmT5NvHnRqVzG8KkQW3jXJFvN7YxQvH9rP2sM1nB4cD5eF
ipfs cat QmT5NvHnRqVzG8KkQW3jXJFvN7YxQvH9rP2sM1nB4cD5eF
ipfs pin add QmT5NvHnRqVzG8KkQW3jXJFvN7YxQvH9rP2sM1nB4cD5eF
The difference from Git is scope. Git deduplicates inside a repo; IPFS deduplicates across the swarm. Two peers uploading identical genome datasets share the blocks physically, and bandwidth scales with similarity rather than size. Unlike HTTP range requests, disjoint blocks parallel-fetch from different peers.
Routing is the tax. Git clones carry everything they need. IPFS must discover which peer holds block H. Kademlia DHT handles discovery, degrading under churn; Bitswap floods requests with ratability scoring to recover reliability at the cost of first-block latency tied to network topology rather than local disk speed.
Pinning replaces automatic garbage collection. Nodes volunteer storage, so an unpinned CID eventually gets evicted for incoming blocks. Pinning declares intent — keep this indefinitely — but managed services (Infura, Pinata) are centralized servers with private SLAs, not consensus guarantees. If the pinning provider fails, the link dies even though the data exists somewhere in the swarm. The mitigation is a self-hosted cluster across separate clouds with libp2p replication and alerting on pin failure, which is operational discipline most teams under-budget for.
Verification is the payoff. Git trusts whoever you clone from. IPFS assumes adversarial peers: a malicious node serving corrupted blocks fails the hash check, gets discarded, and the request retries elsewhere. H ≠ SHA-256(bytes) is the entire trust model.
That model has a practical cost curve. Running IPFS nodes for a local CDN of permanently pinned static assets cut repeat-request latency from ~150 ms against external object storage to ~10 ms across a local mesh, with the first load served by a peer in another region and no egress bill. The trade is disk: redundancy is something you provision rather than rent. For high-bandwidth workloads — video, model checkpoints — the economics invert, because you own the storage and amortize the hardware over years instead of paying per byte served.
The honest limit is that pinning is a promise, not a protocol guarantee. Nothing in the swarm owes you availability. Treat managed pinning as a cache with an SLA, keep a second copy under a different provider or your own cluster, and make the application degrade to a CDN fallback rather than a dead link.
Mutable Names Over Immutable Data
All three systems fight the same tension. Humans want main, myapp:latest, /docs/guide. Machines want abcd1234, sha256:abc..., QmXyZ.... Git resolves it with refs as mutable pointers over immutable commits. Docker resolves it with tags pointing at layer chains, while still allowing :latest to be overwritten. IPFS refuses mutable names outright — new version, new CID, old links break on purpose.
The failure mode is a team problem, not a storage problem. git push --force orphans commits teammates already pulled. Overwriting myapp:latest means a CI pipeline with broken digest detection runs stale code. IPFS has no equivalent because rewriting a CID is impossible; broken links force explicit migration.
Operationalizing CAS:
- Never overwrite immutable identifiers: semantic version tags, pinned production CIDs, protected refs.
- Budget for GC: deleting a million blobs needs background processing, transaction limits, and monitoring.
- Measure the dedup payoff: CAS wins on read-heavy, high-entropy workloads. Low-churn systems pay complexity for nothing.
- Verify end-to-end: compute locally, compare, reject mismatches. TLS protects transit, not the payload.
Scope decides fit. Git fits software history: hundreds of reads per write, integrity non-negotiable, repos staying under 100 GB. Docker layers fit CI/CD: artifacts read thousands of times across parallel runners, written once per commit. IPFS fits archives: datasets, legal records, media libraries you never edit, only re-version. Don't force it on document stores or relational databases — both need efficient point updates, which append-only addressing cannot provide.
The reusable principle is that identifiers should encode trust. Traditional systems trust the server to deliver correct bytes. CAS verifies locally using the identifier itself, shifting security from infrastructure to mathematics. Apply it beyond files: content-hash database rows, digest-tagged API responses, config signed by its SHA-256 rather than its filename — the same reasoning that makes an import path a public API rather than a convenience. Every "trust me" replaced with "verify me" is one fewer supply-chain or corruption surface.
Make every piece of data its own certificate, and no coordinator is required.