5 ms·
My team has been using gRPC + Improbable's grpc-web [0] + Typescript for a green field project and it has been amazing. - Typing all the way to the frontend.
by lima 8y ago
My team has been using gRPC + Improbable's grpc-web [0] + Typescript for a green field project and it has been amazing.
- Typing all the way to the frontend.
- gRPC/protobuf forces you to describe your interfaces and are self-documenting.
- gRPC semantics like error codes and deadlines (if you propagate them through your stack, they're particularly useful - for instance, we cancel database transactions across service boundaries if a request times out).
- Performance is great (but we're far from seeing bottlenecks with JSON, it's not the reason we choose gRPC).
- We use grpc-gateway which auto-generates a REST proxy for our customers. We sometimes use it for interactive debugging. [1]
- Rather than importing database models for our management tools and one-off scripts, using the API is so frictionless that we even use it inside our backend code and for CLI utilities.
The Google API design guide is helpful: https://cloud.google.com/apis/design https://cloud.google.com/apis/design
One piece of advice: Treat your gRPC calls like you would treat a GraphQL resolver - if you squint your eyes, they're very similar concepts.
Rather than specifying a GraphQL query, you specify a Field Mask.
https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/field-mask https://developers.google.com/protocol-buffers/docs/referenc...
Happy to answer questions on our experience.
[0]: https://github.com/improbable-eng/grpc-web https://github.com/improbable-eng/grpc-web
[1]: https://github.com/grpc-ecosystem/grpc-gateway https://github.com/grpc-ecosystem/grpc-gateway
- eberkund 8y agoIs it still necessary to use a REST proxy when using protobuf from the browser?
- lima 8y agoNo - it's just there for customers who want a REST API. We don't use it outside of tests and development.
- jonahss 8y agoWere you able to find a good javascript or typescript gRPC client? The official google one seemed to have spotty documentation for the js module itself. It did not look like it supported promises or Nodejs streams either.
- lima 8y agoWe use the Improbable grpc-web client (linked in the post), plus a thin promises wrapper. We haven't used gRPC from NodeJS (you wouldn't need the grpc-web detour since NodeJS can just speak the "real" gRPC protocol).
- sonnyblarney 8y agolima - great points. Questions: 1) If you have TS on the front and back end - you already have de-facto typing. Why did you opt for gRPC over just some kind of basic serialization, even JSON? I 2) If you have TS classes, then you need to maintain a set of Protobuff service definitions as well - do you find this was a lot of duplicated overhead? 3) gRPC seems to me to be a little 'internal', not quite a web tech meant to be shared between parties. Did you have trouble with authentication, especially with 3rd parties? Or other 'cross-cutting' concerns? I'm literally looking at doing what you're doing, any feedback would be greatly appreciated.
- lima 8y ago1) I forgot to mention - the backend is written in Go. Even if both were TS, all of the interoperability and other advantages will apply. 2) The TS classes are auto-generated and the protobuf definitions are the only authoritative definition. 3) We're using JWT for authentication (in particular, short-lived tokens issues by Keycloak, using their JS library). gRPC has request metadata and it was straight-forward to use it with the Keycloak library. We generate client libraries for customers to use and give them the option of using the REST API if they don't want to deal with gRPC. We consider the gRPC API to be a competitive advantage - our customers are enterprises and like well-defined and typed interfaces.
- lachenmayer 8y agoHey, sorry if this is off-topic, but how have you been finding Keycloak? This is the first time I've seen it mentioned on here, and it looks like a great auth solution at first glance.
- segmondy 8y agoI use it and it's great.
- lima 8y agoKeycloak has been great. - Very complete OpenID Connect implementation. - Back-channel logout. - Short-lived tokens and lots of tooling to handle refreshing them. This solves many of the issues associated with JWT expiration. - Documentation is very complete. - Their data model allows for very fine-grained access control - you can issue sub-tokens with limited scopes, limit scopes per client and so on. - Easy to deploy in OpenShift/k8s. Only pain points are the build process (Java has got nothing on NodeJS as far as number of dependencies go!), data migrations and the fact that it's written in Java (start up time in CI).
- k__ 8y agoDoes converting gRPC into a JS object has better performance than converting JSON into an object?
- deleted 8y ago[deleted]
- gcbw2 8y ago> - Typing all the way to the frontend. ...where it is transpiled to ES5... :(