Bird
Raised Fist0
HLDsystem_design~7 mins

gRPC for internal services in HLD - System Design Guide

Choose your learning style10 modes available
Problem Statement
When multiple internal services communicate using traditional REST APIs over HTTP/1.1, the overhead of verbose JSON payloads and slower serialization causes increased latency and higher CPU usage. This leads to slower response times and reduced throughput in high-scale microservices environments.
Solution
gRPC uses a compact binary protocol with HTTP/2 transport to enable fast, efficient communication between internal services. It serializes data using Protocol Buffers, reducing message size and parsing time. This mechanism allows services to call each other with low latency and supports features like streaming and built-in code generation for multiple languages.
Architecture
Internal
Service A
→Stub
↓
Internal
Service B

This diagram shows how Service A calls Service B internally using gRPC. The client stub serializes requests into compact protobuf messages sent over HTTP/2 to the server stub, which deserializes and invokes Service B logic.

Trade-offs
✓ Pros
→
Significantly reduces message size and serialization/deserialization time compared to JSON over HTTP/1.1.
→
Supports multiplexed streams and bi-directional streaming via HTTP/2, enabling efficient real-time communication.
→
Strongly typed contracts via Protocol Buffers reduce errors and improve developer productivity with auto-generated code.
→
Built-in support for deadlines, cancellations, and retries improves reliability in distributed systems.
✗ Cons
→
Requires learning Protocol Buffers syntax and tooling, adding initial developer overhead.
→
Less human-readable messages compared to JSON, complicating debugging without specialized tools.
→
HTTP/2 support may require updated infrastructure and load balancers that fully support HTTP/2 features.
Use gRPC for internal microservices communication when you need low latency, high throughput, and strong typing at scale, typically above hundreds of requests per second within a trusted network.
Avoid gRPC if your services require broad public API compatibility with browsers or clients that do not support HTTP/2 or protobuf, or if your traffic volume is low enough that JSON overhead is negligible.
Real World Examples
Google
Google developed gRPC to enable efficient communication between their internal microservices, reducing latency and improving scalability across their global infrastructure.
Netflix
Netflix uses gRPC internally to handle high-throughput service-to-service calls with low latency, especially for their edge services and streaming data pipelines.
Dropbox
Dropbox adopted gRPC to replace REST APIs for internal services, improving performance and enabling streaming file synchronization.
Alternatives
REST over HTTP/1.1
Uses text-based JSON over HTTP/1.1 without multiplexing or binary serialization.
Use when: Choose REST when interoperability with external clients and human-readable messages are priorities over performance.
Message Queue (e.g., Kafka, RabbitMQ)
Uses asynchronous messaging with decoupled producers and consumers instead of direct RPC calls.
Use when: Choose message queues when you need asynchronous, event-driven communication with guaranteed delivery.
Thrift
Similar to gRPC but uses its own binary protocol and supports multiple transport layers.
Use when: Choose Thrift if you require cross-language support with legacy systems or specific transport protocols.
Summary
gRPC improves internal service communication by using efficient binary serialization and HTTP/2 transport.
It reduces latency and CPU usage compared to traditional REST APIs with JSON over HTTP/1.1.
gRPC is best suited for high-scale microservices environments within trusted networks.

Practice

(1/5)
1. What is the main advantage of using gRPC for communication between internal services?
easy
A. It provides fast and efficient communication using HTTP/2 and Protocol Buffers.
B. It uses plain text JSON for easy debugging.
C. It requires no schema definition for messages.
D. It only works for external client-server communication.

Solution

  1. Step 1: Understand gRPC communication basics

    gRPC uses HTTP/2 for transport and Protocol Buffers for message serialization, making it fast and efficient.
  2. Step 2: Compare options with gRPC features

    Options A and B are incorrect because gRPC uses binary Protocol Buffers, not JSON, and requires schema definitions. It only works for external client-server communication. is wrong because gRPC is often used internally.
  3. Final Answer:

    It provides fast and efficient communication using HTTP/2 and Protocol Buffers. -> Option A
  4. Quick Check:

    gRPC speed and efficiency = It provides fast and efficient communication using HTTP/2 and Protocol Buffers. [OK]
Hint: Remember gRPC uses HTTP/2 + Protocol Buffers for speed [OK]
Common Mistakes:
  • Confusing gRPC with REST using JSON
  • Thinking gRPC doesn't need schemas
  • Assuming gRPC is only for external APIs
2. Which of the following is the correct way to define a gRPC service method in a Protocol Buffers (.proto) file?
easy
A. service UserService { function GetUser (UserRequest) returns UserResponse; }
B. service UserService { call GetUser (UserRequest) returns UserResponse; }
C. service UserService { method GetUser (UserRequest) -> UserResponse; }
D. service UserService { rpc GetUser (UserRequest) returns (UserResponse); }

