-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC over REST #225
Comments
I must admit, current HTTP API comes with limitations, even in web context: "realtime" updates are not possible without constant polling over HTTP (ipfs-companion, ipfs-desktop) and REST does not improve that. Interactive web applications would benefit from RPC-based API over websockets, so ideally we need something transport-agnostic. Some RPC candidates were previously discussed in ipfs/go-ipfs-cmds#37 and other places, recurring ones:
Is anything else worth adding to the list? What is IPFS Cluster using for RPC? |
FWIW, I don't think it would be at all out of line to think about specing some sort of RPC-ish system that's codec agnostic and under either the umbrella of either IPLD or libp2p. Pretty much all the other options out there seem to be tightly bound to a specific single codec, and that strikes me as... unfortunate. We've already done some protocols that are defacto doing this -- e.g. Graphsync, which is doing something RPC-like (without having an explicit RPC library) over IPLD and incidentally using CBOR. It seems to work fine. |
Also, quick blog post I feel is borderline obligatory to link whenever "RPC" is brought up, either as a thing to use or as a thing to design: https://incubaid.wordpress.com/2012/03/28/the-game-of-distributed-systems-programming-which-level-are-you/ It contains some very useful cautionary tales. |
I'd recommend at least considering a strategy that is compatible with libp2p. People frequently want to build applications that use an RPC pattern (even if they are mere Level 1s 😃) and are confused by how to do it via libp2p. Sometimes they literally just use pubsub to transport messages because there is no obvious answer available. For example, there was some work to make gprc utilize libp2p at libp2p/libp2p#26 and https://github.com/paralin/go-libp2p-grpc |
My experience of RPC has led me to a few observations.
By the very nature of RPC, operations, inputs, outputs and general structure are tightly coupled to the remote implementation. This in turn tightly couples client implementations to the remote implementation since there is no translation layer between them, which means every client feels pain every time you want to refactor something. You also end up leaking the conventions of the remote implementation into clients which may be in a different language and/or have different expectations and norms. You could, could, write a translation layer, but no-one does that. They just think 'Oh cool, this gives me everything I want' and start passing data types around. Then you are trapped, doomed to an endless loop of refactors that must be important to someone but seem utterly pointless to you.
Because RPC takes a granular approach this leads to lots of operations and then lots of code being required to support those operations. A better approach is to have fewer generic resources that the client can orchestrate to perform complex operations. IPFS is in a nice place where most of its operations are idempotent so we should really leverage that.
The page @warpfork links to makes this point about Java RMI. Been there, been burnt, not massively keen on going back. Having RPC be completely transparent is a neat trick but encourages the developer to make lots of RPC calls which will end up with the developer wondering why their application performance is so bad.
If HTTP is the thing that's making your application slow, you are doing pretty well. |
SUPER well said. 👏 👏 👏 Idempotency is a superpower and we should absolutely lean on it, at all times and as much as possible. It makes better things happen with less work and higher reliability. (RPC frameworks are concerning because tend to lead people off that path quite easily unless there's diligent awareness of this. I'll agree it's not "inevitable", but yeah... it's a tendency, and a concerning one. It doesn't mean we shouldn't do an RPC system, or at least document patterns around it, but it's a note to keep forefront in mind.) |
We now have defined HTTP specifications at specs.ipfs.tech - the RPC API concerns Kubo only, as an implementation, and no longer belongs in this repository. Therefore, I'm closing this issue. Feel free to move this to Kubo if you feel like it's useful. |
Re: #224
I'd like to move in the opposite direction: switch to a transport-agnostic RPC API internally so we can support multiple RPC protocols/libraries and multiple transports. I'm concerned that REST, specifically the use of verbs like PUT, DELETE, etc.) will tightly couple us to HTTP.
Why:
ipfs get
andipfs cat
is currently incorrect because we can't accurately calculate the size of the response before we send it. To fix this, we'll likely need to send chunks of data along with progress information. However, that will breakcurl -o file .../api/v0/get/ipfs/QmFoo
.Thoughts? What about JSON RPC (or some similar protocol, ideally using CBOR)?
The text was updated successfully, but these errors were encountered: