Mengapa gRPC?
gRPC menggunakan Protocol Buffers (binary format) dan HTTP/2, menghasilkan serialisasi 5-10x lebih cepat dari JSON/REST. Code generation otomatis memastikan type-safe communication antar service.
Mendefinisikan Proto File
Buat user.proto yang mendefinisikan service interface dan message types. Proto file adalah "kontrak" antar service yang dapat di-generate untuk berbagai bahasa.
Setup gRPC Server (User Service)
Install @grpc/grpc-js @grpc/proto-loader. Load proto file, implementasikan service handlers, dan bind ke port. gRPC server siap menerima request.
Setup gRPC Client (Order Service)
Load proto file yang sama, buat stub (client), dan panggil remote procedure seperti memanggil function lokal. Error handling via callback atau Promise wrapper.
Streaming
gRPC mendukung server streaming (server kirim multiple response), client streaming, dan bidirectional streaming – use case ideal untuk real-time data feeds.
Deployment Consideration
Load balancer harus mendukung HTTP/2 (AWS ALB, Nginx). Untuk Kubernetes, Istio service mesh menangani load balancing dan mTLS untuk gRPC secara transparan.