Solution

  1. Step 1: Recall gRPC service syntax in .proto files

    The correct syntax uses rpc MethodName(RequestType) returns (ResponseType); inside a service block.
  2. Step 2: Match options to correct syntax

    Only service UserService { rpc GetUser (UserRequest) returns (UserResponse); } matches the exact gRPC syntax. Others use incorrect keywords like function, method, or call.
  3. Final Answer:

    service UserService { rpc GetUser (UserRequest) returns (UserResponse); } -> Option D
  4. Quick Check:

    gRPC method syntax = service UserService { rpc GetUser (UserRequest) returns (UserResponse); } [OK]
Hint: Look for 'rpc' keyword inside service block [OK]
Common Mistakes:
  • Using 'function' or 'method' instead of 'rpc'
  • Omitting parentheses around request/response types
  • Misplacing 'returns' keyword
3. Given this gRPC service definition snippet:
service OrderService {
  rpc CreateOrder (OrderRequest) returns (OrderResponse);
}

What happens when a client calls CreateOrder with invalid data that violates the schema?
medium
A. The server returns a validation error before processing the request.
B. The server accepts the request and processes it anyway.
C. The client call fails at compile time due to schema mismatch.
D. The server crashes due to invalid input.

Solution

  1. Step 1: Understand gRPC schema validation

    gRPC uses Protocol Buffers which enforce message structure. Invalid data is rejected by the server with an error.
  2. Step 2: Evaluate options based on gRPC behavior

    The server returns a validation error before processing the request. is correct because the server validates input and returns errors. The server accepts the request and processes it anyway. is unsafe and incorrect. The client call fails at compile time due to schema mismatch. is wrong because client code compiles but runtime validation happens. The server crashes due to invalid input. is incorrect as servers handle errors gracefully.
  3. Final Answer:

    The server returns a validation error before processing the request. -> Option A
  4. Quick Check:

    gRPC input validation = The server returns a validation error before processing the request. [OK]
Hint: Invalid data triggers server validation error, not crash [OK]
Common Mistakes:
  • Assuming client compile-time failure for invalid data
  • Thinking server processes invalid requests
  • Believing server crashes on bad input
4. You notice that your internal gRPC service calls are slow and sometimes timeout. Which of the following is the best first step to debug this issue?
medium
A. Remove Protocol Buffers and switch to JSON messages.
B. Rewrite all services to use REST instead of gRPC.
C. Check network latency and HTTP/2 connection health between services.
D. Increase client timeout without investigating.

Solution

  1. Step 1: Identify common causes of gRPC slowness

    Network issues and HTTP/2 connection problems often cause delays in gRPC calls.
  2. Step 2: Evaluate debugging approaches

    Check network latency and HTTP/2 connection health between services. is the best first step to diagnose root cause. Options B and C are drastic changes without diagnosis. Increase client timeout without investigating. ignores the problem source.
  3. Final Answer:

    Check network latency and HTTP/2 connection health between services. -> Option C
  4. Quick Check:

    Debug gRPC slowness = Check network latency and HTTP/2 connection health between services. [OK]
Hint: Start debugging network and HTTP/2 before changing code [OK]
Common Mistakes:
  • Jumping to rewrite services without diagnosis
  • Ignoring network as a cause
  • Blindly increasing timeouts
5. You are designing an internal microservices system using gRPC. Which design choice best improves scalability and fault isolation?
hard
A. Avoid using Protocol Buffers and send raw JSON over gRPC.
B. Define small, focused gRPC services with clear method boundaries and use load balancing.
C. Use gRPC only for external APIs and REST internally.
D. Combine all functionality into one large gRPC service to reduce network calls.

Solution

  1. Step 1: Understand microservices design principles with gRPC

    Small, focused services with clear APIs improve scalability and fault isolation. Load balancing helps distribute load.
  2. Step 2: Evaluate design options

    Define small, focused gRPC services with clear method boundaries and use load balancing. aligns with best practices. Combine all functionality into one large gRPC service to reduce network calls. creates a monolith, hurting scalability. Use gRPC only for external APIs and REST internally. wastes gRPC benefits internally. Avoid using Protocol Buffers and send raw JSON over gRPC. breaks gRPC efficiency by avoiding Protocol Buffers.
  3. Final Answer:

    Define small, focused gRPC services with clear method boundaries and use load balancing. -> Option B
  4. Quick Check:

    Microservices + gRPC best practice = Define small, focused gRPC services with clear method boundaries and use load balancing. [OK]
Hint: Small services + load balancing = scalable gRPC design [OK]
Common Mistakes:
  • Building large monolithic gRPC services
  • Using REST internally instead of gRPC
  • Ignoring Protocol Buffers benefits
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard