Back to articles
Technology Insight

Production-Ready SQLite: How to Build a Highly Reliable Single-VPS Database Infrastructure Using Litestream

June 3, 2026

The Paradigm Shift: SQLite in Production

For years, architectural convention dictated a strict separation between application servers and database servers. Software engineers routinely reached for heavy-weight, client-server relational database management systems (RDBMS) like PostgreSQL or MySQL, even for minimum viable products (MVPs) and medium-sized enterprise applications. However, this infrastructure complexity introduces significant overhead, network latency, and maintenance costs.

Today, the narrative is shifting. Modern Virtual Private Servers (VPS) are equipped with incredibly fast NVMe Solid State Drives (SSDs) and high-performance CPUs. In this environment, SQLite—a self-contained, serverless, zero-configuration database engine—emerges as a formidable production contender. Because SQLite reads and writes directly to a local file on disk, it eliminates network round-trips entirely, resulting in blazing-fast query execution times.

Yet, the primary deterrent to deploying SQLite in a production environment has always been data durability. If your single VPS crashes, or if the underlying storage becomes corrupted, you risk catastrophic data loss. This is exactly where Litestream comes into play.


What is Litestream and Why Does It Change the Game?

Litestream is an open-source, streaming replication tool built specifically for SQLite by Ben Johnson. It runs as a separate background process (a daemon) alongside your application, continuously monitoring the SQLite write-ahead log (WAL) and streaming incremental changes to independent cloud storage providers (such as Amazon S3, Backblaze B2, Cloudflare R2, or DigitalOcean Spaces).

How Litestream Works under the Hood

To appreciate the reliability Litestream introduces, it is essential to understand its core mechanism:

  • WAL Mode: Litestream requires SQLite to operate in Write-Ahead Log mode. Instead of modifying the main database file directly during a transaction, SQLite appends changes to a separate .wal file.
  • Continuous Tailing: Litestream "tails" this WAL file, capturing byte-level modifications as they happen.
  • Snapshotting and Shadow Paging: Every generation, Litestream takes a full snapshot of the database file. Subsequently, it uploads small, compressed incremental frame files to your object storage every second (or upon transaction commit).

Key Takeaway: By decoupling compute from storage persistence, Litestream guarantees that even if your VPS completely vanishes from existence, your data is safely backed up to the cloud with a point-in-time recovery window of just a few seconds.


Step-by-Step Architecture Guide on a Single VPS

Let us walk through a robust, production-grade implementation of SQLite and Litestream on a single Linux VPS. For this guide, we will assume you are using an Ubuntu server and Amazon S3 for durable object storage.

Step 1: Prerequisites and Server Provisioning

Before installing Litestream, ensure your environment meets the basic criteria:

  1. A provisioned Linux VPS (e.g., DigitalOcean, Hetzner, or AWS EC2) with SSH access.
  2. An application that uses SQLite as its primary database.
  3. An AWS account with an S3 bucket created specifically for database backups.

Step 2: Installing Litestream

Connect to your VPS via SSH and download the appropriate package for your system. For Debian-based systems like Ubuntu, use the following commands:

sudo apt-get update
wget [https://github.com/benbjohnson/litestream/releases/download/v0.3.13/litestream-v0.3.13-amd64.deb](https://github.com/benbjohnson/litestream/releases/download/v0.3.13/litestream-v0.3.13-amd64.deb)
sudo dpkg -i litestream-v0.3.13-amd64.deb

Verify the installation by checking the version:

litestream version

Step 3: Configuring Object Storage Credentials

To avoid hardcoding sensitive credentials into your configuration file, utilize environment variables. Create or edit your environment file (e.g., /etc/environment or via your service manager) to include your cloud storage API keys:

LITESTREAM_ACCESS_KEY_ID="your_aws_access_key_id"
LITSTREAM_SECRET_ACCESS_KEY="your_aws_secret_access_key"

Step 4: Writing the Litestream Configuration File

Litestream relies on a structured YAML configuration file, typically located at /etc/litestream.yml. Open this file and define your database path and replication targets:

dbs:
  - path: /var/www/my_app/production.db
    replicas:
      - url: s3://my-production-sqlite-bucket/database
        sync-interval: 1s

In this configuration, we specify the absolute path to our production SQLite database file and direct Litestream to replicate changes to an S3 bucket named my-production-sqlite-bucket every second.

Step 5: Enforcing WAL Mode in Your Application

For Litestream to function, your application must open the SQLite database with Write-Ahead Logging enabled. You can execute this programmatically within your application code upon initialization:

PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;

Setting synchronous to NORMAL is highly recommended when using WAL mode, as it significantly boosts write performance while maintaining excellent structural safety.

Step 6: Running Litestream as a Systemd Service

To guarantee that Litestream runs continuously and restarts automatically if the server reboots, configure it as a systemd system service. Create a service file at /etc/systemd/system/litestream.service:

[Unit]
Description=Litestream Replication Service
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/environment
ExecStart=/usr/local/bin/litestream replicate
Restart=always

[Install]
WantedBy=multi-user.target

Enable and start the service with the following commands:

sudo systemctl daemon-reload
sudo systemctl enable litestream
sudo systemctl start litestream

Check the status to ensure it is actively replicating without errors:

sudo systemctl status litestream

Disaster Recovery: Restoring Your Production Database

An untested backup is not a backup. The true power of Litestream becomes apparent during a disaster recovery scenario. If your VPS suffers a fatal hardware failure, restoring your application data onto a completely new server is remarkably straightforward.

The Restoration Process

On your fresh, newly provisioned VPS, install Litestream following the same steps outlined above. Once configured with access to your S3 bucket, execute the restore command before launching your application:

litestream restore -o /var/www/my_app/production.db s3://my-production-sqlite-bucket/database

Litestream will automatically download the latest full snapshot and apply all subsequent incremental WAL frames up to the final second before the original server went offline. Once the command completes, your SQLite database file is perfectly reconstructed, and your application can safely resume operations with virtually zero data loss.


Performance and Production Best Practices

While Litestream handles data durability flawlessly, optimizing SQLite for a high-traffic production production lifecycle requires adhering to a few best practices:

  • Manage Database Locks: Since SQLite supports a single writer concurrent with multiple readers, configure a busy timeout (e.g., PRAGMA busy_timeout = 5000;). This prevents immediate application crashes if two web requests attempt to write to the database at the exact same fraction of a second.
  • Monitor Disk Space: Litestream manages its own generation snapshots, but you must ensure your local VPS drive has enough headroom to accommodate both the live database file and active WAL transactions under heavy load.
  • Automate Verification: Periodically run a cron job on a staging server that performs a litestream restore and executes PRAGMA integrity_check; against the restored file to mathematically verify data health.

Conclusion: Simplicity Wins

By pairing the raw, low-latency performance of local SQLite with the streaming durability of Litestream, single-VPS deployments are no longer a compromise. You eliminate complex database network topology, reduce cloud hosting monthly costs significantly, and retain complete confidence that your data is securely backed up to durable object storage second by second.

For modern startups, indie hackers, and pragmatic enterprise developers alike, running SQLite backed by Litestream on a single VPS is not just a viable alternative—it is an elegant, production-ready architectural superpower.