- GraphQL is an API query language developed by Meta. It provides a complete description of the data in the API and allows the client to request only what they need.
- A GraphQL server acts as an intermediary between a client and a server. GraphQL can aggregate multiple REST requests into a single request (both “request” and “query” mean “request” in Russian). A GraphQL server organizes resources into a graph (hence the name).
- GraphQL supports queries, mutations (modifying resources), and subscriptions (receiving notifications about modifications).
GRPC
RPC (Remote Procedure Call) is called “remote” because it enables interaction between remote services when they reside on different servers in a microservice architecture. From the user’s perspective, it appears as a local function call.
The diagram shows the gRPC flow:
- The client sends a REST request. The request body contains data in JSON format (usually).
2-4. The order service (gRPC client) receives the request, transforms it, and sends an RPC request to the payment service (gRPC server). gRPC encodes the client data in binary format and sends it to the low-level transport layer. - gRPC sends data packets over the network using HTTP2. Thanks to binary encoding and network optimizations, gRPC can be up to 5 times faster than JSON.
6-8. The payment service receives data packets over the network, decodes them, and calls the server application.
9-11. The result received from the server application is encoded and sent to the transport layer.
12-14. The ordering service receives data packets, decodes them, and sends the result to the client application.