Live data from Hacker News

gRPC-Go Engineering Practices

grpc.io

41–50 of 85 posts

Re: gRPC-Go Engineering Practices

#41
post #30

Earlier quoted context omitted.

What have you find too complex about protobuffs? Unfortunately twirp is go-only.

It's go-only for now. Protobufs includes a code gen step, which is a burden on project tooling and workflow and it's not very fun using the types it generates or writing boilerplate to convert to the types you'd prefer. Also, I'm not sure about twirp, but protobufs doesn't have a good way to model interface or sum types last I checked.

Proto 3 has the "oneof" type. For instance:

message MyThing { oneof sum_type { TypeOne type_one = 1; TypeTwo type_two = 2; } }

The lack of inheritance seems awkward at first, but with oneof it isn't much of a blocker. The APIs for this aren't always great -- Go's in particular feel kind of awkward (IMO). Java's are nice -- it's a separate enum you can switch over.

An example from a Go project of mine:

  switch req.StartAt.(type) {
  	case *pb.GetLogsRequest_Timestamp:
  		t, err := types.TimestampFromProto(req.GetTimestamp())
  		if err != nil {
  			return nil, errors.Errorf("Bad timestamp: %v", req.GetTimestamp())
  		}
  		filter.Timestamp = t
  	case *pb.GetLogsRequest_Offset:
  		filter.StartOffset = req.GetOffset()
  	case *pb.GetLogsRequest_Position_:
  		switch req.GetPosition() {
  		case pb.GetLogsRequest_LATEST:
  			filter.Position = LATEST
  		case pb.GetLogsRequest_EARLIEST:
  			filter.Position = EARLIEST
  		}
  	case nil:
  	default:
  		return nil, errors.Errorf("Unknown GetLogsRequest.StartAt type.")
  	}
  }

Re: gRPC-Go Engineering Practices

#42
post #29

Earlier quoted context omitted.

Versioning your API is one huge benefit and better done using proto/rpc. If you change your Json schema, have fun propagating that change to all clients without fear. Or hope you've built special infra to do that. Also "just more efficient" is a funny way to characterize the performance difference between just data bytes vs data + structure bytes (read: the gap is large). You gain in transmission and you gain during…

I fully agree, but want to point out that JSON can be compressed.

You're absolutely right. Auth0 shows that when compressed, protobufs don't provide a great benefit vs JSON.

Something I've read from others is that gRPC is not the easiest thing to use directly in SPA. If you have services exposed to a web front end and mobile, double exposing a REST-ish API + gRPC might not be worth it. This is a problem with which I'm currently struggling.

https://auth0.com/blog/beating-json-performance-with-protobu...

Re: gRPC-Go Engineering Practices

#43
Has anyone found a good resource on using gRPC directly in a JS client? I've looked at using gRPC. My current challenge is that I want to support a website/webgateway on one side and mobile gateway on the other. If I use Swift or Java on the mobile side, it's easy. If I use Ionic Framework, I'm in the same spot as with the web gateway; probably better off with HTTP + RPC.

Re: gRPC-Go Engineering Practices

#44
post #2

Its a good time to ask, is gRPC any good? I'd love to standardize on stable middleware layer that handles multiple versions of clients and servers well. Rest with json really seems to work great for most things already. What is the advantage of gRPC - just more efficient?

It would be an ideal standard if it supported browsers.

Re: gRPC-Go Engineering Practices

#45
post #40

Slightly off-topic, but related.. I have read that a common practice for managing proto files (or any schema definitions really) is to put them in a separate repo/package to share. It seems pretty straightforward in my head and provides several advantages. However I still ask about any trade-offs when doing this in practice?

It has similar challenges than a monorepo.

First challenge is, that you have to keep some kind of reference on what proto are you using within your project. What Google (and some others) do, is that they a) put all the proto files in a separate repo [0] and then generate them for each language separately (python [1], ...). This way you can use whichever proto file you need within your project, however you have to load more libraries than you need to. To be honest, it only makes slight difference when deploying, so not too bad.

The second challenge is, that you have to generate the result files every time you make some kind of change. If you have a lot of proto files, then it may take some time to generate them and there are very little tools available to help you. Google open-sourced Artman [2] although it's more focused on APIs than managing shared protos.

The massive advantage is that, because proto files are self-explanatory and if you put enough information in them can function as direct documentation of your API's interface, you don't need to fish out the requirements in the project or in the documentation but rather just directly read the proto file itself. But this does depend on the developers, to make it as consistent as possible, which is not always the case [3].

[0] https://github.com/googleapis/googleapis

[1] https://pypi.python.org/pypi/googleapis-common-protos

[2] https://github.com/googleapis/artman

[3] https://news.ycombinator.com/item?id=16166153

Re: gRPC-Go Engineering Practices

#46

Has anyone found a good resource on using gRPC directly in a JS client? I've looked at using gRPC. My current challenge is that I want to support a website/webgateway on one side and mobile gateway on the other. If I use Swift or Java on the mobile side, it's easy. If I use Ionic Framework, I'm in the same spot as with the web gateway; probably better off with HTTP + RPC.

Does this work? https://github.com/grpc-ecosystem/grpc-gateway

Seems to generate a REST proxy server side.

Re: gRPC-Go Engineering Practices

#47

Does anyone have experience with both gRPC and Thrift? I'd be curious to know how they compare.

Thrift used to support more languages (this has changed). gRPC was more performant (take w/ grain of salt, this is word of mouth) for a while -- unclear if it's changed or if the difference was ever that significant except at very high scale. I think they're pretty similar and you can't lose either way. Facebook's support of Thrift and Google's of gRPC make both decent options. One thing I will say about gRPC is that…

When I looked into Thrift's generated code for Objective-C when we started working on gRPC (so 2014), RPCs were all blocking, which made for a non-idiomatic API. I haven't looked if they've added an asynchronous version since.

Re: gRPC-Go Engineering Practices

#48
post #46

Has anyone found a good resource on using gRPC directly in a JS client? I've looked at using gRPC. My current challenge is that I want to support a website/webgateway on one side and mobile gateway on the other. If I use Swift or Java on the mobile side, it's easy. If I use Ionic Framework, I'm in the same spot as with the web gateway; probably better off with HTTP + RPC.

Does this work? https://github.com/grpc-ecosystem/grpc-gateway Seems to generate a REST proxy server side.

I haven't tried it, but that goes against the grain of gRPC. I understand it as an integration point between legacy REST and gRPC. I don't know, and from what I've read, wouldn't use it for greenfield development.

The only issue I have with full HTTPS + JSON is CRIME. I'm not sure how that works.

Post reply on HN