Exploring some new tech that can live forever

Tuesday, 8/13/24
996 words
5 minutes

tl;dr

  • Astro + Turso is FAST

  • Evolu is LIGHT

  • SQLite is GOAT and will live forever

"SQLite is likely used more than all other database engines combined."

Part of the SQLite documentation, which has been released by author D. Richard Hipp to the public domain. SVG conversion by Mike Toews., Public domain, via Wikimedia Commons D. Richard Hipp, Mike Toews. Public domain, via Wikimedia Commons

"SQLite is probably one of the top five most deployed software modules of any description."

Summary

I've been having two magical (and very different!) DX experiences with TypeScript + SQLite.

Both of these are mobile-first PWAs -> save to Home Screen, with Easter eggs for wider desktop screens:

  1. "Nebula": Astro + Turso

  2. Evolu on Vite


Astro

Astro: FAST code with minimal JavaScript, Astro Islands, multi-framework support (a provably agnostic common layer). Works on serverless Edge and connects to distributed, replicated SQLite via Turso. Drizzle is deeply embedded in the ecosystem, and Zod is native. Was easy to get type safety between front- and back-end, and I find itty.dev's itty-fetcher + drizzle to be more delightful DX than tRPC.

Best-of-all-possible worlds:

  • Astro is easier to reason about than Remix
  • Astro on CF works so much better than Next on CF
  • React on Astro has much better support than React on Hono (which seems fine tbh?)
  • Astro DB will integrate Turso SQLite in a managed service soon

Downsides: Astro on Cloudflare Pages has to spin up with each connection, in order to handle light server-side state ("what default did the user specify previously?"). Each page is its own stateless container, not an "app" like React on Next/Express/Fastify or even a serverless React Router with cross-page shared and persistent state via any number of state management libraries. While Astro provides really nice middleware for context, it still needs to make a connection to Turso's DB API for each SSR page. It depends on access to a puny, but persistent, server-side store to handle sessions for OAuth.

While I love the concept of nanostores, in order to persist them, you need to go to localStorage. But then, how does one island component know that the user has interacted with another island? You end up wiring signals between client-side island components, and it feels like the wrong tool (a superb CMS and modern content/blog platform) for, let's say, a heavily interactive mobile app.

text
To grab a snapshot of my data:
- switch `@libsql/client/web` to `@libsql/client/node`
- sync to an embedded db with a local-file uri
- total elapsed: ~5 seconds.

Evolu

Evolu: SUPER LIGHT built on Vite + anything; a reactive database behind a Suspense wrapper; local-first and synced with any browser that knows the 12-word mnemonic. No auth required, just knowledge and Evolu Server delivers magic sync / data ejection. Kysely for query building: IMHO nicer than drizzle, which locks you into a specific ORM when what you really want is lite-code type safety.

The stack:

  • meant for building a SPA / PWA where a server serves static files
  • files cached by CDNs to leverage web infra and get closer to the user
  • Web Workers and OPFS enable true offline, local-first experiences

Downsides: We are so early. Evolu is a work in progress, empowering users with native privacy, ownership, and portability by construction. Whereas the money for local-first tech apears to be in serving enterprise SaaS for massively collaborative online experiences like Canva, Descript, Figma, etc. The Evolu dev community appears to include some absolute chads, but the vibe is kinda anti-money and anti-centralization.

text
To grab a snapshot of my data:
- a trivial library function exports a blob
- export to user on click (AI knows how to write this code)
- it's a button on the webpage now. 1 click, <1 second

Early Conclusions

Astro + Turso are rock-solid projects, that have ~5 years to gain developers' mindshare before the world moves on to the next hot frameworks. At least they are built on proven and Lindy technologies like JavaScript and SQLite, and have clearly done the work to achieve deep coupling with Vite + Typescript + Zod + Tailwind, while keeping loose couplings with React, Vue, Svelte, Solid, tons of CMS solutions, Netlify, Vercel, GH Pages, CF Pages, Deno, AWS SST, Google Cloud, Fly, Render, etc.

Meanwhile, Evolu is SIMPLE. You don't even need auth to achieve privacy!! But, there's only maybe 5 active devs in the entire world, building Open Source just behind the bleeding edge. Who knows how it will scale, when sync messages contend with the entire internet discovering free, private, "limitless" storage. There's no pricing model AFAICT, just more users spinning up perhaps their own private sync networks. If it comes down to that, I'd do it in a heartbeat. Like free, self-sovereign Dropbox for structured data.


Part of the SQLite code, which has been released by author D. Richard Hipp to the public domain. (SVG version: Raphael Javaux), Public domain, via Wikimedia Commons D. Richard Hipp, Raphael Javaux. Public domain, via Wikimedia Commons

Some other contenders

show/hide

I was gonna start building on ElectricSQL, but they are pivoting. They appear to be kinda starting over, leaning harder towards Postgres and doubling down on the sync layer, while leaving the fully-integrated developer experience for others to solve. For months beforehand, I've been following Kyle Mathews (Gatsby founder) building AWS and Docker ElectricSQL starter templates for *checks notes* a household recipe app, and felt it was industrial-grade tech for local-first apps meant to scale to many synchronous users.

Then I discoverd PowerSync, which has been in prod for ~15 years, but it's highly opinionated about sync with strong vendor lock-in. Vlcn.io has also been around for a while, focused on CRDT as well. They appear to have a roadmap and emphasis that guarantees them research jobs for life.

I just want to write to a database, see it reflected across mutiple surfaces, and have it be cheap (free) to maintain. Not replace a battle-hardened PaaS (Firebase/Supabase) with upstart SaaS on trivial hardware, and lose braincells over CRDT implementation details.

Title:Exploring some new tech that can live forever

Author:artlu99

URL: https://artlu.xyz/posts/sqlite-for-web

Last modified:


This work is licensed under CC BY-NC-SA 4.0 .

長話短說 (short + sweet):
Thanks for reading, anon!