1-Second SQLite Replication and a 36-Second Automated Kyoto-to-Tokyo DR Drill
How we pair NVMe local-path storage with 1-second Litestream replication for ~20s node failover, replicate buckets from Kyoto to Tokyo (~15 ms RTT) with native MinIO, and verify everything weekly in ~36 seconds.
Running stateful web apps on a bare-metal Kyoto Kubernetes cluster comes with two uncomfortable tensions:
- Distributed block storage across multiple nodes is great for convenience, but adds network hops compared to local NVMe (
3,675 MB/stier on our CPU nodes, each carrying ~1.5–1.68 TiBof free local NVMe). - A single physical building—no matter how cleanly wired—is still a single point of failure unless every byte of customer state leaves Kyoto continuously and gets tested against actual restore drills.
Instead of inventing custom backup scripts, we combined three boring, standard tools—Rancher local-path NVMe, 1-second Litestream replication, and native MinIO bucket replication—tied together by a weekly automated restore test that proves our offsite backups actually boot.
Fast Local NVMe + 1-Second Litestream Failover (19.55s)
For SQLite-backed services (including our own web console databases and customer apps), each Pod runs on a fast local-path NVMe PVC paired with:
- A
litestream-restoreinitContaineron boot. - A continuous
1-secondLitestream sidecar streaming WAL frames to our Kyoto S3 cluster.
When a node becomes unhealthy—or when an operator triggers pangea-admin relocate-local-storage—the Control Plane checks S3 via a fail-closed ListObjectsV2 pre-flight check (verify_s3_litestream_replica) so we never strand data without a confirmed replica, patches the Deployment node affinity, and lets the app reschedule onto a healthy node.
In live production testing on a stateful SQLite app, relocating storage across nodes and restoring cleanly from S3 took 19.55s end to end.
One Sharp Edge: gVisor Multi-Mount Lock Contention on Heavy SQLite Apps
We hit one non-obvious bug while migrating a heavier (76.6 MB) SQLite workload that called db.close() per request alongside a Litestream sidecar: under gVisor (runsc), 9p gofer multi-mount coordination between the app container and the Litestream sidecar occasionally hit -shm lock contention. Keeping default untrusted sandboxes in gVisor while running explicitly trusted first-party workloads under hardened runc (with readOnlyRootFilesystem, drop ALL, and RuntimeDefault seccomp) eliminated the contention completely.
Native Kyoto-to-Tokyo Bucket Replication (~15 ms RTT)
Keeping Kyoto safe from a rack-level failure or disk disaster meant getting everything out of the building:
- Control-plane PostgreSQL 17 WAL segments and base backups (Barman Cloud)
- Customer and console Litestream WAL frames
- The OCI container registry blobs
Rather than maintaining fragile custom cron sync scripts, we enabled native MinIO active-passive bucket replication from our Kyoto S3 cluster to a dedicated offsite storage server in Tokyo (~15 ms RTT, 21 ms average). Across all three core buckets—over 414,000 objects totaling ~96 GiB (24 GiB DB/Litestream + 72 GiB registry blobs)—replication settled at Queued: 0, Errors: 0, with object versioning and 7-day lifecycle cleanup for noncurrent versions.
(One narrow set of legacy/auxiliary prefixes still uses a 6-hourly sync job transferring 495 objects / 8.4 GiB in 103.2s—everything in the live hot path relies purely on native bucket replication.)
Backups You Never Restore Are Wishes: Our Weekly ~36s Drill
Every Sunday at 04:30 UTC, a systemd timer runs dr_verify.py strictly against the Tokyo offsite replica—spinning up temporary containers, testing full restoration non-destructively, and pushing Prometheus metrics (PangeaDR alert rules) routed to email alerting.
In verified production runs, the entire 4-part drill finished in 35.694s (expanding to 39.411s after adding a 6th SQLite database in Phase 4):
pg_restore(3.952s): Spins up a temporary PostgreSQL 17 container directly from Tokyo Barman Cloud base backups + WAL segments via Point-In-Time Recovery (PITR) and verifies non-zero row counts across core tables (operations,projects,workspaces,settings).litestream_restore(30.295s): Restores all5/5production SQLite databases (6/6in Phase 4) from Tokyo S3 and runsPRAGMA integrity_check == "ok"on every single file.registry_integrity(1.374s): Walks recent OCI manifests (20+11layers) and verifies all33deduplicated unique blobs exist via SigV4HEAD.offsite_and_replication(0.073s): Checks object freshness across the offsite mirror prefixes (< 1hage).
Finishing the Diet: Native PostgreSQL 17 & S3-Backed Build Sources
On the Control Plane itself, we finished unifying on a 2-instance PostgreSQL 17 HA cluster (pg_dump snapshots in ~0.35s) and completely deleted runtime SQLite dialect translation (db.py shrank from 1,278 to 777 lines, leaving zero import sqlite3 in Control Plane Python). We also moved uploaded build source archives (66 archives / 2.31 GB) and operation logs (666 logs / 81.8 MB) off shared NFS and straight into S3—meaning hot Control Plane paths (/healthz, /v1/tls-ask, /v1/registry/token, PUT /sources, GET /logs) run cleanly even against a read-only (0o500) local root directory, and every build archive replicates to Tokyo automatically.
If a node dies in Kyoto, stateful apps relocate in under 20 seconds. And every Sunday morning, automated temporary containers in Tokyo prove our disaster recovery stack actually boots before anyone ever needs it.