News for hackers. Stuff that matters.
Re:Why We’re Switching to gRPC by stephenr on Monday May 27, 2019 @01:40PM (#20023880)
Apart from “well google (created|uses) it” I don’t really get the benefit of gRPC compared to any other rpc, eg jsonrpc or even xmlrpc, both of which are fairly static, open specifications for a way to communicate, rather than actual releases of a library that apparently has a new release every 10 days or so.
Re:Why We’re Switching to gRPC by wvenable on Monday May 27, 2019 @01:45PM (#20023924)
Binary. Streaming. Strongly typed (with caveats). There's a whole article about the advantages/differences linked from the top of this page.
Re:Why We’re Switching to gRPC by jwalton on Monday May 27, 2019 @02:05PM (#20024077)
> My API just returned a single JSON array, so the server couldn’t send anything until it had collected all results.

Why can't you stream a JSON array?

Edit: Here's a (hastily created and untested) node.js example, even:

    class JSONArrayStream extends Transform {
        constructor() {
            super({readableObjectMode: false, writableObjectMode: true});
            this.dataWritten = false;        
        }

        _transform(data, encoding, callback) {
            if (!this.dataWritten) {
                this.dataWritten = true;
                this.push('[\n');
                this.push(JSON.stringify(data) + '\n');
            } else {
                this.push(',' + JSON.stringify(data) + '\n');
            }
            callback();
        }

        _flush(callback) {
            this.push('\n]');
        }
    }
Re:Why We’re Switching to gRPC by spenczar5 on Monday May 27, 2019 @03:02PM (#20024476)
There can be a bit more to it:

- how can a client send an error message if it runs into problems mid-stream? You can invent a system, but you’re walking into an ad-hoc protocol pretty fast; why not use something others wrote?

- what if the remote end wants to interrupt the stream sender to say “stop sending me this” for any reason? For example, an erroneous item in the stream, or a server closing down during a restart.

- grpc supports fully bidirectional streams, interleaving request and response in a chatty session; how do you do this?

Not that the original article mentioned these. I bristle though when I hear the engineer’s impulse to “why don’t you just”-away at something.

Re:Why We’re Switching to gRPC by stephenr on Monday May 27, 2019 @02:09PM (#20024100)
you’d probably need to do some tricks to get it to parse in a browser.

Editing, because I can’t reply: I was specifically going to mention SSE/EventSource but expected an immediate “not everything is a browser” response.

Editing the 2nd: yep, that’s kinda what I meant by “tricks” - essentially splitting out chunks to pass to the json parser.

Re:Why We’re Switching to gRPC by jwalton on Monday May 27, 2019 @02:16PM (#20024149)
See my edited example above; you can stream data to this, it'll stream nicely to the browser. This uses "\n"s at the end of every line, which means you can write a very simple streaming parser client side, because you can just split the input at "\n," to get nice JSON bits, but there's certainly JSON streaming libraries on NPM that will parse this for you more "properly". And, it parses with a normal JSON parser too.
Re:Why We’re Switching to gRPC by pbedat on Monday May 27, 2019 @02:22PM (#20024197)
Modern browsers understand text/event-stream so no need for dirty tricks ;)
Re:Why We’re Switching to gRPC by pbedat on Monday May 27, 2019 @02:20PM (#20024177)
Also: Server sent events
Re:Why We’re Switching to gRPC by stephenr on Monday May 27, 2019 @02:03PM (#20024065)
https://news.ycombinator.com/item?id=20023784 Specifically claims that validation isn’t performed as the article mentions

“binary” is not necessarily a benefit, particularly for developer tooling/debugging

Streaming is one area it may have a benefit but honestly the other issues outweigh that possible benefit (and it’s not like there aren’t other ways to stream data to a browser without resorting to polling)

Re:Why We’re Switching to gRPC by ska on Monday May 27, 2019 @02:11PM (#20024120)
It's not just streaming. Any heavy natively binary objects (think scientific computing) are a pain to marshal without a good binary interface, and it can easily become a real performance issue.
Re:Why We’re Switching to gRPC by cblum on Monday May 27, 2019 @02:52PM (#20024392)
Of course you're being downvoted. But I'm totally with you on this one.

As someone currently responsible for migrating services to gRPC at my company, I always say that the main reason people are switching is "because Google."

While there are merits to gRPC and protobuf, I don't think there are enough advantages to throw away REST and JSON and all the tooling around it. The moment you start switching, you start feeling the pain.

"Because Google" is also the main reason everyone wants to run their crap on Kubernetes. It's pure hype.

Always makes me think of "You Are Not Google": https://blog.bradfieldcs.com/you-are-not-google-84912cf44afb