REST APIs vs. GraphQL: A Restaurant Analogy
When people hear terms like REST API and GraphQL, they often assume they are competing technologies. They are, but not in the sense that one is simply “better” than the other.
They solve the same problem in different ways. Each makes different trade-offs.
One of the easiest ways to understand those trade-offs is to imagine ordering food at a restaurant.
First, What Is an API?
An API (Application Programming Interface) is simply a way for two pieces of software to communicate.
Imagine you’re using a mobile banking app.
The app does not know your account balance. Instead, it asks the bank’s computer:
“What is Glenn’s current balance?”
The bank replies with the answer.
That conversation happens through an API.
REST and GraphQL are simply two different ways for that conversation to happen.
REST: Ordering From the Menu
Imagine walking into a traditional restaurant.
The restaurant has a menu with fixed meals.
- Cheeseburger Combo
- Caesar Salad
- Fish and Chips
- Steak Dinner
You choose one of the meals.
The kitchen already knows exactly how to prepare it.
If you order the Cheeseburger Combo, everyone knows what that means.
- The kitchen knows what to cook.
- The waiter knows roughly how long it will take.
- You know roughly how much food you’ll receive.
The meal is predictable.
REST APIs work much the same way.
Instead of meals, a REST API offers predefined endpoints.
GET /users/123
GET /users/123/orders
GET /products/456
Each endpoint returns a specific piece of information.
The server decides exactly what comes back.
What If You Want Something Different?
Suppose you only want the burger.
You do not want the fries or the drink.
The restaurant cannot change the meal just because you asked.
It’s not Burger King. You can’t have it your way.
You have three choices:
- accept the whole meal
- order something else
- place another order
REST works in much the same way.
If you need information from several endpoints, your application makes several requests.
GraphQL: A Build-Your-Own Restaurant
Now imagine a different restaurant.
Instead of ordering Meal #7, the waiter asks:
“What would you like?”
You reply:
“I’d like a burger with Swiss cheese, bacon, no onions, curly fries, and a Coke.”
The next customer says:
“I’ll have a grilled chicken sandwich with avocado and a salad.”
The kitchen prepares exactly what each customer requested.
Nobody receives the same meal unless they asked for the same thing.
This is how GraphQL works.
Instead of choosing from fixed endpoints, the application describes exactly which pieces of information it wants.
For example:
Customer
Name
Email
Recent Orders
Order Total
Order Date
The server assembles the response and returns exactly those fields.
No more.
No less.
The Important Difference
The key difference is not flexibility.
It is who decides what the response looks like.
With REST:
The server decides the menu.
With GraphQL:
The client builds the order from the available ingredients.
Notice the phrase available ingredients.
A GraphQL client cannot ask for information that does not exist.
Just as a restaurant cannot put pineapple on your burger if it does not stock pineapple, GraphQL only allows clients to request fields that the server has chosen to expose.
One Request Instead of Several
Imagine you’re viewing a customer’s profile.
You need:
- their name
- their address
- their five most recent orders
With REST, the application might need three separate requests.
Get customer
Get address
Get recent orders
With GraphQL, it can ask for everything at once.
Customer
Name
Address
Recent Orders
The server gathers the information and sends it back in one response.
This is one of GraphQL’s biggest strengths.
Predictability vs. Flexibility
The restaurant analogy becomes even more useful when we think about cost.
Imagine every meal on the menu includes its preparation time.
| Meal | Typical Preparation Time |
|---|---|
| Caesar Salad | 5 minutes |
| Cheeseburger Combo | 10 minutes |
| Steak Dinner | 20 minutes |
When someone orders the Cheeseburger Combo, the kitchen already knows roughly how much work is involved.
There may be small variations, but the cost is predictable.
REST APIs work the same way.
Developers quickly learn things like:
- this endpoint is fast
- this endpoint returns a small amount of data
- this endpoint is expensive
Each endpoint has a fairly well-understood cost.
GraphQL Makes Cost Harder to Predict
Now return to the build-your-own restaurant.
Two customers arrive.
The first says:
“I’d like a cheeseburger.”
The second says:
“I’d like a cheeseburger, fries, onion rings, three dipping sauces, a milkshake, dessert, and another burger to take home.”
Both customers started with the same words.
Yet the second order creates much more work.
GraphQL queries behave the same way.
Two queries may look almost identical.
The first might ask for:
- customer name
- address
The second asks for:
- customer name
- address
- recent orders
- first item in each order
The second query can require dramatically more work.
It may:
- access many more database tables
- call several internal services
- return much more data
- take significantly longer to complete
A small change to the query can create a much larger increase in work.
Why This Matters
With REST, developers can usually estimate the cost of an endpoint before it runs.
With GraphQL, the server often has to examine the query before it knows how expensive it will be.
Because of this, GraphQL servers often include extra protections.
For example:
- maximum query depth
- complexity limits
- maximum response sizes
- request cost calculations
These protections help prevent a client from accidentally—or deliberately—asking for an enormous amount of data.
REST APIs generally need fewer of these safeguards because each endpoint already has a known purpose and a more predictable cost.
Which One Is Better?
Neither.
They optimize for different things.
REST emphasizes simplicity and predictability.
GraphQL emphasizes flexibility and efficiency for clients.
The right choice depends on the problem being solved.
A small internal service with a few well-defined operations may benefit from REST.
A complex application that needs different combinations of related data may benefit from GraphQL.
Many large organizations use both.
Summary
| REST | GraphQL |
|---|---|
| Fixed menu | Build-your-own order |
| Server decides the response | Client chooses the response |
| Predictable request cost | Request cost varies with each query |
| Often requires multiple requests | Often combines related data into one request |
| Easier to cache and monitor | Requires additional safeguards for expensive queries |
REST asks:
“Which menu item would you like?”
GraphQL asks:
“Tell me exactly what you’d like from the menu.”
Neither approach is inherently better.
One offers predictability.
The other offers flexibility.
Choosing between them means deciding which trade-offs best fit your application.