# Consistency models

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
-   Writes succeed if any replica accepts them
-   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
-   Writes require a majority of replicas (quorum)
-   During partitions, minority side becomes read-only
-   No conflict resolution needed (linearizable)

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

## Choosing a consistency model

| Factor | AP Mode | SC Mode |
| --- | --- | --- |
| Availability | Higher | Lower during partitions |
| Read latency | Lower | Slightly higher |
| Write durability | Eventually consistent | Immediately consistent |
| Conflict handling | Automatic (LWW) | Not needed |
| Use case | Caching, sessions | Transactions, inventory |

## Configuring consistency

-   [Java](#tab-panel-2950)
-   [Python](#tab-panel-2951)

```java
// AP mode (default behavior)

Session apSession = cluster.createSession(Behavior.DEFAULT);

// SC mode (requires SC namespace on server)

Behavior scBehavior = Behavior.DEFAULT.deriveWithChanges("STRICTLY_CONSISTENT", b -> {});

Session scSession = cluster.createSession(scBehavior);
```

```python
# AP mode (default behavior)

ap_session = cluster.create_session(Behavior.DEFAULT)

# SC mode (requires SC namespace on server)

sc_session = cluster.create_session(Behavior.STRICTLY_CONSISTENT)
```

## Server configuration

SC mode requires namespace configuration on the server:

```plaintext
namespace myns {

    strong-consistency true

    ...

}
```

## Next steps

-   [Behaviors](https://aerospike.com/docs/develop/client/sdk/concepts/behaviors)
-   [Data Model](https://aerospike.com/docs/develop/client/sdk/concepts/data-model)
-   [Error Handling](https://aerospike.com/docs/develop/client/sdk/concepts/errors)