It’s the first morning of a new fiscal year. A rep opens the CRM and finds that several of their best accounts now belong to someone else. They are going to ask exactly one question: why?
If your territory engine can answer that in a single line, you’re in good shape. If the answer takes an engineer and an afternoon in the logs, the matching logic could be perfect and people still won’t trust it.
At small scale, deciding who owns which account is a spreadsheet. At large scale it’s a system with millions of accounts, thousands of rules, and a planning deadline that doesn’t move. This is how I think about that system, without vendor specifics.
What the engine works with
The engine takes in accounts, rules, and people. Accounts are the companies being assigned, along with the attributes rules look at: geography, industry, size, existing relationships. Rules are statements the sales operations team writes, like “enterprise accounts in this region go to this territory”, each with a priority, effective dates, and its own exceptions. People means territories, the reps who hold them, and how much each rep can carry.
The decision I’d make first is to keep rules in data. Operations teams change rules constantly during planning. If every change needs an engineer and a deploy, your planning cycle moves at the speed of your release process, and nobody on the sales side will thank you for that.
Four steps, and only one of them writes
- Match each account against every rule that applies, pick the winner by priority, and record which rule won and what it beat.
- Validate the result as a whole. Is any account unassigned, or assigned twice? Is any territory far over capacity?
- Dry run: produce the full result without changing anything, and show what would move compared with today.
- Publish the approved result to the CRM in controlled batches.
The first three are safe to run as often as anyone likes. That’s deliberate, and it shapes most of the design.
Same inputs, same answer
Matching has to be deterministic. Give it the same accounts and the same rules and it must produce the same assignments every time. So no dependence on processing order, on which worker picked up which batch, or on the time of day. When two rules tie on priority, there needs to be a written tie-break. “Whichever loaded first” doesn’t count.
Everything downstream assumes the matching is deterministic. A diff between two dry runs only means something if the thing you changed is the only thing that changed.
Keep the reason next to the answer
For every assignment, store the rule that produced it and the rules it beat. After any planning cycle the first question is “why did this account go there?”, and answering it should be a lookup.
One line of that explanation could look like this:
Account: Northwind Traders (Germany, Manufacturing, 4,200 employees)
Assigned: Territory DACH-Enterprise-03
Because: Rule 118 "Enterprise, DACH region" (priority 20, lower wins)
Beat: Rule 407 "Manufacturing, EMEA" (priority 55)
When a rep asks why an account isn’t theirs, that’s the whole answer. It also turns arguments about the engine into arguments about rules, which is where they belong. If Rule 407 should have won, that’s a priority change operations can make and rerun without anyone from engineering in the room.
Dry runs are what planners actually use
A planning team will run the engine dozens of times before they publish once. Each run should be quick, and its output should compare cleanly with the last one. The diff view, showing which accounts would move and which rule moved them, matters more to planners than the final write ever will.
Most of the speed comes from partitioning. Accounts in different regions rarely affect each other, so split the work along those boundaries. Partitions run in parallel, and when one fails you rerun that region alone instead of the whole book.
Publish like the CRM is fragile
Because it sort of is. Changing account ownership sets off sharing recalculations and notifications, plus whatever automations other teams have hung off the owner field. Write in batches and throttle. Make the publish resumable, so a job that dies halfway doesn’t leave the field half-assigned with no clean way to pick up where it stopped.
Manual overrides need an expiry date
Some accounts are assigned by hand and must stay put, for reasons that never make it into a rule. Model those overrides as the highest-priority rule, with an owner and an expiry date. They then show up in the same explanation as every other assignment, and they don’t quietly live forever. Without an expiry, overrides pile up until nobody remembers why most of them exist.
Most wrong assignments are data problems
In my experience, when an account lands in the wrong territory, the engine usually did exactly what it was told. The account had the wrong country, or it existed twice, or nobody had filled in its industry. Cleaner inputs fix more errors than cleverer matching does.
I led a territory assignment engine at LinkedIn, and if I were building one again, two things would come before any tuning of the matcher.
The first is a “could not match” report. Every account the engine can’t place comes out in a list with the reason attached, in terms the data team can act on. They fix the inputs, and the next run is cleaner. That only works if the report names the record and the field that tripped it.
The second is the dry-run diff. Planners see every account that would move before anything is published, so the people who know the business catch mistakes before reps ever see them.