Consistency Models Explained Simply

Consistency models describe how a distributed system presents updates to readers. Understanding these models helps you select the right datastore and set correct expectations for clients.

Consistency Models Explained Simply#

Consistency models describe how a distributed system presents updates to readers. Understanding these models helps you select the right datastore and set correct expectations for clients.

Strong Consistency#

All reads see the latest write. This is the simplest model to reason about but often requires coordination across replicas, which increases latency.

Eventual Consistency#

Replicas converge over time. Reads may return stale data, but availability and scalability improve.

Causal Consistency#

Preserves the order of causally related operations. If event B depends on event A, all readers will see A before B.

Read-Your-Writes and Monotonic Reads#

Client-centric guarantees such as:

  • Read-your-writes: a client sees its own updates.
  • Monotonic reads: once a value is seen, later reads do not go backward.

These guarantees can be layered on top of eventual consistency with session tracking.

Tradeoffs in Practice#

Model Latency Availability Complexity
Strong Higher Lower Moderate
Eventual Lower Higher Higher
Causal Moderate High High

Spring Boot Example: Consistency-Aware Reads#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@RestController
@RequestMapping("/profiles")
public class ProfileController {
    private final ProfileService profileService;

    public ProfileController(ProfileService profileService) {
        this.profileService = profileService;
    }

    @GetMapping("/{id}")
    public ProfileView getProfile(@PathVariable String id,
                                  @RequestHeader(value = "Consistency", required = false) String consistency) {
        ConsistencyLevel level = ConsistencyLevel.from(consistency);
        return profileService.getProfile(id, level);
    }
}

Summary#

Consistency models are a spectrum. Choose strong consistency for correctness-critical workflows and eventual or causal consistency when availability and scalability dominate.

Contents