KandraMultiDc

Multi-datacenter extension for Kandra.

Include kandra-multidc in your dependencies for multi-DC features:

  • Token-aware load balancing with DC failover

  • Per-operation consistency level control

  • Speculative execution for latency-sensitive reads

  • LWT serial consistency configuration for globally unique constraints

All multi-DC configuration lives in KandraConfig blocks:

install(Kandra) {
localDatacenter = "us-east-1"

consistency {
defaultRead = KandraConsistency.LOCAL_ONE
defaultWrite = KandraConsistency.LOCAL_QUORUM
}

loadBalancing {
tokenAware = true
dcAwareFailover = true
allowedRemoteDcs = listOf("eu-west-1", "ap-southeast-1")
}

failover {
onLocalDcUnavailable = FailoverPolicy.RETRY_REMOTE_DC
remoteRetryDelayMs = 100
}

speculativeExecution {
enabled = true
delayMillis = 100
maxAttempts = 2
}
}

LWT serial consistency

Use LOCAL_SERIAL (default) for Paxos within the local DC only — sufficient for region-scoped uniqueness (e.g. wallet creation per-region).

Use SERIAL for globally unique constraints (e.g. usernames unique across all DCs):

// Global uniqueness — Paxos consensus across ALL DCs
val registered = userRepo.saveIfNotExists(user, serialConsistency = KandraConsistency.SERIAL)

Speculative execution

Only idempotent statements are eligible for speculative execution. Kandra automatically sets isIdempotent = false on plain INSERT, collection mutations, and counter updates — the driver skips speculative execution for them.

Functions

Link copied to clipboard

Validates a multi-DC configuration and returns a description of the active policies. Useful for logging at startup.