Litestream: Revamped

290 usrme 59 5/20/2025, 7:58:27 PM fly.io ↗

Comments (59)

maxmcd · 10h ago
Looks like the code is here: https://github.com/benbjohnson/litestream/tree/v0.5

Really nice to see this, I wrote this comment almost 2 years ago when I was a little miffed about trying to use litestream and litefs: https://news.ycombinator.com/item?id=37614193

I think this solves most of the issues? You can now freely run litestream on your DB and not worry about issues with multiple writers? I wonder how the handoff is handled.

The read replica FUSE layer sounds like a real nice thing to have.

edit: Ah, it works like this: https://github.com/benbjohnson/litestream/pull/617

> When another Litestream process starts up and sees an existing lease, it will continually retry the lease acquisition every second until it succeeds. This low retry interval allows for rolling restarts to come online quickly.

Sounds workable!

wiradikusuma · 9m ago
For Fly.io employees here: Can I finally replace my Postgre with this a'la Cloudflare D1 (which is also Sqlite based)?
simonw · 9h ago
This post is like they read my mind and implemented everything I wanted from a new Litestream. So exciting.
mythz · 3h ago
Awesome stuff, this resolves my #1 feature request of being able to replicate an entire directory of SQLite *.db's from a single Litestream process - happy it's finally here.

Should make replicating Multi tenant per-user SQLite databases a lot more appealing.

bradgessler · 7h ago
I wish Fly would polish the developer experience on top of SQLite. They're close, but it's missing:

1. A built-in UI and CLI that manages SQLite from a volume. Getting the initial database on a Fly Machine requires more work than it should.

2. `fly console` doesn't work with SQLite because it spins up a separate machine, which isn't connected to the same volume where the SQLite data resides. Instead you have to know to run `fly ssh console —pty`, which effectively SSH's into the machine with the database.

The problem in general with SQLite web apps is they tend to be small apps, so you need a lot of them to make a decent amount of money hosting them.

adenta · 4h ago
Brad, what’s your take on Rails 8 w/ SQLite? Are you gravitating towards it these days over Postgres?
bradgessler · 3h ago
Yep! I just migrated a Fly PG cluster database to SQLite because I over-provisioned DB resources and got tired of dealing with the occasional node crashing.

TBH I wish they had their managed PG cluster running because it would have made it easier to downsize, but I’m happy with SQLite.

I used SQLite for another project that I knew was going to max out at 100 concurrent users and it worked great. The best moment was when a user reported a production error I couldn’t recreate locally, so I downloaded the database and recreated it with the latest production data on my laptop. You couldn’t do that with a high-compliance app, but that’s not most apps.

I’m hesitant to outright say “SQLite and Rails is great”because you have to know your app will run on one node. If you know that then it’s fantastic.

thewisenerd · 7h ago
ben, thanks for litestream!

we're using it on production for a write-heavy interal use-case (~12GB compressed) for more than a year now; and it's costing us a couple hundred pennies per month (azure).

excited to try the new changes when they land.

malkia · 6h ago
So fossil (which is built on top of sqlite) + this = SCM?
jasonthorsness · 9h ago
What a coincidence, I was just researching Litestream today! I use Sqlite on my VPS and was thinking about adding this.

Am I understanding correctly that I will be able to restore a database to any point-in-time that is while the litestream process is running? Because auto-checkpointing could consume the WAL while it isn't running?

So for an extreme example if the process crashed for an hour between 2:00 and 3:00, I could restore to 1:55 or 3:05 but the information required to restore between 2:00 and 3:00 is lost?

benbjohnson · 8h ago
Litestream saves WAL segments to a given time granularity. By default, it ships off WAL changes every second so you should be able to restore to any given second in your history (within your retention period).
psanford · 9h ago
This looks great! A few years ago I wrote a sqlite vfs for using dynamodb as a backing store[0] called DonutDB. With the recent addition of CAS to S3, I was thinking about making a new version of DonutDB backed by S3. I'm really glad lightstream supports this so I don't have to!

I can't wait to try this out.

[0]: https://github.com/psanford/donutdb

hamandcheese · 4h ago
> With the recent addition of CAS to S3

Do you have a reference for this? I assume by CAS you mean content addressable storage? I googled but can't find any AWS docs on this.

xyzzy_plugh · 3h ago
Compare And Swap
gcr · 3h ago
The TL;DR is that Amazon S3 now supports "conditional writes" which are guaranteed to fail if the file was written by some other writer. This is implemented by sending the ETag of an object's expected version alongside the write request.

Litestream now depends on this functionality to handle multiple writers. Think of optimistic locking.

