Design gRPC service contracts for microservices
PremiumAPI designMedium
- gRPC
- Protobuf schema design
- gRPC status codes
Quick answer
This API design interview question asks you to design gRPC service contracts for microservices. Aim for a design that exposes a clear, consistent and safe interface, then explain the resources, requests, responses and error handling. Interviewers want to see how you name resources, version the interface and handle failure cases.
The problem
Design gRPC service contracts for microservices at a retailer: the .proto definitions between an order service, an inventory service and a notification service. The hard parts are an error model callers can branch on, deadlines with safe retries, and schema changes that never break another team.
The retailer is splitting a monolith, and the teams keep breaking each other with renamed fields and unclear errors. Define the messages and RPCs, the streaming choices, the error model, deadlines and retry rules, metadata for auth and tracing, and the compatibility rules every team must follow.
What must the system do?
- Inventory: ReserveStock for a list of SKUs and quantities with a reservation ID and expiry; ReleaseStock; GetStock for a list of SKUs; a stream of stock-level changes for dashboards.
- Errors: Callers can distinguish not found, insufficient stock, invalid argument, deadline exceeded and unavailable, and get machine-readable details.
How well must it do it?
- Compatibility: A service can deploy a new contract version while callers on the old one keep working, in either order.
- Safety: Retries never double-reserve stock or send a notification twice.
What scale should you design for?
Use these numbers in your estimates.
The scale numbers unlock with this questionUnlock
Key concepts
- gRPC
- Protobuf schema design
- gRPC status codes
- Deadlines and retries
- gRPC streaming
- Field numbering
How you’ll practise
- Use cases
- Resources
- Endpoints
- Errors, auth and limits
- Versioning
- Wrap-up
Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.
What do interviewers look for?
In any API design round.
- Starts from the clients and the use cases
- Names resources and operations consistently
- Defines request and response shapes and status codes
- Covers authentication, rate limits and idempotency
- Plans pagination, filtering and versioning
- Explains how clients learn about and recover from errors
Questions people ask about this interview question
- Which design type is this question?
- It is an API design question. You design gRPC service contracts for microservices and explain your choices the way you would in an interview.
- Is this question asked at entry level?
- It is marked Medium. Entry-level engineers can practise it, but it expects you to reason about requirements and trade-offs, not only list components.
- What should I cover first?
- Start with the clients, the main use cases and the resources they need. Agree on scope with the interviewer before you design anything.
- Can I practise it for free?
- It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.
Related questions
Updated · Written by the SevyDevy team