Skip to content
2024—2026 In production

Replacing a 20-year-old commission engine

A money-critical MLM commission engine, replaced on a cold cutover with no parallel run — and the four months of reconciliation that followed.

The commission engine's cycle screen: three steps — process, reverse and submit a cycle — over a table of end-of-period runs listing stage, cycle number, begin and end dates, status and the date each was run.
Cycle control and the end-of-period run history, the “Commit failed” rows included. Nothing on this screen is client data: no names, no amounts, no contact details.
Breaking-rank evaluation diagram: a director at the root with breaking rank EM, and three branches of the downline. A branch is drawn solid and ticked while each rank stays below the breaking rank, and dashed with a cross from the first rank that equals or exceeds it.
The rule that took finance to define, not the old SQL to read: a rank below the breaking rank passes, a rank equal to or above it stops the branch. Drawn for the rewrite.

The problem. Twenty years of commission rules living in accumulated SQL, with nested conditionals whose execution path depended on the year a plan had been configured. The source was readable; the intent was not. The person who designed it was unavailable.

The constraint that was not negotiable. A cold cutover. The old engine was switched off at 23:59 on the 20th of the month and the new one went live the same night, with no parallel run — so the first monthly cycle was part old engine, which could no longer be queried, and part new engine.

What did not work. Reading the old SQL to recover the rules. We stopped writing code and sat with the client's finance department to define the terms instead: what a generation is, what makes a director active, what happens when someone changes level mid-month. The hardest case was multi-level commissions paid to directors over successive generations below them, on a hierarchy that changes over time — a slowly changing dimension, with almost no clean history to validate against. Much of the work was done in Jupyter notebooks with pandas, and the production engine kept that shape for most of its life, holding its data in pandas. Later, the live recalculation that consultants check through the day moved to ClickHouse, to take its load off the production SQL Server the online store depends on.

The outcome, stated honestly. Before go-live, run against cycles the old engine had already calculated, the final version reproduced them to within about $100 over roughly $500,000 paid out — around 0.02%, and the evidence that our reading of the rules was right. That comparison has no sequel: the old engine was switched off the night the new one went live, so no cycle since then has a second engine to be checked against. In production the calculation held. What took about four months to settle was everything around it: individual reports, company reports and the payment file that did not fully agree; carry-overs and adjustments, which belong to the payment rather than to the calculation and had not been validated before go-live the way the engine had; and errors in the engine's input data, traced consultant by consultant. Every cycle was reconciled with finance before it was committed. Since then the monthly check is internal — the individual payments have to add up to the company reports — and it closes under a dollar. Written four-handed with Alejandro Cespón.

Four months of cycles with errors is the honest headline. The ~$100 residual was measured against cycles the old engine had already run; after the cutover there is no engine left to compare with, only the payments against the company reports.