Skip to content

Consistency models

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Aerospike supports two consistency models: AP (Available, Partition-tolerant) and SC (Strong Consistency). Understanding when to use each is critical for your application.

AP mode (default)

Available, Partition-tolerant — Prioritizes availability over consistency.

  • Reads always succeed if any replica is reachable
  • The default WritePolicy.commitLevel is COMMIT_ALL. At this commit level, write calls require all replicas to acknowledge; a replica write failure causes the call to fail even if the master was updated
  • During network partitions, both sides remain writable
  • Conflicts resolved by “last write wins” (LWW)

Best for: Session stores, caches, real-time analytics, high-availability requirements.

SC mode (strong consistency)

Strong Consistency — Prioritizes consistency over availability.

  • Reads return the most recent committed write (depending on ReadModeSC value)
  • Writes require acknowledgement by all replicas
  • During partitions, if the minority partition has all roster replicas in it, it serves the data and the majority partition is not available
  • No conflict resolution needed (linearizable)

Best for: Financial transactions, inventory systems, any “single source of truth” requirement.

Choosing a consistency model

FactorAP ModeSC Mode
AvailabilityHigherLower during partitions
Read latencyLowerSlightly higher
Write durabilityEventually consistentImmediately consistent
Conflict handlingAutomatic (LWW)Not needed
Use caseCaching, sessionsTransactions, inventory

How the SDK applies consistency

The Developer SDK does not treat AP and SC as a single global switch. Each namespace on the cluster is either AP or SC, and the SDK picks the matching policy bundle for every operation on that namespace.

When you call session.update(...), session.query(...), or other builders, the SDK reads the namespace mode from the cluster partition map and resolves settings with behavior.getSettings(..., scMode). AP namespaces use AP-scoped selectors (for example .reads().ap()); SC namespaces use SC-scoped selectors (for example .reads().cp()).

You can inspect a namespace with Session.isNamespaceSC(String).

Configuring consistency

For most applications, one session with Behavior.DEFAULT is enough. The SDK routes AP settings to AP namespaces and SC settings to SC namespaces.

Use Behavior.STRICTLY_CONSISTENT (Python built-in) or a derived behavior with SC read selectors (Java) when you need linearizable reads on SC namespaces. See Behaviors for full profiles and derivation patterns.

import com.aerospike.client.sdk.policy.Behavior.Selectors;
import com.aerospike.client.sdk.policy.ReadModeSC;
// Mixed cluster: DEFAULT picks AP vs SC settings per namespace
Session session = cluster.createSession(Behavior.DEFAULT);
// Stricter SC reads (linearizable) on SC namespaces
Behavior scBehavior = Behavior.DEFAULT.deriveWithChanges("STRICTLY_CONSISTENT", builder -> builder
.on(Selectors.reads().get().cp(), ops -> ops.consistency(ReadModeSC.LINEARIZE)));
Session scSession = cluster.createSession(scBehavior);
if (session.isNamespaceSC("inventory")) {
// Namespace is SC — transactions and linearizable reads are available
}

📖 API reference: Cluster.createSession(Behavior) | Session.isNamespaceSC(...)

Verify namespace mode

If the code is generic across namespaces and does not know ahead of time if a namespace is AP or SC mode, confirm the target namespace is SC-enabled on the server.

if (session.isNamespaceSC("inventory")) {
System.out.println("inventory is an SC namespace");
} else {
System.out.println("inventory is AP (or unknown)");
}

📖 API reference: Session.isNamespaceSC(...)

SC-scoped behavior settings (Python)

Python behaviors support separate patches for AP and SC namespaces through reads_ap, reads_sc, writes_ap, and writes_sc on derive_with_changes(). Resolution order is documented on Scope; SC namespaces merge readsreads_sc → shape-specific scopes (for example reads_point).

ScopeApplies when
reads_ap / writes_apNamespace is AP
reads_sc / writes_scNamespace is SC

Predefined Behavior.STRICTLY_CONSISTENT sets reads_sc=Settings(read_mode_sc=ReadModeSC.LINEARIZE). Behavior.FAST_RACK_AWARE sets reads_sc=Settings(read_mode_sc=ReadModeSC.SESSION) for lower-latency SC reads when session consistency is enough.

See Behaviors and selectors for the Java selector model and Behaviors for read-mode tables.

Server configuration

SC mode requires namespace configuration on the server:

namespace myns {
strong-consistency true
...
}

Multi-record transactions additionally require Aerospike Server 8.0+ on an SC namespace. See Transactions.

Next steps

Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?