Hello! Welcome to your fourth lesson in the "System Design Interview Framework" module.
In our last lesson, we mastered back-of-the-envelope estimation. We learned how to translate vague requirements into concrete numbers for throughput, storage, and bandwidth. Most importantly, we saw how a Staff-level engineer uses these estimates not as a mere academic exercise, but as a powerful tool to drive critical architectural decisions, such as choosing a database or justifying an in-memory cache.
Today, we'll build directly on that foundation. Having established the "what" (requirements) and "how much" (estimations), we'll now define the "how to interact with it." The learning outcome for this lesson is to define clear API contracts (e.g., REST, gRPC) for the system being designed.
An API contract is the formal agreement between a service and its clients. Getting this right is crucial, as it dictates how the outside world interacts with your system. For a Staff-level interview, this step is less about listing every possible endpoint and more about demonstrating your ability to choose the right communication protocol and articulate the trade-offs involved.
1. The Core of API Design: A 5-Minute Pitch
In a 45-minute interview, you can't afford to get bogged down in excessive detail during the API design phase. The goal is to spend about five minutes demonstrating a clear, reasoned approach and then move on to the more complex architectural components.
Let's start by watching a video that frames the API design discussion for a system design interview, emphasizing the key protocols and the importance of being concise.
API Design in System Design Interviews w/ Meta Staff Engineer
This video from Hello Interview provides an excellent overview of API design in the context of a system design interview. It introduces the main protocols and sets the expectation for the level of detail required.
Watch the first four minutes of the video (00:00:00 - 00:03:59). Pay close attention to: The speaker's advice on time management: don't spend more than 5 minutes on API design. The three main API protocols to consider: REST, GraphQL, and RPC (for microservices). The assertion that REST should be your default choice unless there's a compelling reason otherwise.
This sets the stage for our first major decision: which protocol to use?
2. Choosing Your Protocol: REST vs. gRPC vs. GraphQL
Your choice of API protocol has significant implications for performance, flexibility, and developer experience. As a Staff+ candidate, you're expected to justify your choice based on the system's requirements.
API Design for System Design Interviews
To solidify your understanding of these protocols, let's read a concise summary from the Hello Interview learning platform. This will help you articulate the 'why' behind your choice.
Read the 'API Types' section. Focus on the core use case for each protocol: REST: The default for standard web services and CRUD operations. GraphQL: For flexible data fetching, especially with diverse clients (e.g., mobile vs. web) that have different data needs. RPC (gRPC): For high-performance internal communication between microservices.
Here is a visual comparison to help you remember the key differences, particularly between REST and gRPC, which are the most common choices for external and internal APIs, respectively.

