Creating a branch and changing a branch are different jobs. A branch can start by pointing at the same data as its parent. The moment either branch writes, that shared ownership needs a rule.

RamusDB’s fresh source change makes that rule concrete: its SET path updates exclusively owned tables in place, then copies from the first shared table downward. Creating a branch retains the existing root. [1][2] I find that more useful to understand than a branch-creation timing headline.

Draw the version before changing it

Imagine a tiny tree. The root points to a left subtree and an untouched right-hand value. Two branch names initially point to that same root. A write changes a leaf on the left.

Two branch names initially share one root. After a left-leaf update, main keeps the old root and old leaf; dev has a new root and left node, while the right sibling remains shared.

Original immutable-tree illustration. Orange marks the replacement path; the shared sibling remains unchanged. This is not a RamusDB memory measurement. Image by Shivam Dwivedi.

An immutable representation makes the rule easy to see. Save this as demo.py and run python3 demo.py. It needs only Python’s standard library.

from dataclasses import dataclass, replace @dataclass(frozen=True) class Node: left: object right: object main = Node(Node("old", "neighbor"), "untouched") branch = main assert branch is main branch = replace(branch, left=replace(branch.left, left="new")) assert main.left.left == "old" and branch.left.left == "new" assert branch.left is not main.left assert branch.right is main.right print("main:", main.left.left, "branch:", branch.left.left) print("untouched sibling shared:", branch.right is main.right) bad_main = {"left": {"value": "old"}} bad_branch = bad_main.copy() bad_branch["left"]["value"] = "new" assert bad_main["left"]["value"] == "new" print("shallow-copy main:", bad_main["left"]["value"]) 
main: old branch: new untouched sibling shared: True shallow-copy main: new 

The first assertion establishes the initial sharing. The later assertions check both values and identities: the changed subtree differs, while the untouched sibling is still shared. The final example deliberately breaks isolation with a shallow dictionary copy. Copying the outer dictionary leaves its inner dictionary shared and mutable. Both branch names can still reach the object that was edited. Oops.

Sharing is safe only while writes respect it

In the toy tree, I replace every node on the route to the changed leaf. The real engine can do less work when an upper part of that route already belongs exclusively to the writer. Its ownership counts let it distinguish that exclusive prefix from the shared suffix. [2]

That distinction also explains why “copy on write” need not mean “copy the entire database.” Unchanged subtrees can remain reachable from several roots. The task is to prevent a write from altering a node another live version still needs.

There is a second obligation: failure must preserve the previous version. RamusDB’s checked test file includes allocation-failure cases and checks that the other owner’s physical digest stays unchanged. [3] I inspected those tests; I did not execute the Zig suite. My Python check establishes the little tree’s behavior, without validating RamusDB’s allocator or reference counts.

What a branch does not buy

The repository describes an experimental in-memory database with Redis-compatible commands, without persistence or authentication. [1] I would keep those boundaries beside any evaluation. Branch isolation does not imply crash recovery, a merge operation, or a production Redis replacement.

The useful question for a branching store is therefore specific: after changing one branch, which values and shared objects must remain unchanged in every other branch? A successful branch command alone cannot answer it.

References

  1. Adilet Sarsembayev and contributors, RamusDB overview.

  2. RamusDB contributors, engine ownership and SET implementation.

  3. RamusDB contributors, shared-suffix correctness tests.

Asset credits

Original explanatory figure and example, CC BY 4.0. Credit: Shivam Dwivedi. No third-party image assets.

AI disclosure

AI was used to draft the article.