Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

The issue requests a design for embedding Litestream’s Go library to add replication/restore to sqlite-rest without altering the REST API.

  • Design scope: Opt-in Litestream replication for the SQLite DB; restore before serve; continuous WAL/snapshot replication; logging and Prometheus metrics; fail-fast defaults (no degraded mode) and divergence handled by failing fast with operator-driven force-restore if needed.
  • Configuration surface: Prefer a Litestream YAML config via --replication-config (minimal sqlite-rest flags: enable/config path); detailed tuning (snapshot/retention/replicas) delegated to Litestream config; least-privilege S3 IAM notes; multi-replica refers to multiple remote destinations for the same DB, with initial scope single.
  • Lifecycle & failure handling: Restore pre-open, start replicator alongside HTTP/metrics/pprof, monitor error channels and cancel the process on replication errors/divergence (fail-fast).
  • Testing plan (future work): Flag parsing, file-backed replication integration, restore flow, and metrics assertions.

Example lifecycle sketch:

restoreIfNeeded(ctx, dbPath, restoreURL, restoreOpts)
db := openDB(...)
replicator := newReplicator(dbPath, replicaURL, tuneOpts)
go replicator.Start(ctx)
go metricsServer.Start(ctx)
go pprofServer.Start(ctx)
server.Start(ctx.Done())
// On replicator error: log/metric and cancel ctx to fail fast

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 9 commits January 14, 2026 07:15
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI changed the title [WIP] Design document for embedding litestream for replication Design doc: embed Litestream replication for sqlite-rest Jan 14, 2026
Copilot AI requested a review from bcho January 14, 2026 07:22
Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


### High-level flow

1. **Configuration** (new `ReplicationOptions`):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to consume litestream configuration file here to minimal the deltas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to prefer a Litestream YAML config via --replication-config so sqlite-rest changes stay minimal. (f01868e)

- `--replication-restore-lag` (duration, default `0` meaning no lag allowed; used during startup restore decisions to tolerate a small amount of staleness between the local DB and the replica before forcing a restore).
- Env var mirrors for container use (e.g., `SQLITEREST_REPLICATION_ENABLED`, etc.).

2. **Restore before serving**:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe the behavior of diverging with remote backup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added divergence behavior: default fail-fast on lineage mismatch with remote, operator can force-restore or allow degraded if they accept overwrite risk. (f01868e)


## Open questions

- Should we expose multiple replicas at launch or keep single-replica until requested?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple replicas of what? Please clarify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified this means multiple remote destinations for the same SQLite DB via Litestream; initial scope remains single replica. (f01868e)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this question as we have the answer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the answered question about multiple replicas; doc now just states initial scope is single replica with Litestream config controlling replicas. (d41a7dd)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the answered question; doc reflects single-replica initial scope with Litestream config controlling destinations. (d41a7dd)

## Open questions

- Should we expose multiple replicas at launch or keep single-replica until requested?
- How strict should startup be when replication is enabled but the remote is unreachable? **Recommendation:** fail fast by default to avoid running without configured durability, with an explicit `--replication-allow-degraded` escape hatch if operators need to accept the data-loss risk.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with this decision, but we should refine the cli flag experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag UX is now minimal: enable + config path, optional restore-from/allow-degraded; all other tuning stays in the Litestream config. (f01868e)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the resolved question; CLI UX stays minimal via enable + config path, optional restore-from. (d41a7dd)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the resolved question per feedback. (d41a7dd)


- Should we expose multiple replicas at launch or keep single-replica until requested?
- How strict should startup be when replication is enabled but the remote is unreachable? **Recommendation:** fail fast by default to avoid running without configured durability, with an explicit `--replication-allow-degraded` escape hatch if operators need to accept the data-loss risk.
- What are the sensible defaults for snapshot/retention to balance durability and cost?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaults to disable this feature, delegate the detailed settings to litestream config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented that replication stays disabled by default and detailed settings are delegated to the Litestream config file. (f01868e)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the answered question; defaults remain disabled with detailed settings delegated to the Litestream config. (d41a7dd)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the remaining question; open questions now only cover sensible defaults for snapshot/retention. (d41a7dd)

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI requested a review from bcho January 14, 2026 07:34
Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## Open questions

- Should we expose multiple replicas at launch or keep single-replica until requested?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this question as we have the answer

## Open questions

- Should we expose multiple replicas at launch or keep single-replica until requested?
- How strict should startup be when replication is enabled but the remote is unreachable? **Recommendation:** fail fast by default to avoid running without configured durability, with an explicit `--replication-allow-degraded` escape hatch if operators need to accept the data-loss risk.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this question


- Should we expose multiple replicas at launch or keep single-replica until requested?
- How strict should startup be when replication is enabled but the remote is unreachable? **Recommendation:** fail fast by default to avoid running without configured durability, with an explicit `--replication-allow-degraded` escape hatch if operators need to accept the data-loss risk.
- What are the sensible defaults for snapshot/retention to balance durability and cost?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this question

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI requested a review from bcho January 14, 2026 07:41
Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. **Configuration** (new `ReplicationOptions`):
- `--replication-enabled` (bool, default false).
- `--replication-config` (string, path to Litestream YAML config; preferred path to keep sqlite-rest changes minimal and delegate detailed tuning like snapshot/retention/replicas to Litestream).
- `--replication-restore-from` (optional override to restore from a different replica URL; if omitted, use the primary replica from the Litestream config).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove --replication-restore-from flag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the --replication-restore-from flag; minimal flags are now enable + config path. (61a3a12)

- `--replication-config` (string, path to Litestream YAML config; preferred path to keep sqlite-rest changes minimal and delegate detailed tuning like snapshot/retention/replicas to Litestream).
- `--replication-restore-from` (optional override to restore from a different replica URL; if omitted, use the primary replica from the Litestream config).
- Env var mirrors for container use (e.g., `SQLITEREST_REPLICATION_ENABLED`, `SQLITEREST_REPLICATION_CONFIG`, etc.).
- Recommended CLI UX: keep flags minimal (`--replication-enabled`, `--replication-config`, optional `--replication-restore-from`) and leave all other Litestream knobs to the config file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the UX line tied to the removed flag; doc reflects only enable + config path. (61a3a12)

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI requested a review from bcho January 14, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants