What is gRPC and why is it used for internal services?
gRPC is a fast, open-source remote procedure call (RPC) framework that uses HTTP/2 for transport. It is used for internal services because it supports efficient communication, strong typing with Protocol Buffers, and bi-directional streaming, making it ideal for microservices.
Click to reveal answer
intermediate
How does gRPC use Protocol Buffers in service communication?
gRPC uses Protocol Buffers as its interface definition language and message format. This means service methods and message structures are defined in .proto files, which are then compiled to generate code for client and server, ensuring efficient and strongly typed communication.
Click to reveal answer
intermediate
What are the benefits of HTTP/2 in gRPC for internal services?
HTTP/2 provides multiplexing (multiple requests over one connection), header compression, and server push. These features reduce latency and improve throughput, making gRPC communication between internal services faster and more efficient.
Click to reveal answer
intermediate
Explain the difference between unary and streaming RPC in gRPC.
Unary RPC is a simple request-response where client sends one request and gets one response. Streaming RPC allows sending multiple messages: client streaming (client sends many, server responds once), server streaming (server sends many, client receives many), or bidirectional streaming (both send many).
Click to reveal answer
advanced
What are common security practices when using gRPC for internal services?
Common practices include using TLS encryption for transport security, mutual TLS for authentication between services, and enforcing authorization policies. Since gRPC uses HTTP/2, it supports strong encryption and identity verification to protect internal communication.
Click to reveal answer
What serialization format does gRPC primarily use?
AYAML
BJSON
CXML
DProtocol Buffers
✗ Incorrect
gRPC uses Protocol Buffers as its default serialization format for efficient and strongly typed communication.
Which HTTP version does gRPC use for transport?
AHTTP/1.1
BHTTP/1.0
CHTTP/2
DHTTP/3
✗ Incorrect
gRPC uses HTTP/2 to enable multiplexing, header compression, and low latency communication.
Which gRPC RPC type allows both client and server to send multiple messages?
ABidirectional streaming RPC
BClient streaming RPC
CUnary RPC
DServer streaming RPC
✗ Incorrect
Bidirectional streaming RPC allows both client and server to send multiple messages independently.
What is a key advantage of using gRPC for internal microservices?
AUses slow text-based protocols
BEnables efficient, strongly typed communication
CSupports only REST APIs
DDoes not support streaming
✗ Incorrect
gRPC enables efficient, strongly typed communication using Protocol Buffers and HTTP/2.
Which security feature is commonly used with gRPC for internal service communication?
AMutual TLS authentication
BPlain HTTP
CNo encryption
DBasic authentication only
✗ Incorrect
Mutual TLS is commonly used to authenticate and encrypt communication between internal gRPC services.
Describe how gRPC uses Protocol Buffers and HTTP/2 to improve internal service communication.
Think about how data is structured and sent between services.
You got /4 concepts.
Explain the different types of RPC calls supported by gRPC and when you might use each.
Consider the direction and number of messages exchanged.
You got /4 concepts.
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
Step 1: Understand gRPC communication basics
gRPC uses HTTP/2 for transport and Protocol Buffers for message serialization, making it fast and efficient.
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.
Final Answer:
It provides fast and efficient communication using HTTP/2 and Protocol Buffers. -> Option A
Quick Check:
gRPC speed and efficiency = It provides fast and efficient communication using HTTP/2 and Protocol Buffers. [OK]
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
Step 1: Recall gRPC service syntax in .proto files
The correct syntax uses rpc MethodName(RequestType) returns (ResponseType); inside a service block.
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.
Final Answer:
service UserService { rpc GetUser (UserRequest) returns (UserResponse); } -> Option D
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
Step 1: Understand gRPC schema validation
gRPC uses Protocol Buffers which enforce message structure. Invalid data is rejected by the server with an error.
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.
Final Answer:
The server returns a validation error before processing the request. -> Option A
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
Step 1: Identify common causes of gRPC slowness
Network issues and HTTP/2 connection problems often cause delays in gRPC calls.
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.
Final Answer:
Check network latency and HTTP/2 connection health between services. -> Option C
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
Step 1: Understand microservices design principles with gRPC
Small, focused services with clear APIs improve scalability and fault isolation. Load balancing helps distribute load.
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.
Final Answer:
Define small, focused gRPC services with clear method boundaries and use load balancing. -> Option B
Quick Check:
Microservices + gRPC best practice = Define small, focused gRPC services with clear method boundaries and use load balancing. [OK]