How can we use gRPC with Flatbuffers?

The gRPC protocol is payload-agnostic, but the code generation is not. Since there isn't code generation already for FlatBuffers you will need to do some things manually.

The details vary by language, but the basic pieces are similar. As an example, in Go you would need to implement Codec and prepare the descriptors necessary for Invoke, NewClientStream, and RegisterService. In Java you would need to implement Marshaller and prepare the descriptors necessary for newCall and addService. If you have trouble, you may consider looking at the generated code for gRPC when used with Protobuf.


Since 2017-08-17 gRPC has out-of-the-box support for flatbuffers as mentioned in their blog https://grpc.io/blog/grpc-flatbuffers/#use-flatbuffers-as-an-idl

The recent release of Flatbuffers version 1.7 introduced truly zero-copy support for gRPC out of the box.

Example command from the linked article

flatc --cpp --grpc example.fbs

Since this question was first asked, progress has been made in a) making GRPC codegen independent of protobuf (see https://github.com/grpc/grpc/pull/6130) and then to integrate that codegenerator in the flatbuffers compiler flatc: https://github.com/google/flatbuffers/commit/48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70

This is a a very basic first implementation, feedback welcome.