Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is gRPC and why is it used for internal communication in microservices?
gRPC is a fast, open-source remote procedure call (RPC) framework that uses HTTP/2 for transport. It is used for internal communication because it supports efficient, low-latency, and strongly-typed communication between microservices.
Click to reveal answer
intermediate
How does gRPC use Protocol Buffers in communication?
gRPC uses Protocol Buffers (protobuf) as its interface definition language and message format. Protobuf defines the service methods and message structures, which are then compiled into code for different languages, enabling efficient serialization and deserialization.
Click to reveal answer
intermediate
What are the benefits of using HTTP/2 in gRPC?
HTTP/2 allows multiplexing multiple requests over a single connection, reduces latency with header compression, and supports bidirectional streaming. This makes gRPC communication faster and more efficient compared to HTTP/1.1.
Click to reveal answer
intermediate
Explain the difference between unary and streaming RPC in gRPC.
Unary RPC is a simple request-response where the client sends one request and gets one response. Streaming RPC allows sending multiple messages: client streaming sends many requests, server streaming sends many responses, and bidirectional streaming allows both sides to send multiple messages.
Click to reveal answer
advanced
Why is gRPC considered suitable for internal microservice communication but less common for public APIs?
gRPC is efficient and strongly typed, ideal for internal services where performance and strict contracts matter. However, it requires HTTP/2 and protobuf clients, which may limit browser support and ease of use for public APIs compared to REST/JSON.
Click to reveal answer
What transport protocol does gRPC use by default?
AUDP
BHTTP/1.1
CTCP
DHTTP/2
✗ Incorrect
gRPC uses HTTP/2 as its transport protocol to enable multiplexing and efficient communication.
Which serialization format is primarily used by gRPC?
AJSON
BXML
CProtocol Buffers
DYAML
✗ Incorrect
gRPC uses Protocol Buffers for defining service contracts and serializing messages.
Which gRPC communication type allows both client and server to send multiple messages independently?
ABidirectional streaming RPC
BUnary RPC
CServer streaming RPC
DClient streaming RPC
✗ Incorrect
Bidirectional streaming RPC allows both client and server to send multiple messages independently.
Why is gRPC preferred for internal microservice communication?
AIt supports low latency and strong typing
BIt is easier to use in browsers
CIt uses plain text messages
DIt uses XML for data exchange
✗ Incorrect
gRPC supports low latency communication and strong typing, which are important for internal microservices.
Which of the following is NOT a feature of gRPC?
AAutomatic code generation from service definitions
BUses HTTP/1.1 for transport
CSupports streaming communication
DSupport for multiple languages
✗ Incorrect
gRPC uses HTTP/2, not HTTP/1.1, for transport.
Describe how gRPC works for internal communication between microservices.
Think about the transport, message format, and communication patterns.
You got /5 concepts.
Explain the advantages and limitations of using gRPC for internal microservice communication.
Consider both technical benefits and practical constraints.
You got /3 concepts.
Practice
(1/5)
1. What is the main advantage of using gRPC for internal communication between microservices?
easy
A. It requires no predefined message formats.
B. It provides fast, efficient, and strongly typed communication.
C. It only works with services written in the same language.
D. It uses plain text messages for easy debugging.
Solution
Step 1: Understand gRPC communication benefits
gRPC uses Protocol Buffers which are compact and strongly typed, making communication fast and reliable.
Step 2: Compare with other options
Options B, C, and D are incorrect because gRPC requires predefined message formats, supports multiple languages, and uses binary messages, not plain text.
Final Answer:
It provides fast, efficient, and strongly typed communication. -> Option B
Quick Check:
gRPC speed and typing [OK]
Hint: gRPC is fast and typed, unlike plain text or language-specific methods [OK]
Common Mistakes:
Thinking gRPC uses plain text messages
Assuming gRPC works only with one language
Believing gRPC needs no message definitions
2. Which of the following is the correct way to define a gRPC service method in a .proto file?
easy
A. method GetUser returns UserResponse(UserRequest);
B. service GetUser { rpc UserRequest returns UserResponse; }
C. rpc GetUser (UserRequest) returns (UserResponse);
D. function GetUser(UserRequest): UserResponse;
Solution
Step 1: Recall gRPC .proto syntax
In .proto files, service methods are defined using the syntax: rpc MethodName (RequestType) returns (ResponseType);
Step 2: Validate options
rpc GetUser (UserRequest) returns (UserResponse); matches the correct syntax. Options B, C, and D do not follow the .proto syntax for defining rpc methods.
Final Answer:
rpc GetUser (UserRequest) returns (UserResponse); -> Option C
Quick Check:
.proto rpc syntax [OK]
Hint: Remember: rpc Method(Request) returns (Response); in .proto files [OK]
Common Mistakes:
Using 'service' keyword incorrectly for methods
Confusing method syntax with programming language functions
Omitting parentheses around request and response types
3. Given the following gRPC client call in Python, what will be the output if the server returns a UserResponse with name='Alice' and age=30?
Step 1: Understand the client call and server response
The client calls GetUser with id=123. The server responds with UserResponse containing name='Alice' and age=30.
Step 2: Analyze the print statement output
The print statement accesses response.name and response.age, so it will output the values returned by the server.
Final Answer:
Name: Alice, Age: 30 -> Option A
Quick Check:
Client prints server response fields [OK]
Hint: Client prints server response fields directly as returned [OK]
Common Mistakes:
Assuming client sends back request data instead of server response
Confusing method call syntax causing errors
Expecting empty or default values without server response
4. A developer wrote this gRPC service definition but the client fails to connect:
service UserService {
rpc GetUser UserRequest returns UserResponse;
}
What is the error in this definition?
medium
A. Missing parentheses around request and response types.
B. Service name should be lowercase.
C. rpc keyword should be capitalized as RPC.
D. UserRequest and UserResponse must be strings.
Solution
Step 1: Check gRPC method syntax in .proto
The correct syntax requires parentheses around request and response types: rpc MethodName (RequestType) returns (ResponseType);
Step 2: Identify the error in the given code
The code misses parentheses around UserRequest and UserResponse, causing client connection failure.
Final Answer:
Missing parentheses around request and response types. -> Option A
Quick Check:
Parentheses required in rpc method signature [OK]
Hint: Always use parentheses around request and response in rpc methods [OK]
Common Mistakes:
Ignoring parentheses in rpc method definitions
Thinking service names must be lowercase
Misunderstanding rpc keyword casing rules
5. You have multiple microservices written in different languages that need to communicate internally with low latency and strict message contracts. Which approach best fits this scenario?
hard
A. Use REST APIs with JSON for all communication.
B. Use message queues with XML messages.
C. Use plain TCP sockets with custom binary protocol.
D. Use gRPC with Protocol Buffers for internal communication.
Solution
Step 1: Analyze requirements for low latency and strict contracts
REST with JSON is flexible but slower and less strict. Plain TCP with custom protocol is complex and error-prone. Message queues add latency and XML is verbose. gRPC with Protocol Buffers is designed for efficient, strongly typed, multi-language communication.
Final Answer:
Use gRPC with Protocol Buffers for internal communication. -> Option D
Quick Check:
Low latency + strict contracts = gRPC [OK]
Hint: gRPC + Protobuf = fast, typed, multi-language communication [OK]