Content-addressed storage

What it is

Content-addressed storage names an object by a digest computed from
its contents. A client looking up an object supplies that name,
which the storage system resolves to a location. One common
representation couples the digest algorithm to the encoded result. A
receiving client can recompute the digest and compare it before
using the object. Changing a file ordinarily produces a new address,
while storing the exact same representation again can return the
same address. The storage system still needs places to keep replicas
and indexes telling it where to find them.

The distinction becomes important once a system puts structure
around the bytes. Git hashes a structured object that includes a
header identifying its type and length. The name of a Git blob
consequently need not equal the bare digest of its file contents. In
the Open Container Initiative image format a descriptor names a
particular representation of a component and can record its size and
media type. An image manifest in turn names the objects it depends
on. A digest of a compressed layer is a claim about that stored
compressed representation. Decompressing it may yield bytes that
another part of the image format identifies separately.

A service can offer mutable names beside immutable object
identities. A channel called `stable` can move from one release
manifest digest to another. A client pinning the digest gets the
named version when it can be fetched, while a client following the
channel gets whatever the publisher currently associates with it.
The channel can be useful for discoverability. A deployment or an
audit that needs stable evidence can record the resolved identity at
the time it made the decision.

Why it matters

Caches can keep verified data under a digest without checking every
time whether the name now means something else. A browser receiving
a new page can discover an updated stylesheet at a different path.
It can also keep the previously cached stylesheet available to old
pages until they are replaced. That reduces coordination between
publication and expiration. During a partial update, a client that
already has the older document can still request the resource that
document describes, provided the origin or cache retains it.

Storage systems can exploit equality. If two image manifests refer
to the same layer digest, the registry can store one copy and
distribute it to clients that do not have it. Git can likewise
reference an unchanged subtree from more than one commit. That does
not mean every similar document takes no extra space. The hash
compares the underlying representation. Reordering keys in a JSON
object or changing its compression may produce new bytes even though
an application interprets the payload the same way. If reuse depends
on semantically equivalent output, choose a stable encoding and
specify it as part of the protocol.

Integrity and authenticity are distinct concerns. Matching the
digest gives confidence that the bytes available to the reader are
the bytes referred to by a particular descriptor, under the
assumptions of the algorithm. Establish the choice of descriptor,
the requirements for safe execution and the client’s access
separately. A trusted manifest, verified signature and access policy
can establish those other parts of the decision. Record what was
checked so that a correct hash is not interpreted as a blanket
approval.

What it looks like in practice

Consider a web release that contains an HTML document and an image.
The build hashes the image and gives its URL a suffix derived from
that identity. It then writes the exact URL into the HTML. The
release uploads all objects that the new document refers to, checks
those objects from the serving path and publishes the new document
after its dependencies are available. Keep the old image for at
least as long as the older document can still be used. A reader
retrieving either version can verify that the same URL continues to
carry its expected image. The public web address of the HTML can
stay stable as the referenced assets change.

A container release applies a related idea with different
boundaries. Build an image once and record the manifest digest. Test
that artifact, associate the test result with its digest and ask
each environment to pull the same digest. For a multi-platform
image, record whether the identifier belongs to an image index or a
concrete platform manifest. The runtime may select a
platform-specific child from the index. When a report names only a
mutable image tag, resolving that tag after the incident may lead to
a newer artifact than the one the operator is trying to inspect.

The Engineer ApS credits describe this site's single stylesheet
bundle and its content fingerprint. That is an example at the URL
boundary. A page references the bundle version that was built for
it, so separate pages can share the file and a newer bundle can have
a new address. A complete general-purpose object store has
additional responsibilities, including verifying incoming uploads,
controlling access and reclaiming objects that are no longer
referenced.

Where it goes wrong

Publishing a mutable pointer before its objects are present creates
a dangling reference. Readers can see the new pointer even though
some data it names is missing. Stage dependencies first, and test
them through the same path a reader uses. Tie retention to all
published and staged manifests, including release versions that are
still eligible for rollback. Reclaiming an object merely because the
latest manifest stopped mentioning it can break other versions.

Some pipelines recalculate a digest from a decoded value and compare
it with a digest of the encoded wire object. Those comparisons
answer different questions. Verify the exact representation named by
the format and record versioned canonicalisation rules where a
format deliberately hashes a structured value. Test equivalent
encodings and altered object types so the implementation proves
where equality begins and ends.

Shortening identifiers is useful in a display label. In a storage
lookup, a shortened digest loses collision resistance and can become
ambiguous as the data set grows. Decide whether a short string is a
human hint, an abbreviation expanded by an unambiguous lookup or an
actual addressing rule. Include the digest algorithm in
interoperable references, and check both declared size and
recomputed digest when the format provides them.

Further reading

  * OCI image descriptor specification explains how descriptor
digests identify image components.

  * Git internals and objects shows how Git turns object
representations into identifiers.

  * Docker image pulls documents pulling an image by an immutable
digest.

hThis page on the web	URL:https://engineer.company/glossary/content-addressed-storage/	engineer.company	70
