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

Execution Strategies

3 min read Chapter 10 of 25
Summary

Dynamic Consistency Evaluator adjusts consistency models and execution...

Dynamic Consistency Evaluator adjusts consistency models and execution strategies based on real-time system metrics and intent importance.

Introduction to Execution Strategies

The Dynamic Consistency Evaluator is a crucial component in distributed systems, enabling the dynamic adjustment of consistency models and execution strategies based on real-time system metrics and intent importance. At its core, this evaluator must implement concrete execution paths for Linearizable, Optimistic, and Deferred consistency. In this section, we will delve into the implementation details of these strategies, exploring their characteristics, advantages, and use cases.

Linearizable Execution Strategy

Linearizable execution ensures that all operations appear to take effect instantaneously in a globally consistent order. This strategy is particularly useful when high intent criticality and good system health are present. The Linearizable strategy can be implemented using a synchronous path, where the system blocks until a command is acknowledged by a quorum, ensuring the highest consistency floor.

public record Linearizable(KafkaTemplate<String, Object> template) implements ExecutionStrategy {
    @Override
    public ExecutionResult execute(Intent intent) {
        try {
            // Synchronous wait for producer acknowledgement (acks=all)
            template.send("intent-topic", intent.key(), intent).get(5, TimeUnit.SECONDS);
            return new ExecutionResult(Status.COMMITTED, intent.id());
        } catch (Exception e) {
            throw new ConsistencyException("Failed to meet linearizable floor", e);
        }
    }
}

Optimistic Execution Strategy

Optimistic execution is used for low criticality intents when system health is good, aiming to minimize latency. This strategy assumes success and returns a result immediately, while triggering asynchronous validation and persistence. However, it requires careful consideration of potential conflicts and errors.

Deferred Execution Strategy

Deferred execution is an asynchronous path where an intent is placed into a durable buffer (e.g., Kafka) and the client is immediately acknowledged with a ‘pending’ status. This strategy is suitable for high availability scenarios, especially when system health is degraded or intent criticality is low.

public record Deferred(KafkaTemplate<String, Object> template) implements ExecutionStrategy {
    @Override
    public ExecutionResult execute(Intent intent) {
        // Fire and forget - client receives 'Accepted'
        template.send("intent-topic", intent.key(), intent);
        return new ExecutionResult(Status.ACCEPTED, intent.id());
    }
}

## Decision Matrix for Execution Strategies
The choice of execution strategy depends on various factors, including system health, intent criticality, and consistency requirements. The following decision matrix outlines the strategy selection process:

| Health Status | Intent Criticality | Strategy Selected | Consistency Model |
| :--- | :--- | :--- | :--- |
| Healthy | High | SYNC | Linearizable |
| Healthy | Low | OPTIMISTIC | Sequential/Eventual |
| Degraded | High | ASYNC | Deferred (Eventual) |
| Degraded | Low | ASYNC | Deferred (Eventual) |
| Partitioned | Any | REJECT/ASYNC | Dependent on CAP choice |

## Conclusion
In conclusion, the implementation of Linearizable, Optimistic, and Deferred execution strategies is crucial for achieving dynamic consistency in distributed systems. By understanding the characteristics and use cases of each strategy, developers can design and implement efficient and scalable systems that meet the required consistency and availability standards.

## Sources
[1] PACELC Theorem
[2] Kafka Documentation