Skip to content

How Sync Works

Jimmy Pautz edited this page Nov 20, 2026 · 1 revision

How Sync Works (Schema v1)

Nimbus is engineered so that multiple offline devices can read, highlight, and sync without ever overwriting each other's data — with zero backend server required.


Cloud Folder Layout

Under your configured remote root (default /Nimbus):

/Nimbus/
├── Books/
│   └── <Author> - <Title> [<book_id>]/
│       ├── <Filename>.<ext>                  # Supported: epub, pdf, cbz, mobi, azw3, fb2
│       ├── cover.jpg                         # Optional JPEG thumbnail (max 400px wide)
│       └── metadata.json                     # Per-book metadata snapshot
└── _sync/
    ├── schema_version.json                   # { "version": 1, "min_client": "0.1.0" }
    ├── catalog.json                          # Single-file library index of all books
    └── devices/
        └── <device_slug>/                    # e.g. "Kobo-Libra-2_9f2a", "Web-Browser_1a2b"
            ├── device.json                   # Device identity, platform, last_sync_at
            ├── progress.json                 # Map: book_id -> latest position & status
            ├── annotations.json              # Map: book_id -> highlights, notes & tombstones
            └── sessions/
                └── YYYY-MM.json              # Monthly reading sessions shard

Zero-Collision Write-Ownership Invariant

sequenceDiagram
    participant K as KOReader (Kobo_9f2a)
    participant C as Cloud (/Nimbus/_sync/devices/)
    participant W as Web App (Web_1a2b)

    K->>C: Write ONLY to Kobo_9f2a/progress.json
    W->>C: Write ONLY to Web_1a2b/progress.json
    K->>C: Read ALL sibling device folders
    W->>C: Read ALL sibling device folders
    Note over K,W: Deterministic merge runs locally on each client
Loading
  • Device Shards: A client only writes to its own _sync/devices/<device_slug>/ directory and reads from all sibling device directories.
  • Because no two devices ever write to the same progress.json, annotations.json, or sessions/YYYY-MM.json, offline edits never cause file-level race conditions or lost highlights.

Book Identity & Matching Priority

Each book in Nimbus receives an immutable 8-character lowercase book_id (e.g., a1b2c3d4). Once assigned, book_id never changes even if you rename the title or author.

Clients match local files to cloud books in this strict priority order:

  1. Local Linked book_id (client link map, Calibre nimbus:<book_id> identifier, or IndexedDB).
  2. Exact partial_md5 match — sampled 1024-byte reads at KOReader's exact exponential offsets (0, 1024, 4096, ..., 1073741824), producing bit-identical hashes across Lua, Python, and TypeScript.
  3. Exact sha256 match — full-file SHA-256 digest.
  4. Fallback Metadata Match — normalized (title, primary_author) or isbn (prompting confirmation where appropriate).

Deterministic Merge Rules

All three clients (Lua, Python, TypeScript) implement identical merge logic verified against shared golden test fixtures:

Data Type Winner / Merge Rule Notes
Reading Progress 1. Highest updated_at (epoch seconds)
2. Highest percent
3. Lexicographically greatest device_id
Ensures the newest reading position always wins deterministically.
Highlights & Notes Grouped by stable id (ann_<10hex>):
1. Highest updated_at
2. deleted: true wins on tie
3. Non-empty note, then device_id
Deletions propagate via tombstone records ("deleted": true) so offline devices don't resurrect deleted highlights.
Reading Sessions Deduplicated by (device_id, book_id, start_time) Keeps largest duration_sec, then pages_read; sorted chronologically.

Cross-Engine Position Resolution

KOReader and the Web App use different rendering engines (crengine vs. foliate-js / pdf.js):

  • KOReader → KOReader: Uses exact xpointer (reflowable) or page (PDF/CBZ).
  • Web → Web: Uses exact cfi (EPUB) or page (PDF/CBZ).
  • KOReader ↔ Web: Seeks to the approximate percent, then searches nearby text for text_anchor (a normalized ~40-character snippet around the reading position) to snap to the exact paragraph.

Clone this wiki locally