A database for 2022 · Tailscale
tailscale.com/blog/database-for-2022/Posted Apr 2, 2022, 4:31 AM UTC
Posted Apr 2, 2022, 4:31 AM UTC
Something I really appreciate about tailscale is the accessibility of the blog posts. They hit that sweet spot between technical knowledge and accessibility, and do so in a way that, if not neutral, is at least transparent.
It's pretty rare to have someone with deep technical knowledge and the ability to explain it well. The tailscale blog does a great job of that. CloudFlare does that pretty well too.
Great post. Love seeing SQLite get the recognition it deserves.
I think I remember reading the previous blogpost, where they moved to etcd.
I look forward to the next post, where they move to Kafka, or maybe finally to Postgres. (I kid)
"A database for 2023"
Wait till they discover postgresql can store JSONs!
They will make database out of JSON blobs stored in postgres
This sounds a lot like logical replication in Postgres.
Litestream author here. It's a lot like physical replication in Postgres. It's a technique called WAL shipping and it's basically how Postgres async replication works. There's also a Postgres WAL shipping tool that sends to S3 called wal-e although I haven't used it myself.
Footnote: coworkers point out it’s April Fool’s today and request that I clarify this isn’t a joke. Joke’s on them: every day’s April Fool’s in the Tailscale Database Engineering department.
Why not a cloud provider managed postgres or MySQL?
Maybe costs
How does one do quick iterative development with sqlite though? It doesn't support things like DROP COLUMN for when your schema is changing rapidly so you have to write more migration code when changing your data model.
are unstable database schema a mandatory part of quick iterative development
What's unstable about schema changes?
Looks like they added support for this a year ago: https://stackoverflow.com/a/5987838/66101
I see, then sqlite is more than viable for modern apps. Being able to change schemas quickly was a dealbreaker for me a while ago.
So essentially they're using lightstream to stream incremental changes from an sqlite database via minio across cloud providers. Since the changes are incremental, that could be a heavy cost savings for data which doesn't change often.
The implications for this are pretty extraordinary. A very inexpensive self-hosted distributed database solution.
Would this be theoretically possible for any database that uses WAL?
Litestream author here. Yes! It's not a new technique. It's called WAL shipping and that's how Postgres' async replication works. There's also a tool called wal-e that came out of Heroku that ships WAL files to S3 just like Litestream does.
It doesn't even have to be WAL-based system. Backtrace Labs has a SQLite virtual file system (VFS) called Verneuil that works similarly but works with the rollback journal instead of the WAL.
Yup! PostgreSQL even got hooks where you can put your own commands to set/get WALs.
Of course that works only for master/slave setups but it does work.
I don't quite understand how it works. Is it treating fruits.db as append-only? Doesn't it have to reupload the entire file if you change a previous record? Would it work with more than one table?
It's uploading the WAL (write ahead log) to storage. It's a log that contains all operations that are run on the database. So it's entirely possible to delete records. Just have to replay the WAL.
Aha, I guess it can also occasionally merge the WAL into a db-file for performance. Or is there no db-file uploaded to storage, only every single operation ever made?
Is this also called event sourcing? Keeping a log of all operations, being able to replay them to get the current state.
On the local db side, SQLite periodically merges the logged changes into the main db file, and they could do the same on the backup side whenever they choose to.
That’s an interesting comparison to event sourcing. I wouldn’t say it’s the same thing as this, but it’s definitely related. You could implement something like this by treating individual entries in the WAL as messages on something like Kafka if you wanted to. That isn’t necessarily going to work if you want to replicate well across the public internet in a very distributed fashion, but it could work for something similar to this implemented internally.
[deleted]
[deleted]