JournalSystem Design
System Design

REST API vs GraphQL vs Message Queue: When to Use What

Kirtesh Admute
March 18, 2024
7 min read
REST API vs GraphQL vs Message Queue: When to Use What
Share

REST API vs GraphQL vs Message Queue: When to Use What

Modern backend systems rarely rely on a single communication style. A well-designed system often combines REST APIs, GraphQL, and Message Queues to achieve scalability, flexibility, and reliability.

This article explains what they are, how they work, and when to use them — with practical examples.


1. REST API (Representational State Transfer)

What is a REST API?

A REST API is an architectural style where resources are accessed using standard HTTP methods in a stateless way.

Examples:

  • /users
  • /users/1
  • /products/42

HTTP Methods

MethodPurpose
GETRead data
POSTCreate data
PUTUpdate full resource
PATCHPartial update
DELETERemove resource

REST Request & Response

json
1// Request
2POST /users
3Content-Type: application/json
4
5{
6  "name": "Kirtesh",
7  "email": "kirtesh@ikirtesh.dev"
8}
9
10// Response
11{
12  "id": 1,
13  "name": "Kirtesh",
14  "email": "kirtesh@ikirtesh.dev"
15}

Common HTTP Status Codes

CodeMeaning
200Success
201Created
204No content
400Bad request
401Unauthorized
403Forbidden
404Not found
409Conflict
422Validation failed
429Rate limit
500Server error
503Service unavailable

REST Principles

  • Client–Server → Separation of concerns
  • Stateless → No session stored
  • Cacheable → Improve performance
  • Uniform Interface → Standard methods
  • Layered System → Works with gateways, proxies

When to Use REST

  • Public APIs
  • CRUD-based systems
  • Microservices communication

2. GraphQL – Client-Driven Data Fetching

What is GraphQL?

GraphQL is a query-based API where the client defines exactly what data it needs.

Single endpoint: /graphql


GraphQL Request & Response

graphql
# Request
query {
  user(id: 1) {
    name
    email
  }
}
json
1// Response
2{
3  "data": {
4    "user": {
5      "name": "Kirtesh",
6      "email": "kirtesh@ikirtesh.dev"
7    }
8  }
9}

Schema Example

graphql
type User {
  id: ID!
  name: String!
  email: String!
}

Operations

OperationPurpose
QueryRead
MutationWrite
SubscriptionReal-time

Advantages

  • No over-fetching / under-fetching
  • Fewer API calls
  • Ideal for frontend-heavy apps
  • Flexible data shaping

Limitations

  • Complex backend logic
  • Harder caching
  • Performance issues with large queries

When to Use GraphQL

  • Dashboards
  • Mobile apps
  • Data-heavy UIs
  • Micro-frontends

3. Message Queue (Asynchronous Communication)

What is a Message Queue?

A Message Queue enables asynchronous communication between services.

Flow:

Producer → Queue → Consumer

Message Types

TypeDescription
CommandDo something
EventSomething happened
NotificationInform systems/users

Example Code

java
// Producer
queue.send("ORDER_CREATED");

// Consumer
@QueueListener
public void handleOrder(String message) {
    processOrder(message);
}

Popular Tools

  • Apache Kafka
  • RabbitMQ
  • AWS SQS
  • Azure Service Bus

Benefits

  • Loose coupling
  • High scalability
  • Fault tolerance
  • Enables event-driven systems

When to Use Message Queues

  • Order processing
  • Email systems
  • Background jobs
  • Event-driven microservices

REST vs GraphQL vs Message Queue — Quick Comparison

FeatureRESTGraphQLMessage Queue
CommunicationSynchronousSynchronousAsynchronous
EndpointsMultipleSingleQueue-based
Client ControlLowHighN/A
Real-timeLimitedSubscriptionsEvent-driven
CouplingMediumMediumLow

Conclusion

Modern system design is about choosing the right tool for the right job:

  • REST → Stable, predictable APIs
  • GraphQL → Flexible, client-driven data
  • Message Queue → Scalable async processing

A strong backend engineer doesn’t pick one — they combine them strategically.

Written by

Kirtesh Admute

Full-stack engineer and digital architect — building scalable, production-grade systems with real-world impact.

March 18, 2024 7 min read

Newsletter

Stay in the
loop.

Weekly insights on system design and digital craft. 2,000+ developers subscribed.

No spam. Unsubscribe anytime.