Communication Standards: REST, GraphQL and GRPC

What this lesson covers

This lesson looks inside a large server such as Google's, where a gateway routes requests to many microservices, each with its own database and cache, and asks how those services talk to each other. The first need is a shared language. A profile service queried by many other services must define what a profile looks like (an ID, a name, an age), and that definition is the language other services use to query it, for example asking for the IDs of all users older than 10. Because services may be written in Go, Python or Java, the video describes Thrift, developed by Facebook, which defines the object once in an intermediate, pseudocode like language that each service converts into its own types. The second question is how to query a service. REST is stateless: a request for the user with ID 33 carries everything needed, and the server keeps no context between requests, which simplifies the server and matches how HTTP itself works. Requests are also cacheable, though the video treats that as a minor point. GraphQL differs by letting the caller name only the fields it wants, such as first and last name rather than a whole profile, which saves bandwidth and isolates concerns. Finally, gRPC, written over HTTP 2.0, is the common transport for calls between services, since each service is a client when it sends a request and a server when it responds.

  • Thrift defines an object once in an intermediate language so services in Go, Python or Java can share it
  • A REST request is stateless: the server keeps no context, so a request like the previous ID plus 22 is not stateless
  • GraphQL lets the caller ask for only the fields it needs, which saves bandwidth
  • gRPC runs over HTTP 2.0 and is the usual protocol for calls between services
  • Every service is a client when it sends a request and a server when it responds