Skip to main content
adaptive distributed systems intent-based dynamic consistency in java 21

The Decision Matrix Implementation

4 min read Chapter 9 of 25
Summary

Decision matrix maps intent and health signals to...

Decision matrix maps intent and health signals to execution strategies SYNC, ASYNC, and OPTIMISTIC for distributed system design.

The Decision Matrix Implementation

The implementation of a decision matrix for evaluating intent and system health signals is a critical component of distributed system design. This section will delve into the details of creating a deterministic evaluator that maps intent and signals to a suitable strategy, ensuring consistency and availability in the face of varying system conditions.

Introduction to Decision Matrices

A decision matrix is a quantitative method or logic system used to evaluate and prioritize a list of options based on multiple criteria. In the context of distributed systems, decision matrices can be used to determine the optimal execution strategy based on intent criticality and system health. The decision matrix is essentially a table that maps different combinations of intent and health signals to specific execution strategies, ensuring that the system operates within defined consistency and availability bounds.

Intent Criticality and System Health

Intent criticality refers to the classification of business operation importance that dictates the minimum required consistency floor. System health, on the other hand, is a composite metric representing operational status, including CPU load, memory pressure, and network stability. The combination of intent criticality and system health signals determines the appropriate execution strategy for the system.

Execution Strategies

There are three primary execution strategies supported by the Dynamic Consistency Evaluator: SYNC, ASYNC, and OPTIMISTIC. Each strategy has its trade-offs in terms of consistency, availability, and performance. The choice of strategy depends on the intent criticality and system health, as outlined in the decision matrix.

SYNC Strategy

The SYNC strategy ensures linearizable consistency, where all operations appear to take effect instantaneously in a globally consistent order. This strategy is suitable for high-criticality intents where consistency is paramount, even if it comes at the cost of higher latency.

ASYNC Strategy

The ASYNC strategy provides sequential consistency, which may not guarantee instantaneous consistency but ensures that operations are executed in a consistent order. This strategy is used when the system health is degraded, and the primary goal is to maintain availability.

OPTIMISTIC Strategy

The OPTIMISTIC strategy relies on eventual consistency, which may lead to temporary inconsistencies but offers the best performance and availability. This strategy is suitable for low-criticality intents where consistency can be compromised for better performance.

Implementation

The implementation of the decision matrix evaluator is based on a pure function that takes intent criticality and system health as inputs and returns the appropriate execution strategy. The evaluator uses Java 17+ switch expressions for deterministic evaluation, ensuring that the function always returns the same output for the same inputs.

public record DecisionInput(IntentCriticality criticality, SystemHealth health) {}

public enum Strategy { SYNC, ASYNC, OPTIMISTIC }

public final class StrategyEvaluator {
    public static Strategy evaluate(DecisionInput input) {
        return switch (input.criticality()) {
            case HIGH -> switch (input.health()) {
                case GOOD -> Strategy.SYNC;
                case DEGRADED -> Strategy.ASYNC;
            };
            case LOW -> switch (input.health()) {
                case GOOD -> Strategy.OPTIMISTIC;
                case DEGRADED -> Strategy.ASYNC;
            };
        };
    }
}

Architecture

The architecture of the evaluator consists of four primary components: Signal Ingestor, Policy Engine, Strategy Router, and Feedback Loop. The Signal Ingestor is responsible for collecting intent and health signals from various sources, including Micrometer and Kafka. The Policy Engine evaluates the signals using the decision matrix and determines the appropriate execution strategy. The Strategy Router executes the chosen strategy, and the Feedback Loop verifies the consistency floor and adjusts the strategy as needed.

Conclusion

In conclusion, the decision matrix implementation is a critical component of distributed system design, ensuring that the system operates within defined consistency and availability bounds. By using a deterministic evaluator that maps intent and signals to a suitable strategy, developers can create robust and scalable systems that meet the demands of modern applications.

Sources

[1] https://blog.gaurav.cc/tags/policy-pattern/ [2] https://www.nected.ai/blog/rules-engine-design-pattern [3] https://www.waylay.io/articles/waylay-engine-one-rules-engine-to-rule-them-all