News for hackers. Stuff that matters.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by chubot on Monday January 02, 2023 @05:16PM (#34224449)
Read about the important of idempotence in distributed systems

HTTP GET is idempotent, which seems trivial, but it's worth more than people think. With JSON-RPC you can't safely retry any RPC, and that matters at scale! (If the transport is HTTP, I'm pretty sure all JSON-RPC are POSTs. JSON-RPC can be good for local communication like language servers, where you don't really care about retrying or caching)

FWIW Google had/has a very RPC-like model, and when I left many years ago there, I remember they came around to giving explicit guidance to use a REST-like model (which you can do in an RPC system). That is, where you have more nouns than verbs, and you GET nouns.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by dastbe on Monday January 02, 2023 @05:40PM (#34224705)
i think the benefit of client expectations around verbs isn’t the be-all-end-all. i can still write a non-idempotent fairly easily.

writing resource oriented apis does benefit quite a bit, as it often forces you into good api patterns around idempotency. many aws apis and almost all new ones follow this pattern and they are much betterto integrate with because of it.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Monday January 02, 2023 @07:07PM (#34225598)
> HTTP GET is idempotent

Yeah, def getHandler() = { val a = randomString() + readDatabase(); writeDatabase(a); return a;}

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by yandie on Monday January 02, 2023 @07:14PM (#34225658)
Technically you can implement whatever you want under a `GET` - you can even stuff a body to a `GET` even though the RFC doesn't allow it (see ElasticSearch API).

However that doesn't mean it's a good implementation. What you're doing there is gonna break caching for example, unless that's intended. If I'm calling a `GET` and your service is behaving like a `POST`, I'm not gonna be able to rely on standard semantics for a lot of things!!!

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Monday January 02, 2023 @07:45PM (#34225979)
If you can't enforce a contract it's not a contract.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by BoorishBears on Monday January 02, 2023 @07:52PM (#34226051)
Maybe should learn what an RFC is, and check out this one before you keep trying to counter the document that formally minted the verbs in the first place: https://www.rfc-editor.org/rfc/rfc2616#section-9.1.2

See section 9.1.2: Idempotent Methods, where they succinctly address the point:

> Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.

-

It's funny, I wouldn't have thought the RFC needed to say this. I'd have thought it was a waste of words since it'd be obvious to absolutely anyone that you can't... what? magically force developers to not write a bit of code in a system you have literally no control over?

Yet here we are, proving the authors well-prepared all these years later.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Monday January 02, 2023 @08:12PM (#34226214)
> Naturally, it is not possible to ensure that the server does not generate side-effects

Of course it's possible, there are ways to guarantee that and to prove that. That's an area of ongoing research. E.g. https://link.springer.com/chapter/10.1007/978-3-642-36594-2_...

Though I've said just one thing - you can't expect that a GET query would be idempotent. You may only hope.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by ninthcat on Monday January 02, 2023 @08:55PM (#34226555)
It is not possible to prove that calling the server will not produce side effects. The link you provided does not address side effects, but correctness, which is much weaker. A trivial example is that calling the server will consume electricity.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Tuesday January 03, 2023 @04:33AM (#34229590)
"Side effect" is a breakage of referential transparency.

Depending on your model it can be proven.

Electricity consumption won't be a side effect in any reasonable model.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by notwedtm on Tuesday January 03, 2023 @08:57AM (#34231319)
What are you going on about? This feels like someone who's just read their first compsci book and now thinks they can build New Internet.

Surely this is a troll...

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Tuesday January 03, 2023 @10:29AM (#34232620)
I'm saying that unenforceable contracts, like the "idempotence" of GET requests are no better than an annotation on a method in a conventional RPC IDL.

If fact the latter is better, because it may be somehow enforced by cogen if you code-generate into a language which may, for example, enforce purity or totality.

And the whole story about "REST not being an RPC" or "there is purity/idempotence/whatever in REST because RFC says that GETs are pure/idempotent/whatever" makes very little sense.

At the same time I'm saying that it's total bullshit when someone says that it's not possible to enforce lack of side effects (like in referential transparency) during a remote call.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by BoorishBears on Monday January 02, 2023 @09:06PM (#34226633)
SCC is so unrelated to anything even being remotely discussed, that it would be an insult to the term "orthogonal" to describe it as such.

It's such an off-the-wall connection I can hardly refute it: it's like we're talking about toasters and you dived into talking about CRISPR because I said the word "crispy". If anything it'd imply you're not familiar with CRISPR or toasters.

> Though I've said just one thing - you can't expect that a GET query would be idempotent. You may only hope.

I guess you should look up what it means to expect something. In the context of your sentence hope and expect are synonymous*, so maybe you meant you can't guarantee?

And even ignoring that mistake, it's not really useful to say "You can't be sure something doesn't follow guidance, you can only expect it" because that's tautological. Guidance in and of itself doesn't have any way to assert direct influence on an implementation, that's why it's literally called guide·ance.

*before you use that to dive into a grammatical diversion, that is not generally the case, only specifically in your use.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Tuesday January 03, 2023 @04:46AM (#34229665)
> SCC is so unrelated to anything even being remotely

Let's assume we make a remote call with a list of VM instructions for a virtual machine which has no access to any I/O. Now we only need to prove the correctness of the answer. Whatever you do on the remote side, you won't be able to make your computation impure. Yes, you still may write logs or sleep but it won't break referential transparency, there will be no way to return two different accepted results for the same inputs.

You may even have I/O in some very limited form.

You don't have to supply the code.

If you don't agree, show me side effects in EVM.

> In the context of your sentence hope and expect are synonymous

Only in your eyes.

Anyway, I've been saying that REST is too unformal and weak-typed.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by BoorishBears on Tuesday January 03, 2023 @10:40AM (#34232811)
When you're this far out of your depth, it may be best to stop floundering and see if you can float.

You implicitly revised your previous statements, and the revised point is even further off base (I mean, now you're showing you don't know the difference between REST and HTTP verbs?)

At some point just take it as a learning experience that hamfisted non-sequitur about verifiable computing don't have any of the "shock and awe" on HN that they might on and your Facebook wall...

You should stick to things you understand if you insist on making authoritative statements.

-

By the way: language doesn't only work "in my eyes", words have meaning, learn those meanings before you use them.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Tuesday January 03, 2023 @12:38PM (#34234784)
I don't think I've revised anything. I said that it's possible to impose enforceable contracts on remote code execution. I'm not saying all the approaches are practically useful in the domain of RPC, but even there we can do more than just stick to informal promises.

> You should stick to things you understand

Ok. We don't need VC, for practical purposes we may do a lot of contract enforcement at the tooling level, like if we generate code from an IDL, we may restrict access to various APIs, enforce purity and totality.

> you don't know the difference between REST and HTTP verbs?

It doesn't matter if you talk about REST or HTTP, nothing guarantees "idempotence" of GET. Also the discussion was in the context of REST as something opposed to RPC.

> learn those meanings before you use them.

You command too much.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by BoorishBears on Monday January 02, 2023 @07:46PM (#34225984)
I saw a truly truly awful codebase get around the caching bit by appending a random string of bytes to the query string.

If you're willing to ignore the rules you can get away with pretty awful stuff that no one should really need to account for in a general conversation.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by imiric on Monday January 02, 2023 @08:12PM (#34226207)
> I saw a truly truly awful codebase get around the caching bit by appending a random string of bytes to the query string.

This is a common cache busting technique. Why is it a bad thing?

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by BoorishBears on Tuesday January 03, 2023 @12:01AM (#34227887)
Why do I get the impression this is a leading question...

If you have the option between cache busting and just using the correct HTTP verb, please choose the latter.

As to whether there was an option in this particular case, I think the fact I referred to it as a "truly truly awful codebase" should provide a hint.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by talideon on Tuesday January 03, 2023 @12:18AM (#34227991)
The correct solution for cache busting is generally to put a low TTL on the resource in question. Adding random crap in the end is only good if you're dealing with utterly broken caches or your webserver does some tremendously stupid header rewriting. In my experience, when people resort to that, it's down to a lack of understanding of HTTP itself.

YMMV, however.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by kelnos on Tuesday January 03, 2023 @07:09AM (#34230473)
HTTP GET being idempotent is an agreed-upon contract. If you violate it, that's up to you, but that would be a red flag to me as to the quality of your APIs.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by pshirshov on Tuesday January 03, 2023 @08:44AM (#34231184)
These guys may somehow disagree with you: Etag, Last Modified, the whole If family.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by daxfohl on Monday January 02, 2023 @09:18PM (#34226720)
Pretty much this. I was very anti-REST back circa 2015-2017 when I started doing web dev. I was doing solo work and all my services were JSON-RPC (I can't remember whether that was an actual standard then or if I just rigged it). I was (and still am!) into functional programming, and RPC seemed to fit better: it's just a remote function call. Nakedly PUTting a resource just seemed to violate my idea of good architecture.

In 2017 I left to join Azure, which is REST-heavy (in all this, I mean "modern" REST, not "Fielding" REST). I hated it at first, but eventually saw how nice it is to have the conventions. Less to explain in public API docs, easier to generate scaffolding, common themes of how to destructure incoming requests in middleware handlers and middle-tier services, a standard way to serialize references to resources across the platform. I was a convert.

Moving to google in 2021, they're still very RPC, and it feels so cluttered and arbitrary. I'm not there anymore.

Yes, REST is roughly just some conventions around RPC at the core (though you get things like caching for free), but ultimately it's a really nice set of conventions that are easy to follow and limit surprise, and are standard across the industry. As one user commented, you do sometimes have to work around REST to get it to fit, typically futzing in headers or request metadata, but to me the pros outweigh the cons.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by gspetr on Monday January 02, 2023 @11:32PM (#34227701)
Can you point to some sources of information about the modern REST you are talking about?
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by talideon on Tuesday January 03, 2023 @12:11AM (#34227952)
"Modern" REST generally disposes of things like hypertext and representations as being too complex, instead leaning on things Swagger/OpenAPI to declare an IDL equivalent, so you're getting effectively an RPC system with some of the guarantees you'd get from REST.

Azure's APIs are more RESTful than most: they actually bother using resource URLs as identifiers.

I've never understood what people find so hard about HATEOAS. It's like people have never interacted with a HTML form or followed links to stuff, or have difficulty figuring out how webpages can consist of multiple linked resources.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by naasking on Tuesday January 03, 2023 @01:27AM (#34228456)
> I've never understood what people find so hard about HATEOAS. It's like people have never interacted with a HTML form or followed links to stuff, or have difficulty figuring out how webpages can consist of multiple linked resources.

Or that an object graph of a system is a web of linked resources, and that every program has an entry point object/interface from which you can navigate to any part of that object graph, just like in REST.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by spdionis on Tuesday January 03, 2023 @04:07AM (#34229449)
It's not hard, it's just wasteful and not very useful.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by daxfohl on Tuesday January 03, 2023 @02:21PM (#34236582)
Yes this is what I meant.

The way Azure does it is kind of nice (to me at least, as an ex member of ARM) because ARM can generically check access just by the URIs. The downside though is that the URI also includes the subscription and tenant id, so ARM has to deal with the URI being stale after stuff gets moved around. And then the advent of management groups and cross-tenant access made it so it's not quite so straightforward anymore. But it was still quite useful.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by still_grokking on Sunday January 08, 2023 @04:12PM (#34303179)
> "Modern" REST generally disposes of things like hypertext and representations as being too complex, instead leaning on things Swagger/OpenAPI to declare an IDL equivalent, so you're getting effectively an RPC system

Now the question is: Why do people insist to calling some (no standardized) ad hoc RPC protocol "REST(full)"?

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by wruza on Tuesday January 03, 2023 @04:45AM (#34229657)
What prevents you from making specific calls idempotent? You can even specify it via a POST/PUT method in any sort of RPC call to make HTTP proxies (or automatic resubmitters) aware of this detail.

Idempotency is not exclusive to REST. When you invoke File-Save twice in Notepad it doesn’t create two different files either.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by nullandvoid on Tuesday January 03, 2023 @08:08AM (#34230870)
Isn't the cache situation somewhat solved via defining your RPC as either a "query" or "mutation" (for example in systems such as https://trpc.io/ > https://trpc.io/docs/caching)?
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by chubot on Tuesday January 03, 2023 @11:36AM (#34233709)
How would proxies and load balancers know about this?

You would have to encode your app-specific logic in every proxy or load balancer. In HTTP, they already exist.

The top two comments in this thread explain this more:

https://news.ycombinator.com/item?id=34228122

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by still_grokking on Sunday January 08, 2023 @04:16PM (#34303218)
> How would proxies and load balancers know about this?

By using a proper protocol.

Not everything is nail just because the modern thin-client is only able to wield the HTTP hammer.