Skip to content

Cli Grpc

← Back to all decks

10 cards — 🟢 3 easy | 🟡 4 medium | 🔴 3 hard

🟢 Easy (3)

1. What are the four types of gRPC service methods?

Show answer Unary RPC: single request, single response (like a function call). Server streaming: client sends one request, server returns a stream. Client streaming: client sends a stream, server returns one response. Bidirectional streaming: both sides send streams concurrently. Unary is most common; streaming is used for real-time data feeds, file uploads, and chat-like interactions.

2. What transport protocol does gRPC use and why?

Show answer gRPC uses HTTP/2, which provides multiplexing (multiple concurrent RPCs on one TCP connection), header compression (HPACK), flow control, and server push. This makes gRPC much more efficient than HTTP/1.1-based REST for high-throughput service-to-service communication, especially when many small requests are made concurrently.

3. How do you invoke a gRPC method using grpcurl?

Show answer Use "grpcurl -plaintext -d '{"name": "world"}' localhost:50051 helloworld.Greeter/SayHello" for unary calls. The -plaintext flag disables TLS (for local dev). The -d flag passes the JSON request body. For streaming, pipe input with -d @. List all methods first with "grpcurl -plaintext localhost:50051 list" to discover the service and method names.

🟡 Medium (4)

1. What is grpcurl and how does it use server reflection?

Show answer grpcurl is a command-line tool for interacting with gRPC services, similar to curl for HTTP. With server reflection enabled, grpcurl can discover available services and methods without needing proto files: "grpcurl -plaintext localhost:50051 list" lists services, "grpcurl -plaintext localhost:50051 describe " shows methods. Without reflection, you must pass --proto or --protoset.

2. What is gRPC server reflection and when should it be enabled?

Show answer Server reflection is a gRPC service that exposes the server's protobuf schema at runtime, allowing clients and debugging tools to discover services, methods, and message types without proto files. Enable it in development and staging for debugging with grpcurl/grpcui. Disable in production for security (it reveals your API surface to any client).

3. What is the gRPC Health Checking Protocol and how is it used?

Show answer The gRPC Health Checking Protocol is a standardized service (grpc.health.v1.Health) that reports serving status per service name. It returns SERVING, NOT_SERVING, or UNKNOWN. Kubernetes uses grpc-health-probe or native gRPC health checks (since 1.24) to determine pod readiness/liveness. It replaces ad-hoc health endpoints with a protocol-level standard.

4. What are the main gRPC load balancing strategies?

Show answer Pick-first: connect to the first resolved address (no balancing). Round-robin: distribute RPCs evenly across all resolved addresses. Client-side with external resolver: use a service mesh or DNS-SRV for endpoint discovery. Proxy-based (L7): use Envoy/gRPC-aware proxy that understands HTTP/2 frames. Note: L4 load balancers (TCP) do not work well because HTTP/2 multiplexes on one connection.

🔴 Hard (3)

1. How do gRPC status codes differ from HTTP status codes?

Show answer gRPC has its own status code system (16 codes) separate from HTTP. Key mappings: OK=0, InvalidArgument=3 (not HTTP 400), NotFound=5 (not HTTP 404), PermissionDenied=7 (not HTTP 403), Unavailable=14 (closest to HTTP 503). When gRPC travels through HTTP proxies or gateways, these codes may be translated, causing confusion if you only check HTTP status.

2. What is deadline propagation in gRPC and why is it important for microservices?

Show answer A gRPC deadline sets an absolute time by which the entire RPC chain must complete. When service A calls B which calls C, the deadline propagates through the chain. If the deadline is exceeded at any point, the RPC is cancelled with DEADLINE_EXCEEDED. This prevents cascading timeouts where downstream services continue working on requests the caller has already abandoned.

3. Why does gRPC use Protocol Buffers instead of JSON?

Show answer Protocol Buffers are a binary serialization format that is 3-10x smaller and 20-100x faster to parse than JSON. They use a strongly-typed schema (.proto files) that enables code generation, backward/forward compatibility via field numbers, and compile-time type checking. The tradeoff is human readability -- binary payloads cannot be inspected without tooling.