gRPC: High-Performance Microservices with Protocol Buffers
Presentation guide on gRPC, Protocol Buffers, HTTP/2 multiplexing, and the Backend for Frontend (BFF) architectural pattern using Node.js and Python.
Team Members
- Fiber Piedrahita
- Daniel Fajardo
- Paula Ferreira
Slides and Resources
Project Links and Presentation
- Presentation (PDF): Download gRPC-Pokedex.pdf
- Official Protocol Buffers Documentation: Protobuf Dev
1. gRPC and Protocol Buffers Foundations
gRPC (gRPC Remote Procedure Calls) is an open-source, high-performance RPC framework initially designed by Google. Unlike conventional REST architectures passing textual JSON payloads over HTTP/1.1, gRPC is anchored on two core technical pillars:
- Protocol Buffers (Protobuf): A language-neutral, platform-neutral, extensible mechanism for serializing structured binary data.
- HTTP/2 Transport: Supports full request multiplexing over a single persistent TCP connection, header compression (HPACK), and bi-directional streaming.
Clic para ampliar
2. Comparison: gRPC vs. REST
| Criteria | gRPC | Traditional REST |
|---|---|---|
| Transport Protocol | HTTP/2 (Multiplexed) | Typically HTTP/1.1 or HTTP/2 |
| Payload Format | Binary (Protocol Buffers) | Textual (JSON or XML) |
| Contract Definition | Mandatory and strict (.proto) | Optional (OpenAPI / Swagger) |
| Performance | High throughput, minimal network serialization overhead | Moderate overhead from JSON text serialization |
| Streaming Modes | Unary, Server Streaming, Client Streaming, Bidirectional | Predominantly unary request/response |
| Primary Use Case | Inter-service microservice backplanes | Public-facing web APIs consumed by browsers |
3. Practical Demo: Pokédex with BFF Architecture
1
Define Contract in Protocol Buffers
proto/pokemon.proto
syntax = "proto3";
package pokemon;
service PokemonService {
rpc GetPokemon (PokemonRequest) returns (PokemonResponse);
}
message PokemonRequest {
string name_or_id = 1;
}
message PokemonResponse {
int32 id = 1;
string name = 2;
int32 height = 3;
int32 weight = 4;
repeated string types = 5;
string sprite_url = 6;
string description = 7;
}
2
Implement gRPC Server in Node.js
The Node.js server compiles the .proto schema, queries the upstream PokeAPI, and responds to gRPC clients via structured binary streams:
cd backend_node
npm install
node server.js
3
Implement Python gRPC Client (Flask BFF)
The Python Backend for Frontend (BFF) consumes the gRPC service and serves HTML/JSON to the client browser:
Practical Demo: Pokédex with BFF
cd frontend_python
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python app.py