F4.12 · part 2 of 3 · get & resolve
A Snowflake registry
With entries in their partitions, the store becomes a registry: hand it any branded id and it
resolves the whole picture in one call. The three-letter prefix names the partition, the lookup inside that
partition takes O(log₃₂ n) hops, and the Snowflake packed into the id is its
creation time — no timestamp column to join. An id from a namespace the store does not keep is rejected
before any lookup, the same edge check as the persistence lesson.
Resolve an id. Two are registered; one is from a namespace the store does not hold. Watch what comes back.
Resolve an id
Each lookup reads the prefix, finds the partition, searches its CHAMP, and decodes the Snowflake for the
creation time. A prefix with no partition — here TSK — returns not-found
without searching anything. Pick an id.
Branded id · select one
partition: users
resolved: 2026-05-31 13:35:19
One call returns where an entry lives, whether it is there, what the lookup cost, and when it was made. The id is the index, the router, and the clock at once.
Advanced: get, reject, and free timestamps
get/1 reads the prefix and looks for that partition. If the store holds no such
namespace the call returns :error immediately — the same idea as validating an
id at the edge in F4.08, so a key the store could never hold costs nothing to reject. Otherwise it searches
that one partition’s CHAMP, which is the O(log₃₂ n) descent: a few
node hops, flat as the partition scales.
The creation time comes for free. Because the Snowflake is part of the id, decoding the upper bits gives the
millisecond timestamp without storing a separate created_at — the registry can
report when an entry was made even though it never wrote that down. A present id resolves to its entry plus
its time; an absent id of a known namespace resolves to not-found after a real search; an id of an unknown
namespace never searches at all.
# get/1 — route, reject unknown namespaces, resolve with a free timestamp def handle_call({:get, id}, _from, store) do ns = binary_part(id, 0, 3) reply = case store do %{^ns => champ} -> case Champ.get(champ, id) do # O(log₃₂ n) descent nil -> {:error, :not_found} value -> {:ok, value, Snowflake.created_at(id)} # time from the id end _ -> {:error, :unknown_namespace} # no partition — reject, no search end {:reply, reply, store} end
a branded id
One opaque string from the caller.
its entry and its time
Routed, looked up in a few hops, dated from its own Snowflake.
Next: query by time range — using that same embedded time to pull every entry made inside a window.
References
Primary sources for this lab, and the lessons it assembles.
Sources
- Elixir —
binary_part/3— reading the namespace prefix to route. - Elixir — Patterns and guards — matching the partition or rejecting the namespace.
- Snowflake ID — Wikipedia — the timestamp packed into the id.
Related in this course
- F4.12 · Lab: build a branded CHAMP store — the lab hub.
- F4.07 · Identifiers, Snowflake & branded ids — decoding the creation time.
- F4.08 · Branded ids & persistence — rejecting an id at the edge.
- F4 · Algorithms & Data Structures