skip to content

In package and container registries, how does an immutable version differ from a mutable name such as an OCI tag or an npm dist-tag?

level: middleimportance: must knowfreq 60%

answer

  1. identity versus alias
  2. a pointer that can be re-aimed
  3. latest set on publish
  4. record the version or the digest

basics

~20 s

A version or digest names fixed content and never changes; an OCI tag or npm dist-tag is a pointer the registry lets you re-aim. Use the movable names for discovery and record versions or digests for builds and deploys.

solid answer

~40 s

Registries expose two kinds of names. **Fixed identities**: an npm `package@version` the registry never lets change, and an OCI manifest **digest**, a hash of the content. **Movable aliases**: the OCI distribution spec defines a tag as a human-readable pointer to a manifest, and one digest can carry zero, one or many tags; pushing a manifest to an existing tag moves it, and Harbor's docs say repeated pushes of a tag are allowed by default. npm's `dist-tags` map names such as `latest` or `next` to versions; publishing sets `latest` unless another tag is named. Because aliases move, anything that must be reproducible, such as a lockfile, a deploy or an audit record, stores the version or digest, while the alias serves humans and default installs.

code

json · 17 lines
json
{
  "name": "@platform/date-utils",
  "dist-tags": {
    "latest": "2.4.1",
    "next": "3.0.0-beta.2"
  },
  "versions": {
    "2.4.1": {
      "version": "2.4.1",
      "dist": { "integrity": "sha512-..." }
    },
    "3.0.0-beta.2": {
      "version": "3.0.0-beta.2",
      "dist": { "integrity": "sha512-..." }
    }
  }
}

go deeper

for a junior

Recall which names are fixed (an npm version, an image digest) and which can move (an image tag, an npm dist-tag such as latest).

for a middle

Explain how an OCI tag is a pointer to a manifest that a push re-aims, how npm sets latest on publish, and why identities belong in lockfiles and deploys.

for a senior

Show you treat a version-shaped image tag as mutable until the registry freezes it, and that you pin deploys to digests or versions rather than re-reading aliases.

for a principal

Decide which aliases an organisation offers, what each may point at, and which registries must freeze version-shaped tags so names that look like releases behave like releases.

## Two layers of naming Every registry that serves versioned artifacts ends up with two kinds of name: - **Identity**: a name that always means the same content. In npm that is `package@version`; in an OCI registry it is the manifest **digest** (for example `sha256:...`), computed from the manifest's bytes. - **Alias**: a name that points at an identity and can be **re-aimed**. In an OCI registry that is a **tag**; in npm it is a **dist-tag**; in a Maven repository the `<latest>` and `<release>` elements of artifact-level `maven-metadata.xml` play the same role. Confusing the two is the root of most "it worked yesterday" incidents: a team records an alias where it needed an identity. ## OCI registries: tags move, digests do not The OCI distribution spec defines a **tag** as "a custom, human-readable pointer to a manifest", and notes that a manifest digest may have zero, one or many tags. A client pushes a manifest with `PUT /v2/<name>/manifests/<tag-or-digest>`; unless the registry adds its own rule, pushing to an existing tag simply points that tag at the new manifest. Harbor's documentation describes the default plainly: users can repeatedly push an artifact with the same tag, the tag migrates to the new artifact, and the previous artifact becomes tagless. The upstream registry code does not enforce a fixed mapping between a tag and a digest. Freezing tags is therefore an **extra registry setting** (Harbor's tag immutability rules), not something tags do by themselves. The digest stays reliable because it is derived from the content. ## npm: versions are fixed, dist-tags are not The npm registry stores a **packument** per package, which lists every version and a `dist-tags` map: - A **version** is immutable: npm's policy says that once a `package@version` is used it can never be used again, even after an unpublish. - A **dist-tag** is an alias to a version. Publishing sets `latest` to the new version unless another tag is given, and installing a package with no version or tag installs `latest`. - Other than `latest`, no tag has special meaning to npm; `next` is a common convention for an upcoming version. - Tags share a namespace with versions, so a tag that parses as a semver range, such as `v1.4`, is rejected. Each version entry carries `dist.integrity`, a hash of the tarball, so a consumer can check that the bytes behind a version are the bytes it recorded. ## Side by side | Format | Fixed identity | Movable alias | Who moves the alias | |---|---|---|---| | OCI registry | manifest digest | tag | any push to that tag, unless the registry freezes it | | npm registry | `package@version` | dist-tag (`latest`, `next`) | publish, or an explicit dist-tag change | | Maven repository | `groupId:artifactId:version` release | `<latest>`, `<release>` in `maven-metadata.xml` | each deploy updates the metadata | ## Where aliases bite Aliases are useful precisely because they move, and the incidents come from forgetting that: - A deployment that names `myapp:latest` may re-read the alias whenever a node pulls, so two replicas started an hour apart can run different builds. - A backport published to an older npm line, without naming another tag, moves `latest` backwards for everyone who installs with no version. - A version-shaped tag such as `2.4.1` looks like a release, but on a registry without immutability rules it is still an alias, and a second push re-points it. - In Artifactory's Docker repositories, overwriting a tag is allowed, and **Docker Tag Retention** decides how many of the overwritten revisions are kept, which helps recovery but does not stop the move. The OCI distribution spec also lets a registry accept tags as `tag` query parameters when a manifest is pushed by digest, answering with an `OCI-Tag` header for each tag it accepted, so a registry can apply its own rules to each name separately. ## The working rule 1. Use aliases for **discovery**: "what is the current stable build?" 2. Record identities for **anything that must be repeatable**: lockfiles, deployment manifests, promotion records, audit evidence. 3. Never let a version behave like an alias. A version-shaped container tag such as `2.4.1` is still only a tag unless the registry freezes it, so registries that serve releases should freeze version-shaped tags and leave true aliases like `latest` mutable. An alias moving is not a defect; it is the alias doing its job. The defect is a deploy that re-reads the alias later and silently picks up different content.

  • If a container tag can move, how does a deploy stay reproducible?
    The deploy records the manifest digest the tag resolved to at release time and pulls by that digest afterwards. The tag stays useful for humans and for finding the newest build, but the digest is what guarantees the same bytes, because it is computed from the content rather than assigned.
  • Why does the npm registry reject a dist-tag named v1.4?
    Dist-tags share a namespace with version specifiers, because both go in the same slot of `name@...`. `v1.4` parses as a semver range, so it would be ambiguous. npm's docs suggest tags that do not begin with a number or the letter v.

A version is a printed edition of a book with its own ISBN: once printed, that edition never changes. A dist-tag or container tag is the shop's 'current bestseller' shelf label, which staff move to a different book whenever they choose.

  • A version-shaped container tag like 2.4.1 can never be overwritten.
  • npm's latest dist-tag always points at the highest version published.
  • Pinning to latest is fine because the registry keeps it stable.
  • A digest is just another tag the registry assigns at push time.
  • Moving a dist-tag changes the contents of the version it pointed to.