VISEN GROUP
Technology & Engineering

Choosing the Right Communication Protocol in Distributed Systems

November 4, 20263 min readUncategorized

Deciding how microservices communicate with one another is a foundational architectural decision. Defaulting to synchronous HTTP REST calls for every inter-service interaction creates tightly coupled systems susceptible to Cascading Failures: if Service C slows down, Service B’s connection pool saturates, causing Service A to time out and crash.

This runbook analyzes when to use Synchronous (gRPC/REST) vs Asynchronous Event-Driven (Kafka/RabbitMQ) communication paradigms.

1. Protocol Comparison Matrix

SYNCHRONOUS COMMUNICATION (gRPC / HTTP REST)
[Client Service] ─── Synchronous Request (Thread Blocked) ───► [Target Service]
                 ◄─── Synchronous Response (Thread Released) ──

ASYNCHRONOUS EVENT-DRIVEN COMMUNICATION (Message Queue)
[Producer Service] ── Publish Event ──► [Message Broker] ── Decoupled Consumer ──► [Service B]
                                                          ── Decoupled Consumer ──► [Service C]
CriteriaHTTP/1.1 RESTgRPC (HTTP/2)Asynchronous Message Queue
Transport ProtocolHTTP/1.1 (Text JSON)HTTP/2 (Binary Protobuf)TCP AMQP / Custom Binary
Execution ModelSynchronous BlockingSynchronous / StreamingAsynchronous Non-Blocking
Network OverheadHigh (Verbose headers/JSON)Ultra-Low (Binary compact payload)Low
Coupling LevelHigh (Requires IP/DNS resolution)High (Requires IP/DNS resolution)Zero Coupling (Brokered via topics)
Failure IsolationPoor (Requires Circuit Breakers)Poor (Requires Circuit Breakers)Excellent (Queue buffers messages)

2. High-Performance Internal Communication with gRPC

Use gRPC for synchronous, low-latency, internal microservice queries (e.g., checking account balances or validating user permissions in real time).

Step 1: Define Protocol Buffer Schema (billing.proto)

Protocol Buffers

syntax = "proto3";

package billing;

option go_package = "github.com/toolswave/billing/proto";

service BillingService {
  rpc GetAccountBalance (BalanceRequest) returns (BalanceResponse);
}

message BalanceRequest {
  string user_id = 1;
}

message BalanceResponse {
  string user_id = 1;
  double balance = 2;
  string currency = 3;
  bool is_active = 4;
}

Step 2: Implement Node.js gRPC Client Connection with Keep-Alive

TypeScript

import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
import path from "path";

const PROTO_PATH = path.resolve(__dirname, "./proto/billing.proto");
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
});

const billingProto = (grpc.loadPackageDefinition(packageDefinition) as any).billing;

// Reuse single client connection channel across application lifecycle
export const billingClient = new billingProto.BillingService(
  process.env.BILLING_SERVICE_URL || "localhost:50051",
  grpc.credentials.createInsecure(),
  {
    "grpc.keepalive_time_ms": 10000,
    "grpc.keepalive_timeout_ms": 5000,
    "grpc.keepalive_permit_without_calls": 1,
  }
);

export function fetchUserBalance(userId: string): Promise<any> {
  return new Promise((resolve, reject) => {
    billingClient.GetAccountBalance({ user_id: userId }, (err: any, response: any) => {
      if (err) return reject(err);
      resolve(response);
    });
  });
}

3. Decoupling Workflows with Asynchronous Event Streams

Use asynchronous message queues (RabbitMQ / Kafka) when processing business events where the calling service does not need an instant inline result (e.g., sending email notifications, updating analytics, or generating PDF invoices):

TypeScript

// Producer emits domain event without caring who consumes it
await eventBroker.publish("user.registered", {
  userId: "usr_9982",
  email: "[email protected]",
  registeredAt: new Date().toISOString()
});
// Producer proceeds instantly in < 2ms without waiting for downstream services

Leave a Reply

Your email address will not be published. Required fields are marked *