A comprehensive demonstration project showcasing all four gRPC communication patterns (Unary, Server Streaming, Client Streaming, Bidirectional Streaming) using a Python server and TypeScript (Node.js) clients. The entire setup is containerized with Docker and orchestrated with Docker Compose, featuring secure communication via TLS.
This project serves as an excellent learning resource for understanding practical gRPC implementation, cross-language service development, and secure microservice communication.
- All 4 gRPC Communication Patterns:
- Unary: Device Registration, Status Checks, Simple Commands.
- Server Streaming: Real-time Telemetry Subscription.
- Client Streaming: Bulk Telemetry Upload from devices.
- Bidirectional Streaming: Interactive Device Sessions (real-time commands and status updates).
- Secure Communication: Implements TLS for encrypted client-server communication using self-signed certificates.
- Cross-Language:
- Python gRPC Server
- TypeScript (Node.js) gRPC Clients
- Containerized: Fully Dockerized services for consistent environments and easy setup.
- Orchestrated: Uses Docker Compose to manage and run the multi-container application.
- Modern Tooling: Utilizes Protocol Buffers for service definition and type generation.
- gRPC: Core communication framework.
- Protocol Buffers: Interface Definition Language.
- Python: For the gRPC server.
grpcio,grpcio-tools
- Node.js & TypeScript: For the gRPC clients.
@grpc/grpc-js,@grpc/proto-loader,google-protobuftypescript,ts-node,grpc-tools,grpc_tools_node_protoc_ts
- Docker & Docker Compose: For containerization and orchestration.
- OpenSSL: For generating self-signed TLS certificates.
grpc-iot-project/ βββ certs/ # SSL/TLS certificates β βββ server.crt β βββ server.csr β βββ server.key β βββ openssl.cnf # Config for cert generation βββ client/ # Node.js/TypeScript gRPC clients β βββ src/ β β βββ proto_gen/ # Auto-generated client stubs & types β β βββ device_simulator.ts β β βββ management_console.ts β βββ Dockerfile β βββ package.json β βββ package-lock.json β βββ tsconfig.json βββ proto/ # Protocol Buffer definitions β βββ iot_service.proto βββ server/ # Python gRPC server β βββ Dockerfile β βββ requirements.txt β βββ server.py βββ .gitignore βββ docker-compose.yml βββ LICENSE # Project's license file βββ README.md - Git
- Docker Desktop (includes Docker Engine and Docker Compose)
- OpenSSL (usually pre-installed on Linux/macOS; available for Windows)
git clone https://github.com/kunalPisolkar24/grpc-iot-project.git cd grpc-iot-projectSecure communication requires TLS certificates. These steps generate self-signed certificates for development.
mkdir -p certs cd certs cat <<EOL > openssl.cnf [ req ] distinguished_name = req_distinguished_name req_extensions = v3_req prompt = no [ req_distinguished_name ] C = US ST = YourState L = YourCity O = YourOrganization OU = Development CN = py-server [ v3_req ] subjectAltName = @alt_names [ alt_names ] DNS.1 = py-server EOL openssl genrsa -out server.key 2048 openssl req -new -key server.key -out server.csr -config openssl.cnf openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt -extensions v3_req -extfile openssl.cnf cd ..Note: The CN (Common Name) and DNS.1 in openssl.cnf are set to py-server.
From the project root directory (grpc-iot-project/):
docker-compose build docker-compose up -dTo view the logs:
docker-compose logs -fOr for specific services:
docker-compose logs -f py-server docker-compose logs -f node-device-simulator-ts docker-compose logs -f node-management-console-ts- Unary & Client Streaming & Bidirectional Streaming: The
node-device-simulator-tsclient automatically demonstrates these. - Server Streaming: The
node-management-console-tsclient (as configured indocker-compose.yml) demonstrates this.
Observe the interleaved logs to see the patterns in action.
docker-compose down- Unary RPC:
RegisterDevice,GetDeviceStatus,SendCommandToDevice. - Server Streaming RPC:
SubscribeToDeviceTelemetry. - Client Streaming RPC:
UploadBulkTelemetry. - Bidirectional Streaming RPC:
EstablishInteractiveSession.
- Communication is secured using TLS (Transport Layer Security).
- Uses self-signed certificates with
py-serveras the CN/SAN for hostname verification.
Contributions are welcome! Please see the CONTRIBUTING.md file for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.