LankaDB

In Progress: Distributed KVP Database With Deterministic Replication

A quorum-replicated, deterministic KVP database designed for control-plane workloads and predictable behavior under failure.

1. Project Overview

LankaDB is a distributed key-value database built for control-plane workloads, where correctness, predictability, and operational clarity matter more than raw feature surface.

It is designed for systems that require:

LankaDB is deployed as a single binary per node and forms a cluster using a quorum-based consensus protocol (Raft-style).

The system is intentionally narrow in scope:

It is a replicated coordination and state system, similar in role to etcd or Chubby.

2. Design Principles

3. System Architecture

LankaDB is a modular monolith:

3.1 Core Components

  1. Consensus Core (Node Actor)

    • owns term, role, commit index, log coordination
    • processes all consensus events serially
    • enforces ordering and safety invariants
  2. Replication Engine

    • manages follower state (next_index, match_index)
    • handles APPEND and snapshot installation
    • implements Raft backtracking with conflict hints
  3. WAL Storage

    • append-only segmented log
    • CRC-protected records
    • crash-safe recovery via forward scan
  4. State Machine (Apply Loop)

    • applies committed entries in order
    • maintains in-memory KV state
    • emits watch events
  5. Transport Layer

    • persistent TCP connections between peers
    • multiplexed message channels
    • priority-aware write queues
  6. Client API Layer

    • GET / PUT / DEL / TXN / RANGE / WATCH
    • leader redirection semantics
    • idempotency support (in-memory v1)
  7. Snapshot & Compaction

    • periodic state snapshotting
    • WAL truncation for bounded disk usage

4. Replication Model

4.1 Consensus

LankaDB uses a Raft-style protocol:

4.2 Write Flow

  1. Client sends write to leader
  2. Leader appends entry to WAL
  3. Entry replicated to followers
  4. On quorum ACK + durable write:
    • commit_index advances
    • entry applied
  5. Response returned to client

4.3 Read Model

5. Storage Model

5.1 Write-Ahead Log (WAL)

5.2 Snapshots

5.3 Compaction

6. Lease System

LankaDB includes a deterministic lease engine:

Key property

Expiry is not local. It is replicated.

The leader emits LEASE_EXPIRE entries:

7. Watch System

7.1 Semantics

7.2 Backpressure Policy

This avoids:

8. Network & Protocol

8.1 Transport

8.2 Framing

8.3 Channels

8.4 Priority Model

Lower numeric value = higher priority:

9. Failure & Recovery Model

9.1 Node Failure

9.2 Network Partition

9.3 Disk Failure

9.4 Shutdown (SIGTERM)

10. Observability

Metrics (v1)

Ops Endpoints

11. Safety Properties

12. Non-Goals

13. Deployment Model

Works with:

14. What Comes Next (v2)

Closing Note

LankaDB is intentionally constrained.

The goal is not to build the most feature-rich database, but to build a system where:

Most complexity exists to ensure that under stress or failure, the system behaves in a way operators can reason about.