Client side streaming in gRPC-Web

Enhancing the GopherJS gRPC-Web bindings with Websockets

In a previous post I introduced my open source project to bring GopherJS bindings to Improbable’s gRPC-Web client. I’m happy to say that the initial goal of supporting all features of the gRPC-Web client has been completed. I was initially going to leave it at that and wait for client side streaming to land in the WHATWG Streams API Standard, and subsequently added to the official grpc-web spec and probably the gRPC-Web client, but then I was sitting at the GolangUK conference and I had a brain wave. [Read More]

Chunking large messages with gRPC

Using gRPC server-side streaming with binary blobs

One of the gotchas of using gRPC is that it was not designed to transport large messages in one chunk. The default max message size is slightly arbitrarily set at 4MB today, and while it is possible to configure, that kind of behaviour might lead to a slippery slope scenario of ever increasing max message sizes. So what do we do when the message size is too large? We chunk the data into smaller pieces and stream it, using the gRPC streaming methods, naturally. [Read More]

Throttling resource intensive requests

OOM errors hate this one weird trick

Sometimes when you’re writing a server, you’ve got a function that consumes a lot of memory while running, or some other resource, and you might be worrying that a sudden burst of requests could crash the server, since gRPC by default will just spawn another goroutine to handle any incoming requests, oblivious to the danger. In these situations, it can be useful to implement some custom request throttling. Here I’ll show an easy way to accomplish this with the use of a Go channel. [Read More]

GopherJS Integration Tests

With friends Qunit, Ginkgo and Agouti

Recently I found myself wondering how I was going to test my new GopherJS gRPC-Web bindings. Writing tests was something I had been waiting with until I had something working, mostly because I had no idea how I was going to meaningfully test GopherJS code that relies on interactions with JS and the reponses of a server. I have in the past made a small contribution to the GopherJS websocket repo, and found myself impressed with the extensive tests written for the repo. [Read More]

gRPC-Web with GopherJS

Introducing the GopherJS gRPC-Web bindings

In a previous blog series I’ve talked about how to work with a gRPC backend from the GopherJS world. It relies on the gRPC-gateway which is a great piece of tech, but unfortunately carries a couple of downsides: Clients don’t know what types are used - the interface is HTTP JSON. This can be somewhat mitigated with the use of swagger generated interfaces, but it’s still not perfect. The interface being JSON means marshalling and unmarshalling can become a significant part of the latency between the client and the server. [Read More]

Go Protobuf Tips

A couple of tips for working with proto files in golang

I’ve had my fair share of dealing with proto files in go (and to some extent JS), so I thought I’d share some stuff I’ve learnt the hard way by working with proto files. Protoc include paths The protoc include paths can be pretty confusing, so I’ll give a few examples of how to use it properly. Just include the current directory protoc requires that the files referenced are in the include path, so if you’re referencing files relative to the current directory, you’ll need to specify -I. [Read More]

GopherJS Client and gRPC Server - Part 4

A guide to implementing a GopherJS frontend to a gRPC backend exposed over HTTP via the gRPC-gateway

Putting it all together As we touched upon earlier, we generate a package from the generated JS (meta, right?), which can be served from the server. We’ll create a new file, main.go, in which we can spin up a server, serve the frontend and the gRPC backend. Much of the logic in this file is inspired by the excellent blog post put together by Brandon Philips over at CoreOS. We’re using his elegant solution to serve both the HTTP API and the gRPC API on the same port. [Read More]

GopherJS Client and gRPC Server - Part 3

A guide to implementing a GopherJS frontend to a gRPC backend exposed over HTTP via the gRPC-gateway

Implement the client GopherJS can be used in a couple of different ways, and there’s a couple of different bindings to many popular JavaScript frameworks. The GopherJS wiki has some great resources. I tried a couple of different ones and ended up using the VueJS bindings because it made it easy to prototype things quickly. I hear VueJS works well for many JS evangelisers out there, but I’ve only used it with small projects. [Read More]

GopherJS Client and gRPC Server - Part 2

A guide to implementing a GopherJS frontend to a gRPC backend exposed over HTTP via the gRPC-gateway

Implement the server I like to start by creating a struct and write a simple definition that’ll immediately fail to compile. package server import ( "github.com/johanbrandhorst/gopherjs-grpc-websocket/protos/server" ) type Server struct{} var _ server.MyServerServer = &Server{} This won’t compile, because the Server struct does not implement the server.MyServerServer interface. But it’ll also tell us what we’ve got left to implement. So lets implement the server methods: func (s Server) Simple(ctx context. [Read More]

GopherJS Client and gRPC Server - Part 1

A guide to implementing a GopherJS frontend to a gRPC backend exposed over HTTP via the gRPC-gateway

Create the protobuf interface We’ll start by creating a folder for the package we want to create. Lets call it server. Next we type up a .proto file to define the interface between the server and the client. We’ll have to include some extra proto annotations in order to have the gRPC-gateway generate the translations methods we need. Lets define a simple service with a single HTTP GET endpoint: [Read More]