"In enterprise commerce, totals don't drift because someone forgot algebra. They drift because reality changes: promos expire, eligibility changes when an address arrives, catalog data updates, substitutions happen, and returns unwind prior discounts. When someone asks "why did the total change?" you need more than narration. You need evidence - a trail of facts you can replay and a pure computation that deterministically produces the same result."
"This is not an argument for (or against) event sourcing. It's a smaller, more practical pattern: record the decisions your system makes as immutable facts, then compute the answer from those facts with pure functions. When you do that, "what happened?" becomes "run the same computation over the same facts." You stop guessing, and you stop doing archaeology in logs."
"Imagine a cart where the system makes a series of decisions over time: items come and go, promotions are either accepted or rejected for specific reasons, and restrictions may only become knowable until context is provided. At checkout time you need the current totals, but you also need the story that makes the totals defensible later. If you only persist the final state, you can often show the number, but you can't reliably explain it."
Enterprise commerce totals change due to real-world events: promotions expiring, eligibility shifts, catalog updates, substitutions, and returns. Rather than storing only final state, systems should record immutable facts as decisions occur, then compute answers deterministically using pure functions. foldLeft in Scala provides a safe, predictable way to walk through collections left-to-right without relying on recursion. This pattern enables complete auditability—when totals are questioned, the same computation replayed over the same facts produces identical results. This approach transforms troubleshooting from log archaeology into reproducible computation, making totals defensible and explainable.
Read at Medium
Unable to calculate read time
Collection
[
|
...
]