WebAssembly is eating the database?
dylibso.com
dylibso.com
Naturally one needs to sell WebAssembly as being the first of a kind.
Without exception the existing APIs mentioned in this article don’t attempt to handle “data sandboxing” since it’s so application specific. So it remains the case that exposing your db to user defined functions is dangerous without a ton of work, and WASM in no way reduces the amount of work needed.
This is because UDFs can write to tables, and perform I/O in other ways depending on system configuration and security policy. Just because the UDFs are in WASM instead of one of the other UDF languages doesn't eliminate the need for a security system.
(Aside -- curiously in PostgreSQL, the privilege system isn't even strong enough to prevent something as innocuous as e.g. reading a view owned by another user from dropping your own tables.)
[1] https://www.postgresql.org/docs/15/sql-createpolicy.html#id-...
https://blog.cloudflare.com/mitigating-spectre-and-other-sec...
"User-defined functions (UDFs) have been a fixture in database systems for a considerable period of time, allowing users to extend the database’s built-in functionality to complement good ol’ SQL."
Granted, I'm biased, but I think we did a decent job elaborating from there on the novelties WebAssembly brings to this age-old field.
> developers are in most cases forced to use unfamiliar programming languages, typically unique to the database itself.
What parent correctly points out is that this simply isn’t true. Your examples of novelty are all things that were possible decades ago in most mainstream DBMSes. The SQLite one in particular is bizarre: it’s inherently an embedded db with bindings in every language.
Supporting user defined functions as compiled objects loaded into the database is as old as the hills. The sandboxing part is silly since no one in their right mind is going to expose their database to untrusted users in the first place.
Leave it for kernels and drivers.
Plus GraalVM runs LLVM bitcode if you have such a desire.
That's circular logic. You would not do it when it's unsafe. But when it is, it could open up entirely new use cases. Most obviously, infrastructure-as-a-service offerings.
In the general case using WASM as an object format does nothing to actually enable this use case beyond what exists.
It doesn’t really matter since this “untrusted user functions in the db” scenario is incredibly niche. The vast majority of database usage involves data access patterns entirely controlled by the developers of the system. Stored procedures in a variety of languages have long been available to such developers _and are generally considered an anti-pattern_.
I've seen projects do exactly this, with PostgreSQL row-level security.
https://www.graphile.org/postgraphile/
EDIT: Though to be clear, it does seem a terrible idea to me too....even when you prevent unauthorized access, there is always the issue of resource usage.
As mentioned by other people there have been attempts to allow writing UDF using the JVM, Javascript, Python and so on, by they never caught on (and some of them are difficult to install) and are not that portable to other database vendors, they require installing third party extensions and so on.
I for one see WASM to be a good candidate for a really portable solution.
My only worry in all this (and wasm) in general is how well you can debug this later - be it interactive, or postmortem dump. I'm having my reservations, but would have to experiment and see.
So far the best integration I've seen between different languages/runtimes have been C++ / .NET (C#) and C++/CLI (e.g. their managed C++) - I can debug, step in, post-mortem debug without an issue.
I can't even do this properly with GoLang, and had mixed success with Python (+.pyd files).
Debugging (interactive, and post-mortem) is often overlooked, and thought about later.
But I'm all excited about wasm now :)
Isn’t that a step backwards? De linking them means you can scale the two appropriately independently.
I guess if you’re using could and can “steal” a bit of compute that way it makes sense.
It could be for some use cases, but there are significant efficiency advantages to processing the data where it lies instead of shipping a copy to separate compute services.
It's definitely situational, and this can be true! But, generally its this kind of scaling optimization on everything that has us drowning in microservices today. If we can afford to "steal" some compute from the DB server, and minimize the amount of infra spun up for things that are basically scripts, I consider that a win.
If Network I/O between your compute and data dominates every other dimension, you might want to to collocate compute and data.
Being able to fit the architecture to the performance of the workload is a good thing.
Today there are lots of practical ways to autoscale databases and colocating data and compute is generally good for performance and simplicity (your mileage may vary for simplicity).
Ideally you want scalable storage with compute (assuming really large datasets), so you can move the computation, which usually is small, close to the data.
In any case, it's not one size fits all, and each problem space matters.
We blogged [2] about this feature, and you can read the relevant PRs [3] containing the changes necessary for its implementation.
[1] https://seafowl.io/docs/guides/custom-udf-wasm
[2] https://www.splitgraph.com/blog/seafowl-wasm-udfs
[3] https://github.com/search?q=repo%3Asplitgraph%2Fseafowl+wasm...
Backend in Elixir, with Extism embedded and example plug-ins in Rust and Javascript!
How this all works varies a lot between databases, so what works in one may not be optimal in another.
There is a valid concern with using extra CPU/RAM on a (hard to scale) database rather than (easy to scale) application servers.
But it all depends on what you are doing, your tenant model, etc.
It is possible that there are a lot of tool to examine JS code for "suspicious code" and that those tools might not work well on WASM.
In practice the WASM interpreter in the browser is a functionality that can be (almost) completely polyfilled.
Personally I would be way more worries about hardware exploits via WebGL.
But it is probably already possible with JSFuck and webworkers.
It does get recompiled to bytecode that runs directly on the processor, so in theory there could be vulnerabilities that come up from that, but I think it’s a pretty well-understood surface area at this point.
Edit: read the first half of my sentence again.
I think that's because the word "binary" has connotations that aren't strictly technically justified. There's no difference between running WASM and running JS (which is usually obfuscated anyway). Both are JITted into machine code, and it's important the JIT is implemented securely. (JIT compilers have been sources of exploits.) The only difference is complexity of the source language, where simpler languages are easier to secure. And WASM is orders of magnitude simpler than JS.
You can already do things like http://www.jsfuck.com/ and even more complex ones, but they would likely have bad performace.
With wasm you could do malware-level obfuscation with less drawbacks.
(Obviously, as WASM JIT compilers get more elaborate and it incorporates things like GC'd references, some of the advantages of this design wrt simplicity will disappear, but I anticipate that these kinds of features will mostly not be used in settings like databases).
Unfortunately, the design of WASM and common compilers targeting it means that your security is at risk as a user, even though your PC is safe. Applications compiled to WASM have a wide variety of fun security vulnerabilities that have been gone on native targets for decades, which means that if (for example) Gmail moved to WASM, it would now be possible for malicious parties to attack your Gmail tab even though they can't attack your PC. Some examples:
* Address space layout randomization is gone - if an attacker gets a write-anwyhere primitive, it will work 100% of the time
* Function pointers are densely packed - any possible value within the correct range (0 - function count) is a valid function pointer, as long as the signature matches. Even worse than not having ASLR.
* Page protections are gone - all data is mutable, even things that shouldn't be like string constants compiled into the binary
* Zero page accesses don't trap - while compilers go out of their way to try and make reading/writing from null pointers fail in WASM, the actual runtime happily allows you to do it. This makes attacks easier to execute because while stray nulls would kill a native application on dereference, in WASM they will just yield a 0 and execution will often continue.
* Most stuff is static linked - for native applications, it is common (albeit less common now in our modern era of Electron Hell) to pull in services from the OS and its packages, whether it's zlib or https or whatnot. The WASM runtime model generally offers a very limited set of capabilities in comparison, and there's no equivalent way to dynamically link against vendored packages that get security updates automatically. So every application ships its own ICU (for time zone and localization data), ships its own zlib (for compression/decompression), ships its own crypto (because the browser crypto APIs are extremely limited and async-only), etc...
Ultimately WebAssembly runtimes are very secure, but you have to protect everything else from the code you're running, because the code itself can easily be attacked by uncontrolled input.
Flash, Silverlight, Java Applets, and loads more stuff existed while people were still OK serving stuff up without SSL, trying to figure out cookies and generally not putting a lot of thought into cross site scripting attacks. That was a security nightmare and all the obvious things happened. WASM does not seem like a repeat of that. Rather it builds on all the learning we've had since then.
Other than a few extremely niche situations (maybe browser-based gaming?) does anyone ever really think to themselves "wow I should really use WebAssembly here?" Even the post itself doesn't talk about any real solutions, just about what might be possible:
> database platforms could gain these additions with little to no incremental work required
Ultimate cope. It's the classic solution looking for a problem.
(Edit: mass downvoted by the WASMOOOORS)
WASM will eat SPAs and a chunk of the gaming market, it's just a matter of how long it takes.
Ah yes, the classic "we're still early"—might I introduce you to cryptocurrency? Apologies for the snakiness, but if it hasn't happened in the last 10 years, do you really think it will happen in the next 10?
It's like implementing Photoshop in Python. Why would you do that?
The lift here is astronomical, not to mention that companies just want to get a merch store up. No business person or product manager really cares about the "runtime."
But you dodged my question: do you think that a technology needs two decades to really "mature?" Go and Rust clearly solved real problems (or at least are fun to use) and we see many developers leveraging them. Even React (which I personally hate) made things easier for front-end devs. WASM adoption is virtually zero.
The use case is less traditional websites and more performance-demanding "apps." (And non-web uses for portal runtime.)
You fundamentally misunderstand the purpose of WASM for web development. It is not another web app framework or programming language. It's a platform for building frameworks/DSLs.
Of course the "business person or product manager" doesn't care about the runtime. They also don't care about 99% of the Web APIs or how React was implemented. They don't have to, because that work was done by the people working on the runtime (or reactive framework). WASM is for the latter group.
Average webdev yesterday wrote PHP/HTML and JQuery.
Average webdev today writes React DSL (e.g. TSX) for a monstrous "runtime" hacked together in JS.
Average webdev tomorrow writes Python for a reasonably fast Python interpreter implemented in the browser with WASM [1] (and maybe written in Rust).
[1] - https://pyscript.net/
Python is just as hand-wavy as Javascript, so I fail to see the win here. At least C/C++/Rust/Go give you some neat guarantees, but you lose all the velocity JS gives you. I mean, pyscript doesn't even support hot reloading out of the box, but yeah, I'm sure it's definitely the future. Besides, you could probably just write the interpreter in vanilla JS and it would be comparably fast (at least in Chrome), so WASM is completely superfluous.
Wow, imagine if you could compile these to WASM.
> Besides, you could probably just write the interpreter in vanilla JS and it would be comparably fast (at least in Chrome), so WASM is completely superfluous.
This one is going in the orange site bookmarks, lol.
I mean, benchmarks say the performance gains are from 0.2%-60% comparing vanilla JS to WASM given various browsers (keep in mind it's not even twice as fast even in synthetic benchmarks). So I guess you're right: if I built my next todo web app, I'd definitely want to change my entire workflow, write a custom purpose-built runtime, and transpile from Python to WASM to eek out that sweet sweet performance in Google Chrome.
I don't even think we live on the same planet.
I've no idea why you think that situation is a close analog to WASM.
Those people seem to get excited at the idea that you could build web apps with a “real compiler”.
But personally I just don’t buy that JavaScript is the reason web development is hard. I think it’s just the natural outcome of the fact that the capabilities of browsers are both varied and ever changing, and therefore the expectations of clients are always changing, and therefore the tooling to be able to (relatively) quickly meet those requirements is always changing.
But we’ll see. Maybe there will be some beautiful, stable web dev framework built on WASM that comes out!
Regarding use cases, I think there are plenty, mainly in places where you need to protect yourself against th code you're running, so pretty similar to docker, but lighter and faster boot time. Admittedly, also less feature complete and a different target: less business-y code and more system-y code.
So anything like cloud functions, database functions as described in this article, indeed web browser based games. I think Fastly is providing cloud functions at the edge that are wasm based.
With these uses cases, theoretically, an ecosystem might develop making more use cases transferable from docker to wasm, particularly use cases of isolated pieces of logic that need to be executed unitarity.
> mainly in places where you need to protect yourself against the code you're running
You can do this with LUA or like a million other languages (heck, even vanilla JS). The idea that WASM is the only sandboxed thing in the universe is just weird.
I don't know anyone who has ever said that.