Ashley Flowers

Work · A high-growth insurtech · February 2026 onward

Twenty-eight rules in two languages

Replacing a branching routing monolith with a declarative classification layer

What was happening

Support cases arrive from several channels and have to end up with the right team. Billing goes one way, claims another, a document request another, and the routing decision depends on a stack of attributes: who sent it, what it is about, which product it concerns, what channel it came in on.

The logic that made those decisions had grown to twenty-eight rules spread across three files in two different technologies. Part of it lived in a declarative automation flow, defined in XML. Part of it lived in hand-written code. They had been added to independently over a long period by people solving the problem in front of them, which is how every system of this kind gets built.

The symptom that brought it to me was a class of bug that nobody could reliably reproduce. A case would be routed as one thing by the routing process, and treated as a different thing by the job that merges duplicates. Same record, two components, two incompatible answers, and depending on timing you would get either outcome. Intermittent, inconsistent, and resistant to the usual approach of reading the logs and finding the mistake, because neither component was making a mistake. They were each correctly applying a different set of rules.

Two side effects made it worse. Any new routing rule required a code deployment, which meant a support operations question became an engineering ticket with an engineering lead time. And nobody could answer "why did this case go there" without reading two codebases.

What was actually wrong

There was no shared model of what a case is.

That sounds abstract and it is the entire problem, so it is worth stating concretely. Nothing in the system ever said "this case is of type X." Instead, each consumer independently re-derived a classification from raw field values at the moment it needed one, using its own copy of the rules. The routing flow had its interpretation. The merge job had its interpretation. The two sets of rules had been maintained separately and had drifted, because there was no mechanism that could have kept them in step and nothing that would fail if they disagreed.

So the split-brain bugs were not a defect in either component. They were the guaranteed output of an architecture where classification is an implicit, repeated, per-consumer derivation rather than a stated fact about the record.

Once I had that framing the rest followed. The question stopped being "which of the twenty-eight rules is wrong" and became "why does a case not know what it is."

What I did

I built a single classification layer and made everything else consume it.

One place decides. A classification service takes a case and stamps it with a routing classification. Every consumer, the routing flow and the merge job included, reads that classification instead of re-deriving one. Disagreement between components is now structurally impossible rather than merely discouraged, because there is only one answer and they are both looking at it.

The rules are configuration, not code. The classification logic is driven by metadata records rather than branching statements. Adding a routing rule is creating a record. Changing one is editing a record. Neither requires a deployment, neither requires an engineer, and support operations can make a routing change in minutes rather than filing a ticket and waiting for a release.

The service is a pure function. Attributes in, classification out, with no database reads or writes inside it. This was a deliberate design constraint and it is the one that paid off most. A pure function is unit testable without any scaffolding to create records, so the full rule set can be tested exhaustively and cheaply, and the tests run in a fraction of the time the old database-dependent ones did. The old logic was technically testable and practically was not, because every test needed a world built around it.

Blast radius is bounded by construction. A misconfigured rule can only misclassify cases matching its own pattern. It cannot take down routing generally. That property is what makes it safe to hand the configuration to non-engineers, and without it, "a non-engineer can change this" would have been a liability rather than a feature.

What I decided against

Rewriting the twenty-eight rules in one language. The tempting cheap fix: move the code-based rules into the flow, or the flow-based rules into code, and at least have them in one place. It would have taken a fraction of the effort and it would have eliminated the immediate split-brain bugs. I did not do it because it treats the two-technologies problem as the cause, when the two technologies were a symptom. Consolidate twenty-eight branching rules into one file and you have one file with twenty-eight branching rules, still requiring a deploy to change, still with no shared model, and the next consumer that needs a classification will do what every previous consumer did and derive its own. The bug class comes back the moment a third component appears.

Fixing the reported bugs. Each individual split-brain case was debuggable and fixable in an afternoon. I could have closed the tickets. They would have kept arriving, because every fix is a manual re-synchronization of two rule sets that have no mechanism keeping them synchronized, and the arrival rate is proportional to how often anybody touches routing.

A fully general rules engine. The other failure mode, in the opposite direction. Build enough configurability and you have written a programming language with a worse debugger, maintained by one person, understood by nobody. The classification layer handles the shape of decision this business actually makes. Anything genuinely novel is still code, deliberately.

What happened

The split-brain bug class is gone, not reduced, because the condition that produced it does not exist in the new design.

Routing rules became metadata records rather than code deploys, which moved an entire category of request out of the engineering backlog.

The part I did not anticipate is the part that mattered most. Having a stable, reliable statement of what each case is turned out to be a foundation other things could stand on. An automation for one high-volume case category became straightforward to build on top of it and has diverted more than two thousand five hundred cases from human triage. And when the AI case-summary pipeline was built later that year, it consumed the same classification rather than inventing a fourth interpretation of what a case is.

That is the argument for this kind of work in general, and it is hard to make in advance. A shared model does not announce its value at the moment you build it. It shows up as the reason the next three things were cheap.

What I would change

I would have written the migration as a dual-run with comparison logging rather than a cutover with tests. Running old and new classification side by side for a period, logging every disagreement without acting on either, would have produced a list of real divergences from production traffic. The test suite can only check the cases I thought of. Production generates the ones I did not.

I would also build the configuration UI earlier. "Support operations can add a rule without an engineer" was true from the start as a capability and was not true in practice for a while, because the interface was a metadata editor rather than something a support lead would choose to open. A capability that nobody uses is indistinguishable from a capability you do not have.

And I under-documented the classification taxonomy itself. The architecture is clean and the question "which classification should this new rule use, and why does it differ from the adjacent one" still routes to me. The code explains how classification works. Nothing explained why the categories are the ones they are, and that is the knowledge that leaves when a person does.


Stack. Salesforce Apex, Flow, custom metadata types, Service Cloud case management and Omni-Channel routing, Apex unit tests, Git-based CI/CD on GitHub Actions.

More case studies

The latency nobody could see

A speed-to-lead SLA that kept regressing, inside a managed package with no readable source

Human approval, on purpose

An AI triage loop that proposes and drafts, and never closes the ticket itself