https://aws.amazon.com/about-aws/whats-new/2024/11/amazon-s3...

hobo_mark · 7h ago
If you wanted to use litestream to replicate many databases (ideally, one or more per user), which is one of the use cases described here (and elsewhere), how do you tell litestream to add new databases dynamically? The configuration file is static and I haven't found an API to tell it to track a new db at runtime.
mrkurt · 7h ago
I would expect this problem to get solved. It's tricky to detect new sqlites, but not impossible.

In the meantime, it's pretty straightforward to use as a library.

neom · 7h ago
Is Litestream on a path to subsume LiteFS's capabilities? Re: PITR, would this be used to facilitate automated A/B testing of AI-generated code changes against live data subsets? I can imagine a lot of cool stuff in that direction. This is really cool Ben!
JSR_FDED · 2h ago
Will the new litestream work with object stores that don’t provided conditional writes?
rads · 3h ago
What will be required from users of the existing Litestream version to upgrade to the new one? Is it a matter of bumping the version when it comes out or is there more to it?
rawkode · 9h ago
Amazing to see and hear about the progress. Always a pleasure when Ben works on something and shares it. Keep it up!
j0e1 · 8h ago
This is exciting! Especially glad that Litestream is still maintained. Is there a use-case for Litestream for more than backup? I am a fan of offline-first but it would be cool to have a way to synchronize on-device SQLite instances to a single central instance.
benbjohnson · 8h ago
Backups & read replicas are the primary use cases. If you're interested in local-first, you can check out projects like cr-sqlite[1].

[1]: https://github.com/vlcn-io/cr-sqlite

j0e1 · 8h ago
Thank you Ben for the great work on this project! Also, I remember looking into this one and: https://github.com/vlcn-io/cr-sqlite/issues/444
dankebitte · 7h ago
> read replicas

Can this be done with only Litestream, or is LiteVFS still in development? I looked into this last year but was put off by LiteFS's stated write performance penalty due to FUSE [1]; it's still marked as WIP [2] and hasn't seen updates for over a year.

[1] https://fly.io/docs/litefs/faq/#what-are-the-tradeoffs-of-us...

[2] https://github.com/superfly/litevfs

oliwary · 7h ago
Fantastic to see it's getting updated! I am a big fan of litestream, have been using it for a while together with pocketbase. It's like a cheat code for a cheap, reliable and safe backend.
srameshc · 10h ago
I have been following Ben for a long time but I never knew LiteFS was based on his work. I somehow settled eventually for rqlite for self managed distributed.

https://github.com/rqlite/rqlite

digianarchist · 7h ago
Similar approach to LiteFS but rqlite embeds raft into the project instead of depending on consul.

https://youtu.be/8XbxQ1Epi5w?si=puJFLKoVs3OeYrhS

tptacek · 7h ago
I don't think they're similar at all. LiteFS uses Consul to elect a leader for a single-write-leader multiple-replica configuration, the same way you'd do with Postgres. rqlite (as I understood it last time I looked) runs Raft directly; it gets quorums for every write.

One isn't better than the other. But LiteFS isn't a "distributed SQLite" in the sense you'd think of with rqlite. It's a system for getting read-only replicas, the same way you've been able to do with log shipping on n-tier databases for decades.

apitman · 4h ago
rqlite also requires you to use special client libraries, whereas litefs is transparent to the program.
dastbe · 3h ago
asking since ben does take a look here...

will revamped litestream have a solution for ACKing only when transactions have durably committed to storage?

fra · 9h ago
Litestream has seen very little development lately and I was worried it was dead. Very glad to see Ben Johnson is continuing to push the project forward with some exciting new plans.
avtar · 4h ago
That's the conclusion I reached a couple months ago when I was evaluating similar tools. The last Litestream release was issued in 2023 and the official Docker image is over a year old. In the end it seemed like a safer bet to accept some inconvenient tradeoffs and just create backups more frequently.
tptacek · 4h ago
Ben also wrote BoltDB, which was untouched (archived, even) for years despite a thriving community. Sometimes things are just done!
m3sta · 5h ago
Is there anything like Livestream that can be just pip installed?
caleblloyd · 8h ago
Is the backend pluggable? Could it be configured to write to any key value store with support for optimistic concurrency control?
benbjohnson · 8h ago
We don't support plug-ins at the moment but there's several backends at the moment (S3, Azure Blob Storage, Google Cloud Storage, SFTP, etc)
yowmamasita · 6h ago
tangent: in modern SQLite, are writes still serialized? That's my main concern when choosing a tech stack for an app that might have thousands of writes happening on peak periods
simonw · 5h ago
Yes they are, but if you benchmark thousands of writes a second you'll likely find that SQLite does just fine.

