CMD Guide
HomeSystem DesignScalable Systems (Advanced Topics)

What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing

Content-addressable storage (CAS) makes the address a function of the bytes — you run a cryptographic hash over the content and use the digest as the key, so the name is derived from the data and cannot drift from it; location-based addressing does the opposite, giving data a name (a path, a URL, a disk offset) that is assigned independently of the bytes and stays fixed while the bytes underneath are free to change.

That single design choice — is the name computed from the content, or assigned to a place? — is what produces every downstream property: deduplication, tamper-evidence, immutability, and location-independent retrieval on one side; mutability, human-readable names, and in-place updates (plus link rot) on the other.

The mechanism, step by step

A CAS write is a pure pipeline: address = H(content). Because H is deterministic, the same input always yields the same address, and (for a good hash) different inputs practically never do. Git is the cleanest real example — every blob, tree, and commit is stored under the SHA-1 of a small header plus its bytes. Here is exactly what Git computes for the string hello\n (the \n is a real newline byte, so the payload is 6 bytes):

  1. Build the object: "blob" + " " + "6" + "\0" + "hello\n" — the type, a space, the byte length, a NUL separator, then the raw content.
  2. Hash it: SHA-1("blob 6\0hello\n").
  3. The digest is the address: ce013625030ba8dba906f756967f9e9ca394464a. Git stores the zlib-compressed object at .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a.

Now trace three writes to see every CAS property fall out of that one rule:

WriteContent (bytes)Computed address = SHA-1(header+content)What the store does
1. a.txthello\nce013625…394464aNew address → write one object
2. copy.txt (identical bytes)hello\nce013625…394464aAddress already exists → store nothing new; both files reference the same object (dedup)
3. edit one letterhellp\nd7a963a6…81628048Different bytes → different address → a brand-new object; the old one is untouched

Write 2 is the whole point of CAS and the place the earlier draft used the wrong word: two identical inputs producing the same digest is a hash match, not a hash collision. A collision is the pathological case where different inputs hash to the same digest — the thing a cryptographic hash is designed to make infeasible. Dedup relies on matches; collisions would break CAS (see Pitfalls). Write 3 shows integrity for free: change one byte and the address changes completely (ce013625… vs d7a963a6…), so a stored object can never silently disagree with its own name — re-hash on read and compare.

diagram
diagram

Location-based addressing, and why it is the default

A path like C:\Users\Name\photo.jpg or a URL like https://example.com/img/photo.jpg names a slot. The filesystem walks directory entries (or DNS + the server's routing walks host and path) to reach that slot and returns whatever currently lives there. The name is assigned by a human or an allocator, never derived from the bytes, so: (a) you can overwrite in place and every existing reference silently sees the new version — ideal for a homepage or a mutable database row; (b) the same bytes copied to two paths are two independent objects with no notion that they are equal; and (c) if the slot moves or its host disappears, the name resolves to nothing — a 404, the canonical failure of location addressing (link rot).

Pitfalls

When to use it / when not to

Concrete signals that point to CAS: the data is write-once / rarely-mutated (build artifacts, packages, media, snapshots); you need tamper-evidence or reproducibility ("the artifact behind this hash is provably the one I tested"); many references share identical bytes and dedup pays off (backups, container layers); or you want location-independent retrieval across a distributed/decentralized fleet where any holder can serve the bytes.

Signals that point to location addressing: the data mutates in place and consumers must always see "current" (a homepage, a config file, a DB row); humans need to read, guess, or organize the names hierarchically; write latency matters and you can't afford a hashing step; or a single owner legitimately controls and moves the resource.

Trade-offs vs. the alternative

Choosing CAS over location addressing buys you free integrity checks, automatic dedup, immutable/verifiable references, and any-node retrieval. It costs you: a required mutable-name layer for "latest" (extra indirection and a second system to keep consistent), opaque non-human-readable addresses, hashing CPU on every write, version bloat plus GC, and a discovery mechanism (an index or a DHT) to find who holds a given hash. Choosing location addressing buys simplicity, in-place mutation, human-friendly names, and the fastest possible writes — at the cost of no integrity guarantee, no dedup, and brittle links that rot when things move.

Choose CAS when the content is effectively immutable and you value verifiable identity, dedup, or decentralized retrieval more than write speed and readable names. Prefer location addressing when content changes frequently in place, references must track the newest state automatically, and human-readable, fast, single-owner access is what you actually need. Most real systems combine them — an IPFS gateway URL (https://gateway/ipfs/{CID}) or a content hash embedded in a path gives you a readable, resolvable location wrapping a verifiable content address.

Takeaways


Re-authored and deepened for this guide. Sources: the Git internals model of objects (Scott Chacon & Ben Straub, Pro Git, ch. 10 "Git Objects"); the IPFS content-identifier (CID) and pinning docs (docs.ipfs.tech); the SHAttered SHA-1 collision result (Stevens et al., CWI/Google, 2017) and Git's SHA-256 transition plan; and the classic content-addressable-storage discussion in the DesignGurus system-design answers. Hash values in the worked example were computed with git hash-object.

🤖 Don't fully get this? Learn it with Claude

Stuck on What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing** (System Design) and want to truly understand it. Explain What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes