Getting started with grpc-protobuf in java. Complimentary repo for blog post "GettingStartedWithProtobufGrpc"
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
gradle/wrapper
src/main
.gitignore
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle

README.md

workshop-grpc

This repository is setup to provide a basic understanding of the gRPC protocol and introduce the steps required to setup a project. This repository also works as a complimentary code repository for the blog post GettingStartedWithProtobufGrpc

Goals

  • Introduction to gRPC protocol.
  • Project setup for gRPC using gradle.
  • Basic understanding of protocol buffers.
  • Code generation in gRPC projects.
  • Client-Server implementations.

Introduction

gRPC is a application development framework created by Google in 2015. It borrows a lot of concepts from RPC / CORBA framework where a client can call a method on a server through a stub, as if it was available locally to client.

In addition, its based on HTTP/2 protocol which provides performance gains along with additional capabilities like stream processing, connection multiplexing and inbuilt SSL/TLS support . It uses a serialization framework called protocol buffer under the hood to binary encode the data being transferred.

This makes gRPC a very good candidate for creating microservices. It also has a lot of support for cloud, being a part of Cloud Native project and works seamlessly on container orchestration frameworks like kubernetes.

If you are used to building microservices using REST + JSON, transition to gRPC would feel like a next natural progression. Moreover, ability to implement the framework in your preferred programming language makes it an excellent choice for modern application development.

To build REST apis, we use something like:

REST API = HTTP1.1 + REST + JSON

In gRPC we would handle the same scenario using

gRPC API = HTTP2 + RPC + Protobuf

While both approaches are used to serve client-server communication, there are few notable differences.

  • gRPC allows stream processing and also implements server push.
  • gRPC allows single connection to multiple all data transfer between client and server. This is different from HTTP1.1 application where each data transfer needs to open and close a new connection
  • gRPC enables data transfer in binary format using protobuf serialization under the hood. REST+JSON is still mostly text based.
  • gRPC has inbuilt support for security using (SSL/TLS)
  • gRPC provides more flexibility on the types of operations client can perform on server. This is different from REST which strictly encourages to use only CRUD operations on the object.

In this workshop we will work from scratch to develop a working prototype for an Invoice generation System. Follow the docs below in sequence to read the problem statement and step-by-step process to implement a gRPC project.

  1. Problem statement
  2. Project setup
  3. Defining payload and services
  4. Code generation from protobuf to java
  5. Server implementation
  6. Client implementation