DEV Community

Cover image for SQLite for JavaScript bundles, plus a distributed version on Lambda

SQLite for JavaScript bundles, plus a distributed version on Lambda

Edoardo Dusi on December 03, 2026

A JavaScript bundler takes hundreds (sometimes thousands) of modules and turns them into a single file a browser can run. Every bundler you use, we...
Collapse
 
nilesharma0108 profile image
Nilesh Sharma •

Running linking as recursive SQL is a fun idea, and discovering the import graph one level at a time explains the four to eight times remote slowdown better than blaming the network would. One thing I kept thinking about is the build lock. AWS's docs say an If-None-Match write fails whenever "an identical key name is found in the bucket", so the lock only clears when something deletes that object. If the builder times out or gets killed mid-build, what stops later visitors from seeing "another visitor started this build" forever? Does the lock object carry a timestamp or owner so a stale one can be taken over?

Collapse
 
edodusi profile image
Edoardo Dusi AWS •

Good catch, and you read the docs right: the create-only write never clears itself. Two things cover it. The lock body is just a timestamp, and when a visitor finds an existing lock older than two minutes it treats it as a dead build and takes it over with a second conditional write, IfMatch on the ETag it just read, so if two visitors spot the same stale lock only one of them wins.

Then a lifecycle rule on locks/ expires anything older than a day, as a backstop. No owner id in the object, the ETag does that job. It's in acquireLock() in distributed/serve/server.js if you want to look at it. Two minutes is generous for this demo, a real system would size it from the slowest build plus some slack, or heartbeat the lock while building.

Collapse
 
nilesharma0108 profile image
Nilesh Sharma •

The IfMatch takeover on the ETag is a neat trick. It makes stealing a stale lock safe without storing an owner id, and the lifecycle rule covers the case where nobody comes back. Heartbeating the lock sounds like the natural next step for longer builds. Thanks for pointing me to acquireLock().

Collapse
 
smtahosin profile image
S M Tahosin •

Hey Edoardo! 25 of 56 checks passing, query returning same number whatever you asked... I've been handed that 'done' lol. recursive SQL for ResolveExport, I'd steal that xD :)

Collapse
 
edodusi profile image
Edoardo Dusi AWS •

Ha, thank you! Yeah the function was fast because it never read the question :D That's why I now ask the agent for tests it didn't write for itself before I read any walkthrough! Steal away, the linker is in src/sql.js in the repo and the same query runs in the plain sqlite3 shell

Collapse
 
smtahosin profile image
S M Tahosin •

Thanks Edoardo!! tests it didn't write for itself, ok that one's going on my wall lol. tuesday night mine... wrote a test, passed, I was hovering over merge and then wait, the expected value was just the bug wearing a hat?? nearly shipped it, tea was already cold. src/sql.js tonight then, if sqlite3 shell runs it I can actually poke at it :D

Thread Thread
 
edodusi profile image
Edoardo Dusi AWS •

"The bug wearing a hat" is going on my wall now :D

Thread Thread
 
smtahosin profile image
S M Tahosin •

deal lol, wall trade accepted

mine's still that tuesday one... 1am, tea gone cold, me reading the expected value out loud like 'hold on. hold on hold on' because it was literally just the bug again?? green tick and all. haven't trusted a first green since, not really. anyway thanks Edoardo, needed that laugh tonight :D

Thread Thread
 
edodusi profile image
Edoardo Dusi AWS •

Never trust an agent 😄 Glad I've helped!!!

Collapse
 
syedfahads profile image
Syed Fahad •

the database storing a copy of itself inside itself is my favourite row in that claims table lol. an accidental quine