PATTERN Cited by 1 source
Deterministic rule ordering¶
Deterministic rule ordering is the pattern for building a ranker / decider (e.g., "which of these two candidates is better?") out of a fixed-order list of rules plus a guaranteed-distinct terminal tie-breaker. Each rule is independently responsible for one question; rules are evaluated in order; the first rule that can differentiate the inputs wins; the terminal rule is chosen so it always breaks ties. Net effect: same input → same output, always, with no randomness and no hidden state.
Shape¶
def better(a, b):
for rule in ordered_rules: # operations-team-managed
outcome = rule(a, b)
if outcome != EQUAL:
return outcome
return terminal_rule(a, b) # guaranteed distinct
Each rule answers a single crisp question. Keep them simple — "prefer the path that visits sites with production capacity", "prefer the path with earlier deliverability". Rules that need to compare paths on multiple dimensions at once are a sign the rule list is wrong.
The terminal tie-breaker¶
The quality of the whole pattern lives or dies on the terminal rule. Canva's choice — total production-location distance to the customer, in metres — is instructive:
- Continuous real-valued quantity. Two sites are vanishingly unlikely to be equidistant down to the centimetre. Ties therefore effectively never happen.
- Aligned with other goals. Shorter distance means lower carbon emissions and faster shipping — the terminal rule isn't arbitrary, it's semantically good.
- Cheap to compute. It's already available in the graph.
If you can't find a real-valued tie-breaker, a deterministic hash over
a stable ID works — but it degrades explainability ("why did we pick
A? because hash(id_A) < hash(id_B)") and should be last resort.
Filters vs. rules — two-phase design¶
Canva splits constraints into two phases:
- Filters run during graph preprocessing and eliminate candidates that don't meet a hard criterion (e.g., "supplier can't produce this product" → edge flow set to zero).
- Rules run in the ranker and are generous with equality — they only differentiate when they must.
This keeps the hot path small. The ranker never has to check hard-constraint conditions that can be applied once up front.
Why determinism matters here¶
- Explainability. Combined with a per-decision log (see patterns/explainability-log), determinism means a support engineer can answer "why did order X ship from supplier Y?" exactly.
- Reproducibility. Replay a historical routing decision against a new decision engine and diff the output — you can A/B-test ranking changes.
- Debuggability. No "flaky" routing — two identical orders don't get different suppliers.
When you need non-determinism¶
Deliberate randomness (load shedding across equally good suppliers, randomized A/B assignment) should be introduced explicitly, not as an accident of unspecified tie-breaking. Example: use a deterministic seed per order so the same order still always maps to the same choice even when randomness is part of the ranking.
Seen in¶
- sources/2024-12-10-canva-routing-print-orders — Canva's Decision engine: ordered rule list edited by the operations team (add/remove/reorder), terminal rule = shortest total production-location distance; explicit "no randomness" guarantee.
Related¶
- patterns/explainability-log — determinism + logging together make "why?" answerable
- systems/canva-print-routing