Part 3 of 12 · 2 min read
Pointers, not copies: how rollback actually works
Production is a pointer to an immutable release; rolling back just moves the pointer.
Think of a bookmark in a book versus photocopying every page you read. Moving the bookmark back to page 40 costs nothing and is instant; it only works because the book's pages themselves never change underneath it.
In plain words: because each release manifest is immutable, an environment like production can just be a pointer to one release id, and rolling back is simply moving that pointer to the previous id rather than reconstructing or re-editing anything.
A worked example. Publishing a release and promoting it to prod sets the pointer to that release's id. Promoting a second release moves the pointer again. Rolling back then moves prod's pointer straight back to the first release id — and both manifests are still sitting in the registry afterward, exactly as they were published, ready to be pointed at again if needed.
The key lines.
# from code/mini-versioning/versioning.py
def promote(self, env, mid):
if mid not in self.store: raise KeyError("unknown release")
self.history.append((env, self.ptr.get(env), mid)); self.ptr[env] = mid
stack = self._stack.setdefault(env, [])
if not stack or stack[-1] != mid: stack.append(mid)
def rollback(self, env):
stack = self._stack.get(env, [])
cur = stack.pop(); prev = stack[-1]
self.ptr[env] = prev
return prev
Read it as: promoting pushes a release id onto a stack and moves the pointer to it. Rolling back pops the current one off and moves the pointer to whatever is now on top. Nothing about the manifests themselves is ever touched. Only which one the pointer currently names changes.
Immutable, pointer
Immutable means a manifest is never edited after it is published; a pointer is a named reference, like prod, that points at one specific release id and can be moved to another.
Example: the rollback above, which only reassigns what prod points to, never rewrites either manifest.