You might start running into problems at tens or hundreds of thousands of writes a second, though even then you may be OK on the right hardware.

soamv · 4h ago
nodesocket · 8h ago
Is there a migration guide from stable to the branch 0.5? I’m running Litestream as a Docker sidecar alongside my Python app container and it’s been great and a nice comfort knowing my SQLite db is backed up to S3.
ignoramous · 8h ago

  We have a sneaking suspicion that the robots that write LLM code are going to like SQLite too. We think what coding agents like Phoenix.new want is a way to try out code on live data, screw it up, and then rollback both the code and the state.
Prescient.

Agents would of course work well if they can go back in time to checkpoints and branch from there, exploring solutions parallely as needed.

Anyone who has experience with building workflows (Amazon SWF, Temporal, and the like) knows how difficult it is to maintain determinism in face of retries & re-drives in multi-tier setups (especially, those involving databases).

Replit recently announced their Agent's integration with Neon's time travel feature [0] for exactly the purpose outlined in TFA. Unlike Fly.io though, Replit is built on GCP and other 3p providers like Neon and it is unclear if both GCP & Databricks won't go all Oracle on them.

[0] https://blog.replit.com/safe-vibe-coding

nico · 9h ago
Very cool idea, I wonder if that works better than their Postgres instances

Recently, I deployed a little side project using a small postgres vm on fly.io After a couple of days, and only having about 500kb of data stored in that db, the postgres vm went into an unrecoverable fail loop, saying it ran out of memory, restarting, then immediately running out of memory again, so on and so forth

It took about 3-4hrs to recover the data jumping through a lot of hoops to be able to access the data, copy it to another volume and finally download it

I would've reached for support, but it seems like the only option available is just posting on their forum. I saw a couple of related posts, all with unsatisfactory answers unfortunately

To be fair, it was incredibly easy to get up and running with them. On the other hand, almost all the time I saved by that quick start, was wasted recovering the failing db, all the while my site was down

Ironically, I originally developed the project using sqlite, but then switched to postgres to deploy

tptacek · 8h ago
This post has nothing to do with Fly.io's platform offerings. Litestream is completely uncoupled from Fly.io. Ben started it before he got here.
sosodev · 6h ago
Clearly it does have something to do with fly.io considering fly is and has been pushing for litefs/stream as the ideal database solution for fly users. It seems reasonable that readers would compare it to other fly offerings.
tptacek · 6h ago
We have... never done that? Like ever? LiteFS is interesting for some read-heavy use cases, especially for people who are doing especially edge-deployed things, but most people who use databases here use Postgres. We actually had a managed LiteFS product --- LiteFS Cloud --- and we sunset it, like over a year ago. We have a large team working on Managed Postgres. We do not have a big SQLite team.

People sometimes have a hard time with the idea that we write about things because they are interesting to us, and for no other reason. That's also 60-70% of why Ben does what he does on Litestream.

sosodev · 6h ago
I’m sorry. I think that I, and probably others, have misinterpreted it. Between Ben’s writings on the fly blog and litefs cloud it seemed like that was the case. I didn’t realize it had been discontinued.
tptacek · 6h ago
Neither LiteFS nor Litestream (obviously) have been discontinued. They're both open source projects, and were both carefully designed not to depend on Fly.io to work.
yellow_lead · 8h ago
It's strange to me that they still haven't offered a managed Postgres product. Other providers like Render or even Heroku seem to have realized that this is a core part of PaaS that customers want. Instead they focused on GPUs and LiteStream. When I evaluated different PaaS for the startup I work at, I had to go with Render. I couldn't even give Fly.io a try since I knew we needed Postgres.
tptacek · 8h ago
We're rolling out Managed Postgres, very slowly.
yellow_lead · 6h ago
Looking forward to it!
nico · 8h ago
It think they are in beta. I wished they had a managed Redis though

For Postgres I ended up going with Neon (neon.tech), very happy with them so far. Super easy to setup and get up and running, also love being able to just easily see the data from their web interface

biorach · 8h ago
sergiotapia · 7h ago
Try Railway - nothing but good experiences with these dudes. Fairly priced and great dev UX.
apitman · 4h ago
You might try paying the $29/mo. I've found the email support to be great.
gavinray · 10h ago
Just a heads-up, the link in the "Litestream is fully open source" callout is malformed and leads to:

https://http//litestream.io/

tptacek · 8h ago
Thanks!
mixmastamyk · 8h ago
For something rather new there seems to be too many choices already. Please pick a strategy under one name, good defaults, and a couple of config options.

No comments yet