The Staff-Level Playbook:
- For external, client-facing APIs: Default to REST. It's universally understood, stateless, and works over standard HTTP. Say, "I'll start with a standard REST API for the public-facing endpoints, as it's simple and well-supported."
- For internal, service-to-service communication: Propose gRPC. It's highly performant, type-safe, and supports advanced features like streaming. Say, "For communication between our internal microservices, I'd opt for gRPC to maximize performance and ensure type safety."
- If requirements demand flexibility: Mention GraphQL as a possibility if the problem involves clients with vastly different data needs (e.g., designing the Facebook News Feed API, which serves mobile, web, and third-party apps).
3. Defining a REST API Contract
Since REST is the default for most interview problems, let's detail how to define a contract quickly and effectively. A good REST API is designed around resources, which should map directly to the core entities you identified earlier in the interview framework.
For a system like Ticketmaster, your core entities (and thus, resources) might be events, venues, tickets, and bookings.
The same video we watched earlier provides a great walkthrough of the components of a REST API.
API Design in System Design Interviews w/ Meta Staff Engineer
Let's continue with the 'API Design in System Design Interviews' video to break down the mechanics of REST.
Watch the segment from 00:03:59 to 00:12:41. Focus on these four key areas: Resource Modeling: How to use plural nouns in URLs (e.g., /events). HTTP Methods: The purpose of GET, POST, PUT, PATCH, and DELETE, and the concept of idempotency. Passing Inputs: The distinct roles of path parameters (required identifiers, e.g., /events/{id}), query parameters (optional filters, e.g., ?city=LA), and the request body (data for creation/updates). Handling Responses: Using status code families (2xx, 4xx, 5xx) and simplifying the response body representation (e.g., returns: [Event]).
Here's a quick reference image that summarizes many of these best practices.
Example REST Endpoint Definition:
Let's apply this to a hypothetical "get fare estimate" feature for Uber.
- Action: A user provides a start and end location to get a price and ETA. This creates a temporary "fare" or "ride" resource.
- Method:
POST, because we are creating a new resource (the fare estimate). - Endpoint:
/rides/estimateor just/estimates. - Request Body: Contains the source and destination coordinates.
{ "source_location": { "lat": 34.0522, "lon": -118.2437 }, "destination_location": { "lat": 34.1522, "lon": -118.4437 } } - Response (Success - 201 Created): Returns the key details of the newly created estimate.
{ "estimate_id": "est_123xyz", "estimated_fare": { "amount": 25.50, "currency": "USD" }, "estimated_arrival_time": "2023-10-27T18:45:00Z" }
4. Defining a gRPC Service Contract
For internal communication, especially at companies like Google (the creator of gRPC) and Uber (a heavy user), demonstrating knowledge of gRPC is a significant advantage.
Unlike REST, gRPC is action-oriented and contract-first, using Protocol Buffers (protobufs) to define services.
How to Design gRPC Service Contracts
This article from OneUptime provides a practical guide to designing gRPC service contracts. We'll focus on the core concepts.
Read the first four sections of the article: Protocol Buffers Basics: Understand the purpose of a .proto file, the syntax, package definitions, and the importance of field numbers. Message Design Principles: Grasp the key ideas of using specific message types (not primitives), grouping related fields, and using repeated for collections. Defining Services and RPCs: See how a service groups related RPC methods and the naming conventions. RPC Patterns: This is crucial. Understand the four patterns: Unary, Server Streaming, Client Streaming, and Bidirectional Streaming. Think about when you might use each one (e.g., Client Streaming for file uploads, Server Streaming for notifications).
Example gRPC Service Definition:
Let's imagine an internal DriverService that the MatchingService calls to find nearby drivers.
// In a file like driver/v1/driver_service.proto
syntax = "proto3";
package uber.driver.v1;
// The service definition.
service DriverService {
// A unary RPC to find nearby drivers.
rpc FindNearbyDrivers(FindNearbyDriversRequest) returns (FindNearbyDriversResponse);
// A server-streaming RPC to get real-time location updates for a specific driver.
rpc TrackDriver(TrackDriverRequest) returns (stream Location);
}
// Request for finding drivers.
message FindNearbyDriversRequest {
Location search_center = 1;
double radius_meters = 2;
int32 limit = 3;
}
// Response containing nearby drivers.
message FindNearbyDriversResponse {
repeated Driver drivers = 1;
}
// Data structures used in the service.
message Driver {
string driver_id = 1;
Location current_location = 2;
enum Status {
STATUS_UNSPECIFIED = 0;
AVAILABLE = 1;
ON_TRIP = 2;
OFFLINE = 3;
}
Status status = 3;
}
message Location {
double latitude = 1;
double longitude = 2;
}
message TrackDriverRequest {
string driver_id = 1;
}
In an interview, you wouldn't write out the full .proto file, but you could verbally describe it: "The Matching service would make a unary RPC call, FindNearbyDrivers, to the Driver service, passing the rider's location. The Driver service would return a list of available driver objects."
5. Staff-Level Polish: Security, Pagination, and Pragmatism
Merely listing endpoints isn't enough. A senior candidate demonstrates a production-ready mindset.
Design Uber w/ a Ex-Meta Staff Engineer: System Design Interview breakdown
Let's watch a clip from a mock interview for designing Uber. The candidate, an ex-Meta Staff Engineer, demonstrates several senior-level thought processes while defining his API.
Watch the segments from 00:13:40 to 00:16:50 and 00:18:34 to 00:20:42. Notice how the candidate: Uses appropriate HTTP verbs: POST to create an estimate, PATCH to update it into a requested ride. Identifies hidden APIs: Realizes that to match drivers, he also needs an API for drivers to update their location (PATCH /locations). Shows pragmatism: Explicitly states he is omitting data types like number or string to save time, a classic senior move. Highlights a critical security point: Explains why user_id should not be in the request body and must be derived from a session token or JWT in the header to prevent impersonation.
Key topics to briefly touch upon to show seniority:
- Authentication: "Endpoints that create or modify data, like
POST /rides, will be authenticated. We'll use a JWT passed in theAuthorizationheader to identify the user." - Pagination: "For any endpoint that returns a list, like
GET /users/{id}/ride-history, I'll implement cursor-based pagination to handle large datasets efficiently. The request will take alimitand an optionalcursor, and the response will include the list of items and anext_cursor." - Rate Limiting: "We'll apply rate limiting on sensitive or expensive endpoints to prevent abuse. For example, we might limit fare estimate requests to 10 per minute per user."
- Versioning: "I would version the API in the URL, like
/v1/rides, to allow for future non-breaking changes."
Conclusion
Defining the API contract is a pivotal moment in a system design interview. It transitions your discussion from abstract requirements to a concrete interface. For your Staff-level role, the emphasis is on making deliberate, well-justified choices that reflect real-world experience.
Key Takeaways:
- Be Protocol-Aware: Start with REST for external APIs and suggest gRPC for internal ones. Be ready to explain the trade-offs (performance, type safety, flexibility).
- Be Resource-Oriented (for REST): Structure your endpoints around nouns (core entities), not verbs. Use HTTP methods correctly to act on those resources.
- Be Action-Oriented (for gRPC): Think in terms of functions and procedures. Mention the power of streaming for relevant use cases.
- Think Like a Senior Engineer: Go beyond just the endpoints. Briefly mention authentication, pagination, and versioning to show you're designing a robust, production-ready system.
- Be Pragmatic: Keep it concise. Define the most critical APIs and verbally mention others, but quickly move on to the high-level design. The goal is to demonstrate competence, not to write a full OpenAPI specification.
Preview of the Next Lesson:
With our API contract defined, we have a clear boundary between clients and our system. Now, we need to design the system behind that boundary. This brings us to one of the most fundamental trade-offs in distributed systems. In the next lesson, we will learn how to drive trade-off discussions around data consistency and availability (CAP theorem).