Each time we write about it, we get a little bit better at golfing down a description of what Litestream is. Here goes: Litestream is a Unix-y tool for keeping a SQLite database synchronized with S3-style object storage. It’s a way of getting the spe
Overview
This article by Ben Johnson explains two major new features added to Litestream's Virtual File System (VFS): writable mode and background hydration. These features were developed specifically to support Fly.io's Sprites product, enabling SQLite databases to serve both reads and writes directly from S3-compatible object storage during cold starts, then seamlessly transition to local storage through background hydration.
What You'll Learn
How Litestream VFS enables read-write SQLite queries directly against S3-compatible object storage without downloading the full database
Why single-writer mode is chosen over multi-writer distributed SQLite and what trade-offs that entails
How background hydration works to transition from remote object storage reads to local file reads without blocking queries
When to use the Litestream VFS writable mode versus standard Litestream sidecar configuration
How the many-SQLite-databases pattern can replace centralized PostgreSQL for per-tenant workloads
Prerequisites & Requirements
- Understanding of SQLite and its WAL (Write-Ahead Logging) mechanism
- Familiarity with S3-compatible object storage concepts
- Basic understanding of Virtual File Systems (VFS) and how SQLite uses them
- Understanding of cold start problems in ephemeral compute environments(optional)
- Litestream installed and basic familiarity with its backup/restore workflow
Key Questions Answered
How does Litestream VFS enable writing to SQLite databases stored in object storage?
What is background hydration in Litestream and how does it improve performance?
Why doesn't Litestream VFS support multiple writers?
How does Fly.io Sprites use Litestream for sub-second boot times with 100GB storage?
What is the many-SQLite-databases pattern and when should you use it?
How does the Litestream VFS index work for serving reads from object storage?
What happens to the hydration file when a Sprite bounces or exits?
Key Statistics & Figures
Technologies & Tools
Some links below are affiliate links. We may earn a commission if you make a purchase.
Key Actionable Insights
1Consider the many-SQLite-databases pattern as an alternative to centralized PostgreSQL for per-tenant workloads. Each tenant gets their own SQLite database synchronized by Litestream to object storage, providing natural data isolation and simpler scaling characteristics.Fly.io's Sprites orchestrator uses this pattern to replace their centralized Postgres cluster, which had become a major engineering challenge to maintain at scale.
2For cold-start scenarios where you need to serve database queries before a full restore completes, use Litestream VFS to query directly from object storage. Set LITESTREAM_HYDRATION_PATH to enable background hydration that transitions to local storage without blocking reads.This is particularly valuable for ephemeral compute environments where instances need to serve requests within milliseconds of booting, such as serverless functions or Fly.io Sprites.
3Only enable Litestream VFS writable mode (LITESTREAM_WRITE_ENABLED=true) when your application can tolerate eventual durability — writes aren't truly durable until the periodic sync to object storage happens (approximately every second). For standard read/write workloads, use Litestream as a normal sidecar instead.The writable VFS was designed specifically for environments like Sprites where all storage already has an eventual durability property. Most applications need stronger durability guarantees.
4When designing storage systems that need to handle cold starts, borrow the background hydration pattern from dm-clone: serve queries from a remote source immediately while running a background loop to pull data locally. Switch over to local storage only when hydration is complete.This pattern allows you to decouple availability from data locality, providing immediate service while optimizing for steady-state performance in the background.
5Avoid implementing multi-writer distributed SQLite. The article strongly advises against this approach due to extreme complexity. Instead, design your system around single-writer semantics and use replication for read scalability.Litestream's VFS explicitly disables polling in write mode and assumes a single writer, treating multi-writer distributed SQLite as an intractably complex problem.