“Should we use GraphQL?”
The engineering team splits in half. One side says it’s amazing. The other says REST is fine. Nobody can explain the difference without defaulting to “it depends.”
This guide settles it.
This is the Mastery Guide to API Protocols. We’ll use the “Restaurant Menu” model to understand REST (Fixed Menu), GraphQL (Custom Order), and gRPC (Walkie-Talkie between chefs).
Part 1: Foundations (The Mental Model)
REST = The Printed Menu
A REST API is like a restaurant with a printed menu. The kitchen decides what dishes exist. You pick from the list.
- Strength: Simple, universal. Every language and every tool (Postman, curl) understands it.
- Weakness: You get exactly what’s on the menu. If you only want the salad from the “Grilled Chicken Salad Combo,” you still pay for the whole combo. (Over-fetching). Or the menu doesn’t have exactly what you want; the waiter brings you three separate dishes. (Under-fetching).
GraphQL = The Custom Order
GraphQL is like a restaurant where you tell the chef exactly what you want.
- “I want the chicken breast, no sauce, extra rice, and the mango salad dressing.”
- The kitchen makes exactly that. One trip. Exactly what you asked for.
- Strength: No over-fetching. No under-fetching. Perfect for mobile apps where bandwidth is limited.
- Weakness: The kitchen is complex. You must manage a schema. Authorization is harder (is this user allowed to ask for
user.creditCard?).
gRPC = The Chef’s Walkie-Talkie
gRPC is not for customers. It’s for kitchen-to-kitchen communication.
- Chef from the Cold Kitchen radios Chef from the Hot Kitchen: “Steak ready?”
- Uses a binary protocol (not human-readable text) for maximum speed.
- Strongly typed. The contract is defined in a
.protofile. - Strength: Blazing fast (3x-10x JSON/REST). Bi-directional streaming possible.
- Weakness: Not for browsers. The
.protocontract requires shared tooling.
Part 2: The Investigation (The Technical Differences)
1. The N+1 Problem (REST’s Achilles Heel)
Imagine a UI that shows a list of Posts with their Author names.
| |
GraphQL’s Fix: One query, exactly the data needed.
| |
2. gRPC: The Proto Contract
The .proto file is the DNA of gRPC — a shared language both client and server understand.
| |
From this one file, protoc generates strongly-typed client and server code for Python, Go, Java, etc.
Part 3: The Diagnosis (When to Use What)
| Use Case | Best Choice | Why |
|---|---|---|
| Public API (third-party devs) | REST | Universal — any language, any tool. |
| Mobile App (bandwidth matters) | GraphQL | Fetch exactly what the screen needs. No more. |
| Internal Microservices | gRPC | Fast, type-safe, streaming support. |
| Real-time data (chat, live feed) | GraphQL Subscriptions or gRPC Streaming | Built-in streaming. |
| Simple CRUD | REST | Don’t over-engineer. |
| BFF (Backend for Frontend) | GraphQL | Aggregates multiple services for one UI. |
Part 4: The Resolution (Code Examples)
1. REST (Python/Django)
| |
2. GraphQL (Python/Strawberry)
| |
3. gRPC (Python)
| |
Final Mental Model
| |
Start with REST. Move to GraphQL only when mobile clients complain about data size. Move to gRPC when internal service latency becomes a bottleneck.
