Live data from Hacker News

Cap'n Web: a new RPC system for browsers and web servers

blog.cloudflare.com

251–260 of 305 posts

Re: Cap'n Web: a new RPC system for browsers and web servers

#251

Earlier quoted context omitted.

No, the requests are queued and sent as a batch.

Ah, okay, that's much better then... In principle, that then allows the server to aggregate or optimise the operations rather than performing them as written. While that might not be relevant for version 1, it's useful to have for later.

What does server-side aggregation for optimization have to do with round trips, though?

Re: Cap'n Web: a new RPC system for browsers and web servers

#252

>> let namePromise = batch.getMyName(); let result = await batch.hello(namePromise); This is quite interesting. However the abysmal pattern I have seen a number of times is: list = getList(...) for item in list getItemDetails(item) Sometimes this is quite hard to undo.

Keep reading, the blog post addresses this.

Re: Cap'n Web: a new RPC system for browsers and web servers

#253
post #213
post #66

Earlier quoted context omitted.

The input to the map function (when it is called in "record" mode on the client) is an RpcPromise for the eventual value. That means you can't actually inspect the value, you can only queue pipelined calls on it. Since you can't inspect the value, you can't do any computation or branching on it. So any computation and branching you do perform must necessarily have the same result every time the function runs, and so…

Also, your function needs to be very careful on closures. Date.toLocaleString and many other js functions will be different on client and server, which will also cause silent corruption.

If you invoke `Date.toLocaleString()` in a map callback, it will consistently always run on the client.

Re: Cap'n Web: a new RPC system for browsers and web servers

#254

Big fan of Cap'n'Proto and this looks really interesting, if RPC is the thing that works for your use-case. However, stumbled over this: The fact is, RPC fits the programming model we're used to. Every programmer is trained to think in terms of APIs composed of function calls, not in terms of byte stream protocols nor even REST. Using RPC frees you from the need to constantly translate between mental models, allowing…

Eh, I think composed function calls have legitimately won _because_ they compose well and are easy to understand, not just because we haven't tried other things.

Re: Cap'n Web: a new RPC system for browsers and web servers

#255
post #212

Earlier quoted context omitted.

I disagree that async/await is purely about avoiding overhead of kernel threads. Kernel threads are actually not that expensive these days. You can have a server with 10,000 threads, no problem. The problem is synchronization becomes extremely hard to reason about. With event loop concurrency, each continuation (callback) becomes effectively a transaction, in which you don't need to worry about anything else modifyin…

I totally agree with your framing of the value of async/await, but could you elaborate more on why you think that this behavior (which I would call "cooperative concurrency") is important for (ocap?) RPC systems? It seems to me that preemptive concurrency also suffices to make RPC viable. Unless you just feel that preemptive concurrency is too hard, and therefore not workable for RPC systems?

Almost all ocap systems seem to use event loops -- and many of the biggest ocap nerds I know are also the biggest event loop nerds I know. I'm not actually sure if this is a coincidence or if there's something inherent that makes it necessary to pair them.

But one thing I can't figure out: What would be the syntax for promise pipelining, if you aren't using promises to start with?

Re: Cap'n Web: a new RPC system for browsers and web servers

#256
I've built similar things in the past. (And apologies for merely skimming the article.)

In general, I worry that framework frameworks like this could be horribly complex; breaking bugs (in the framework) might not show up until late in your development cycle. This could mean that you end up having to rewrite your product sooner than you would like, or otherwise "the framework gets in the way" and cripples product development.

Some things that worry me:

1: The way that callbacks are passed through RPC. This requires a lot of complexity in the framework to implement.

2: Callbacks passed through RPC implies server-side state. I didn't read in detail how this is implemented; but server-side state always introduces a lot of complexity in code and hosting.

---

Personally, if that much server-side state is involved, I think it makes more sense to operate more like a dumb terminal and do more HTML rendering on the server. I'm a big fan of how server-side Blazor does this, but that does require drinking C# kool-aide. On the other hand, server-side Blazor is very mature, has major backing, and is built into two IDEs.

Re: Cap'n Web: a new RPC system for browsers and web servers

#257
Hey kentonv, this looks really neat. How would you go about writing API documentation for something like this? I really like writing up OpenAPI YAML documents for consumers of APIs I write so that any time someone asks a question, "How do I get XYZ?" I can just point them to e.g. the SwaggerUI. But I'm struggling to understand how that would work here.

Re: Cap'n Web: a new RPC system for browsers and web servers

#258

Big fan of Cap'n'Proto and this looks really interesting, if RPC is the thing that works for your use-case. However, stumbled over this: The fact is, RPC fits the programming model we're used to. Every programmer is trained to think in terms of APIs composed of function calls, not in terms of byte stream protocols nor even REST. Using RPC frees you from the need to constantly translate between mental models, allowing…

Ah, the good old squeak/smalltalk days. A few years back I worked on signals (or rather a static analyser for the editor to support signals) in squeak/smalltalk. The kind of signals those indie frameworks like angular and svelte now adopt trying to solve the problem of changepropagation you outline in your paper.

What i'm getting at is: For the places where other tools are better (like the UI example), we already have other tools (signals, observables, effects, runes,...). And for the places like client/server-communication: This is kind of where "call/return" usually shines.

Re: Cap'n Web: a new RPC system for browsers and web servers

#259

Earlier quoted context omitted.

> I wonder why they don't just do `.toString()` on the mapping function and then parse the resulting Javascript into an AST and figure out property accesses from that. That sounds incredibly complicated, and not something we could do in a <10kB library!

To the contrary, a simple expression language is one of those things that can easily be done in that size.

But the suggestion wasn't to design a simple expression language.

The suggestion was to parse _JavaScript_. (That's what `.toString()` on a function does... gives you back the JavaScript.)

Re: Cap'n Web: a new RPC system for browsers and web servers

#260

Earlier quoted context omitted.

> First, like others mentioned, you'll have N+1 problems for nested lists. That is, if we call comments() on each post and author() on each comment, we absolutely don't want to have one individual call per nested object. In GraphQL, with the data loader pattern, this is just 3 calls. Why is that a problem? As far as I can tell, those calls are all done on the server, where they're cheap normal function calls, and the…

Because they each result in round-trips and individual queries to the database rather than a more efficient single round-trip with a join. Note: I don't know the details of GraphQL, but I'm assuming it does the smarter thing. In this paradigm, the places where you are calling map() could probably be replaced with explicit getComments() or getCommentsWithAuthors() or two methods that do just one query each.

Well, if the server is a Cloudflare Durable Object running sqlite, then the round-trip to the database is free.

https://www.sqlite.org/np1queryprob.html

But you are right that this won't work great with traditional databases without significantly more magic on the server side, and in that sense the comparison with GraphQL is... aggressive :)

It is still much better than making all the calls client-side, of course. And there are many use cases where you're not querying a database.

And maybe there can be some fusion between GraphQL server infrastructure and this RPC-oriented syntax that gives people the best of both worlds?

Post reply on HN