Serverless SQLite
sql.lspgn.workers.dev
sql.lspgn.workers.dev
My https://datasette.io/ project is built around a similar idea to this: the original inspiration for it was Zeit Now (now Vercel) and my realization that SQLite read-only workloads are an amazing fit for serverless providers, since you don't need to pay for an additional database server - you can literally bundle your data with the rest of your application code (the SQLite database is just a binary file).
If you want to serve a SQLite API in an edge-closest-to-the-user manner for much larger database files (100MB+) I've had some success running Datasette on https://fly.io/ - which runs Docker containers in a geo-load-balanced manner. I have a plugin for Datasette that can publish database files directly to Fly: https://docs.datasette.io/en/stable/publish.html#publishing-...
We are toying around with the idea of launching a Cloud SQLite product targeting this exact use case.
How large are your data sets?
Would you be interested in a quick call to discuss your needs in more detail?
We would price such a service to be competitive with the obvious alternative of using a long-running VPS or ec2 instance.
It’s been working extremely well and it runs fully sandboxed in a separate worker thread with zero network traffic after the source data has been transferred across. With computational notebooks running alongside it, you can do some pretty powerful analytics with very low latency and it’s great to be able to do inserts and complex queries entirely client-side.
SQLite is one of the greatest software projects I know.
(first published 2007, before the more recent misuse of the term began)
From the two definitions found in https://www.sqlite.org/serverless.html
classic serverless --> "embedded database" exists and is often used
neo-serverless --> I suspect that this is a marketing term used to attract cool people to new cloud offerings (like "jamstack" for services such as netlify). There is no good replacement here because the term was tied to this new kind of infrastructure really early. But anytime I hear someone repeat "of course serverless does not mean there is no server!" I die a little more.
Naming things is hard but at least we ought to try to come up with terms that are not blatantly misleading.
No one has the power to change this. It's like saying "I think the word 'spoon' is stupid, let's all call it 'scooper' instead." This is our language now, it is what it is. Vendors offering serverless solutions have to call it "serverless" whether they like it or not because that's the word customers understand. You can keep complaining about it, but it won't change. You might as well accept it and move on.
"Cloud" is a stupid term too, your servers aren't really floating in the sky. But here we are.
Sometimes I complain about some of those too.
Personally, I'm looking forward to the next loop around, when the concept is rediscovered again. It will need a new name. Unfortunately, that's probably going to be 20 or 30 years.
I'm the lead engineer on Cloudflare Workers. We didn't originally call it "serverless", but after talking to lots of engineers who said "Oh so it's serverless?" we decided to go with that term. The decision was not made by marketers.
That's my excuse for being so slow to grasp "cloud". When AWS made EC2 public, I really didn't understand why anyone would want to use it.
Cloud era "serverless" just pisses me off. The applicable cliche is "Every sufficiently complex C project recreates LISP, poorly."
It's seems like we're doomed to repeatedly reinvent the past. Championed by youngsters who never read the book.
Maybe this explains "worse is better".
I know, I know. I've become the old crank. All you noisy kids get off my lawn.
Robert Morris' addendum is, "Including Common Lisp."
If you don't believe Robert Morris, tell me what LOOP does. :-)
(Note, this is the Robert Morris who wrote the first major internet worm, cofounded Viaweb with Paul Graham, and cofounded YCombinator, again with Paul Graham.)
Personally the whole indexdb, localstorage really break the web page as a stateless model. Why do you need save so much local data to just maintain the session? Stop putting everything in the web browser.
What I'm curious is if (1) serverless is cheaper than hiring competent sysadmins who can maintain the infrastructure instead and (2) are these savings worth being locked into a chaotic architecture and boring proprietary tooling that is forced on you for the profit of the Google, Microsoft, and Amazon monopolies?
I've recently entered the job market and personally find no joy in working in serverless environments because of the latter.
It comes down to if you want to have generic and reusable sysadmins vs. cloud serverless specialists.
Storing data locally is often out of convenience or possibly for cached data for offline support.
There are valid reasons for maintaining local state.
I guess that's to replace the traditional desktop application with something that can be deployed over the web?
AWS marketing is very good.
Serverless was a creation of the AWS Lambda team / AWS marketing department "I helped start the serverless movement..." from the LinkedIn of Tim Wagner (https://www.linkedin.com/in/timawagner/)
Worker-based or FaaS (function as a service) don't roll off the tongue that well.
I'm not advocating for the term, just trying to explain why it is so popular.
Language does change and evolve. The misuse and subsequent additional meaning for “literally” to now also be a simile for “figuratively” is a good example of how this isn’t necessarily always a good thing.
I always find this particular example to be somewhat self-contradicting for this reason.
[1] https://www.merriam-webster.com/words-at-play/misuse-of-lite...
If a change diminishes the clarity, efficiency or even the beauty of the language for no good reason, then it's a bad change, at least for the purposes of communication.
A simile would require a sentence in which "literally" is compared to "figuratively", wouldn't it?
My impression, as a non-native speaker, is that the misused "literally" is to indicate exaggeration, not the quality of being figurative.
Used to be. Now "literally" literally means "figuratively". [1]
> Can literally mean figuratively?
> One of the definitions of literally that we provide is "in effect, virtually—used in an exaggerated way to emphasize a statement or description that is not literally true or possible." Some find this objectionable on the grounds that it is not the primary meaning of the word, "with the meaning of each individual word given exactly." However, this extended definition of literally is commonly used and is not quite the same meaning as figuratively ("with a meaning that is metaphorical rather than literal").
That seem to confirm my impression that "literally" is used to indicate exaggeration, rather than being figurative.
Edit: formatting the quote
Complaining that modern people are literally ruining the word literally is a popular internet gripe.
It's just language, you might disagree but usage determines correctness (eventually).
Also, out of a cost perspective, running a VM with SSD for cheap with SQlite will give much more requests than a CF worker for much less.
Adding writes to this is also very limited due to the max 1sec write per KV key limit.
Which is why it takes a lot less CPU time to do streaming and even to some degree, a streaming parsing of the content.
It runs out of CPU-time at 6MB of index though.
There's someone that made a WASM for full-text search too, it's definitely faster and can handle quite a lot more text.
My idea is to modify SQLite to use ajax with the HTTP Range header to fetch B+ pages from the server as they are needed. SQLite already has a VFS (virtual file system) so this shouldn't be too hard.
I am not sure how fast it would be and it would waste a lot of bandwidth. That's why I haven't made it yet.
This would only be useful for using it with Github pages.
They are used to share structured and unstructured data in a p2p way where a torrent could be a database(structured) or a fileset(unstructured) .
But all of this is part of a bigger project that is basically a new sort of p2p "app browser" with a local-first emphasis but where every app can share its functionality though RPC (locally or remotely) with distribution going over DHT's and torrents.
> The upper bound on [the number of keys on an interior b-tree page] is as many keys as will fit on the page.
I think a tricky part of this idea would be the locking. Usually SQLite relies on the locking of the underlying filesystem. You could add your own mechanism that causes a lock to be assigned to a single client connection, but what if it never unlocks? (On a single machine you can tell if the client process has crashed.) You could add a timeout but what if the client process then does respond?
It is going to be read only.
Locking wouldn't be problem because in the eyes of the sqlite running in the browser it would have it's own read only copy of the database.
Even with an artificially slow connection it seems to be reactive enough. Actually fetching pages on-demand can only be better for the bandwidth, the real issue is going to be latency
Seriously though, if it's Truing complete, you know it'll be abused to do something completely unintended, like run a ray tracer or something.
[1] https://github.com/sql-js/sql.js [2] https://ml-ranking.geospiza.me
Yes but now it runs on someone else server! Wait a minute, this makes no sense...
'serverless' is perhaps the stupidest marketing buzzword developers have come up with.
Catchy like vagrant but perhaps a bit insensitive (unless it was used to highlight the plight of the homeless).
Less catchy - Poste Restante or General Delivery
"Don't care where it runs, don't want to manage it, I want to pay only for when I actually use it, thanks for managing it, here's some extra cash for the effort"
But you can only apply that metric if you remove the end users from actually touching the machines (virtual or real).
This is the "less" in serverless.
Turns out that this is also something people want: not having to be on the hook for actually administering machines, installing security patches etc etc.
So managed (platform as a) service + fine grained billing
Managed service
> Recently, folks have begun to use the word "serverless" to mean something subtly different from its intended meaning in this document. Here are two possible definitions of "serverless": Classic Serverless: [...] Neo-Serverless: [...]
SQLite was already "Classic Serverless". Now it's "Neo Serverless" as well.
We've been building an experimental shared file system that specifically targets the FaaS setting. It supports SQLite and gets big performance gains over NFS/EFS, especially on read-mostly workloads, due to improved local caching and lock elision. See: https://arxiv.org/abs/2009.09845
How do you deal with ephemeral file storage? I guess you actually need the provider (say AWS) to build this into the platform?
For running a write-enabled DB on a CF worker a major problem is that the only storage option that I could find has really low write limits [0], 1000 writes a day for the free option. "Durable Objects" is a beta API, perhaps its transactional-storage-api [1] has better limits?
--
0: https://developers.cloudflare.com/workers/platform/limits#kv...
1: https://developers.cloudflare.com/workers/runtime-apis/durab...
Client issued arbitrary queries is one of the use cases for GraphQL and publishing immutable data sets on the web is the main use case for Simon Wilson’s Datasette [2].
In-memory SQLite compiled to WASM works in the browser and Node.js too. In the future, we can expect proper ACID operations on any WASM runtime that supports fsync in WASI [3], a POSIX-like API.
[0] https://en.m.wikipedia.org/wiki/Two-phase_commit_protocol
But they are limited to read only files.
Cloud flare workers allow running simple programs at the CDN node closest to the user.
SQLite is embeddable C code that is like a normal SQL server just without the network parts - just the sync functions embedded into your process.
This wraps SQLite with the networking and CDN abilities of cloud flare, allowing you to http-get a subset of data dynamically using SQL (that would not be possible with the simple “download 100% of file X”).
Workers KV imposes 25MB limit per key. Worker memory limit is 128MB. Concatenating several values from the store or using sqlite's ATTACH DATABASE should make possible querying of about 100MB large databases, would be my guess.
A small DB to search in a list of storefronts which typical retail websites have, a database of flags or promotion codes which you don't want to send to the browser are some examples I came up with.
Personally I would write a code generator to embed the data in the code but to each their own.
We use KV and workers to serve static data (json) to browser based code.
This could be used to filter, sort or aggregate that data before sending the client.
Perhaps for inventory / product lookup on a e-commerce site.
There's no ability to change the anything through the SQL. It spins up a new sqlite db every time, and builds the table in memory.