99.999999999% Durability for SQLite Data

Ravi Yasakeerthi
2 min readMay 29, 2022

Trying out Litestream with AWS S3

In case you have a workload that using SQLite in your production environment you know the pain if your server dies. Instead of having a nightly backup solution, Litestream suggests continuously steaming your data to a cloud-based object store like S3. With that, you can support lower RTO with higher availability and durability for your Data.

To try out this you need to have SQLite installed and AWS CLI configured as a pre-requisite.

Install Litestream

brew install benbjohnson/litestream/litestream

Other Installation options can be found here.

Create Database

sqlite3 demo.db

Create Table

CREATE TABLE cars (make TEXT, color TEXT);

Add few records

INSERT INTO cars (make, color) VALUES (‘Nissan’, ‘black’);
INSERT INTO cars (make, color) VALUES (‘Toyota’, ‘red’);

Create S3 Bucket

aws s3api create-bucket — bucket lkravi-litestream — region us-east-1

Replicate database

litestream replicate demo.db s3://lkravi-litestream/demo.db

Add one more record to test continuous replication

INSERT INTO cars (make, color) VALUES (‘Honda’, ‘blue’);

Restore database

litestream restore -o demo2.db s3://lkravi-litestream/demo.db

Check Data in New DB

sqllite3 demo2.db ‘SELECT * from cars’

It’s pretty interesting to witness how simple and smooth the setup is. In Background Litestream replicates your database all the time and you don’t need to worry about it. In a Desaster, you can quickly restore the Database from your S3 Stream.

References :
https://news.ycombinator.com/item?id=26105570
https://litestream.io/
https://github.com/benbjohnson/litestream

--

--