Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Distributed Secrets Management, Dynamic
Lease & Envelope KMS Platform.

A production KMS must never expose plaintext secrets to storage disks or Raft logs while still serving 100k decrypt QPS under 2 ms.
Start the journey2 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

Place an AES-256-GCM Seal Barrier in front of a 5-node Raft storage cluster, shield the HSM with singleflight KEK caching, and enforce dual-sink fail-closed HMAC auditing.

TL;DR30-second simplified summary
▾

Combine Envelope Encryption + Seal Barrier + Min-Heap/Prefix-Trie Leases + Dual-Sink Fail-Closed Audit.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Envelope Encryption (KEK -> DEK)
Decouples HSM root wrapping from high-throughput AES-GCM payload encryption.
Raft Consensus
Provides RPO=0 quorum replication for key versions, policies, and lease state.
Full walkthrough · 2 stages
01
L4 · FUNDAMENTALS

R & S — Cryptographic Seal Barrier & Raft Storage.

5-Node Raft Cluster Behind Seal Barrier

All writes pass through an in-memory Seal Barrier encrypted with the Barrier Key (unwrapped via HSM Auto-Unseal or Shamir t-of-n shares) before entering Raft WAL/BoltDB. Standby followers forward writes to the Raft leader and serve read-only KEK lookups from local cache.

02
L4 · FUNDAMENTALS

H & D — Dynamic Leases & Prefix-Trie Revocation.

Secrets & KMS Control/Data Plane

Workload (SPIFFE)KMS API + KEK CacheSeal Barrier + RaftDual Fail-ClosedAuditmTLS DecryptRead/WriteSync HMAC Log
Engineering Decision Framework
Problem
How should the KMS enforce fail-closed audit logging without turning a single Splunk hiccup into a global outage?
Naive Solution
Write synchronously to one Splunk HTTP collector and fail all requests if Splunk times out.
Why It Fails
A 5-second Splunk GC pause or network blip takes down every microservice in production.
Alternatives
Dual-sink synchronous quorum (Kafka + local NVMe ring),Single synchronous audit sink,Best-effort async audit queue
Engineering Decision
Require synchronous ACK from at least 1 of 2 independent audit sinks (Kafka + local NVMe WAL), failing closed only if both fail.
Trade-Offs
Maintains strict compliance (zero unlogged reads) while surviving single-sink outages.
Decision Exercise · Make the Call

Why do Performance Secondaries maintain independent local lease trees instead of replicating ephemeral leases over WAN?

Each workload pod receives an ephemeral DB role (v_k8s_pod42_9f8a) tracked in both a TTL Min-Heap and a Prefix Trie (/auth/k8s/pod-42/*). On node compromise, revoking the prefix drops all child DB roles immediately:

import heapq, time

class LeaseRevoker:
    def __init__(self):
        self.heap = []  # (expires_at, lease_id)
        self.active = {}

    def register(self, lease_id: str, prefix: str, ttl_sec: int) -> None:
        exp = time.time() + ttl_sec
        self.active[lease_id] = prefix
        heapq.heappush(self.heap, (exp, lease_id))

    def revoke_prefix(self, target_prefix: str) -> list:
        revoked = [lid for lid, p in list(self.active.items()) if p.startswith(target_prefix)]
        for lid in revoked: del self.active[lid]
        return revoked
Recommended Learning Flow