19. Microservices

A. gRPC

Microservices are built in different languages and encompass a function of your business. These services need to talk to each other and need to agree on:

  • API to exchange data
  • Data format
  • Error patterns
  • Load balancing
  • etc…

When developing an API, we need to think of multiple things such as data model, endpoints, invoking and handling errors. In addition, we also need to evaluate efficiency, latency and scalability.

I. What is gRPC?

Free and open-source framework developed by Google

gRPC lets you to define REQUEST and RESPONSE for RPC (remote procedure calls) and handles all the rest.

  • At the core of gRPC, it lets you define the messages and services using Protocol Buffers
  • Brings a great deal of flexibility and convenience to the table

Example:

syntax = "proto3";

message Greeting {
    string first_name = 1;
}

message GreetRequest {
    Greeting greeting = 1;
}

message GreetResponse {
    string result = 1;
}

service GreetService {
    rpc Greet(GreetRequest) returns (GreetResponse) {}
}

Why do we use Protocol Buffers?

  • Language agnostic
  • Code is generated for any language
  • Data is binary and efficiently serialized
  • Allows for easy API evolution using rules
Previous
Next