Insights / Engineering

Designing a Multi-Level Calculation Engine That Explains Why Results Fail

Humalligence April 07, 2026 5 min read
Futuristic Engineering Center

Most systems today are very good at giving answers. Very few are good at explaining them.

If you’ve ever built a scoring system, risk model, eligibility engine, or analytics pipeline, you’ve likely faced this:

  • The final result is “Failed”
  • But no one knows why

And that’s where things break down:

  • Users lose trust
  • Debugging becomes painful
  • Business teams keep asking questions

In one of our recent projects, we had to design a multi-level calculation engine where each level depended on the previous one, more importantly, we had to trace failures all the way back to their root cause.

This blog breaks down how to design such a system.

The Problem: Results Without Explainability

Let’s say your system has 4 levels:

  • Level 1: Raw data checks
  • Level 2: Derived metrics
  • Level 3: Aggregated scoring
  • Level 4: Final classification (Failed / Good / Advanced / Best in Class)

Now imagine: Level 4 = Failed

But why?

Possible reasons:

  • A single input field failed validation
  • A derived metric was below threshold
  • Aggregation logic weighted something incorrectly

Without traceability, you're blind.

Core Idea: Make Calculations Traceable, Not Just Executable

Instead of designing calculations like this:

final_score = calculate_level4(data)

Design them like this:

result = {
    "value": final_score,
    "status": "Failed",
    "trace": {
        "level_3": {...},
        "level_2": {...},
        "level_1": {...}
    }
}

Every level should return:

  • value
  • status
  • metadata
  • failure reasons (if any)

Designing the Multi-Level Flow

Think of it as a pipeline: Level 1 → Level 2 → Level 3 → Level 4

But instead of passing only values, pass context objects:

class CalculationResult:
    def __init__(self, value, status, reasons=None, meta=None):
        self.value = value
        self.status = status
        self.reasons = reasons or []
        self.meta = meta or {}

Now each level:

  • consumes previous result
  • adds its own reasoning
  • propagates failures forward

Failure Propagation Strategy

Key design decision: Should failure at Level 1 automatically fail Level 4?

Two approaches:

  1. Hard Fail Propagation: If any level fails → final result = Failed. Simple, strict, easy to reason.
  2. Weighted / Conditional Propagation: Some failures are tolerable. Final result depends on scoring thresholds.

Example:

if level_2.score < 50:
    reasons.append("Low derived metric score")

This gives flexibility but requires careful design.

Storing Calculation Logic (Dynamic vs Static)

Option 1: Static (Code-based)

Faster • Easier to debug • Harder to modify

Option 2: Dynamic (DB-driven)

{
  "field": "revenue",
  "condition": "<",
  "threshold": 1000,
  "failure": "Revenue too low"
}

Pros: Business-configurable, no redeploy
Cons: Debugging complexity

👉 Hybrid approach works best in real systems.

Debugging & Observability

This is where most systems fail.

Add:

  • Structured logs per level
  • Unique calculation IDs
  • Store traces (even temporarily)

Example output:

{
  "final_status": "Failed",
  "reasons": [
    "Level 2: Revenue too low",
    "Level 1: Missing transaction data"
  ]
}

Now: Devs can debug • Business teams understand • Users trust the system

Performance Considerations

Traceability adds overhead. Optimize by:

  • Avoiding deep copies of large objects
  • Storing only failure paths (not everything)
  • Using lazy evaluation where possible

Key Takeaways

  • Don’t just compute results explain them
  • Treat calculations as data + context, not just functions
  • Design for failure tracing from day one
  • Balance flexibility (dynamic rules) with maintainability
  • Observability is not optional, it’s core to the system

Start the Conversation

If you are a technology or engineering leader wondering when the right time is, what the right structure looks like, or whether the economics work at your scale, those questions are answerable. Not in a whitepaper, but in a direct conversation with engineers who don't just advise on capability centres, but actively build and operate them.

[email protected]

No proposals. No scope documents. Just a direct conversation.