Skip to content
Microservices Architecture and APIs with GraphQL
4 min read

Microservices Architecture and APIs with GraphQL

Microservices and GraphQL — a topic I’m excited about. I’ve been building distributed systems and REST is falling short for what I need on the mobile side. GraphQL is gaining traction and I wanted to share what I’ve learned.

Here are the concepts I covered. If you prefer to see the slides directly, here they are.

Audience during the talk at Pereira Tech Talks


Divide and Conquer

The core principle behind microservices is simple: divide and conquer. Instead of building a monolithic application that does everything, we break the system into smaller, focused services. Each microservice does one thing and does it well — a philosophy I inherited from the Unix tradition and that has served me well for scalable, maintainable architectures.

Divide and conquer — the strategic principle behind microservices


What Is a Microservice?

To me, a microservice is a self-contained unit of functionality that meets several characteristics I value:

  • Does one thing well — focused on a single business capability
  • Is autonomous — identified by a unique URL, operates independently
  • Is isolated — I can modify, test, and deploy it without impacting other parts of the solution
  • Is elastic — can be scaled independently (vertically or horizontally)
  • Is resilient — fault tolerant and highly available
  • Is responsive — responds to requests in a reasonable amount of time
  • Is message oriented — relies on asynchronous message-passing to establish boundaries between components
  • Is programmable — exposes APIs; applications are composed from multiple microservices
  • Is automated — its lifecycle (dev, build, test, staging, production) is managed through automation

Are They the Silver Bullet? No.

Whenever I talk about microservices, someone asks if they’re the solution for everything. No. They’re a powerful pattern, but they come with trade-offs. I showed this table in the talk:

ProsCons
ScalableNetwork latency increases with message interchange
Reduce deployment costsDeployment and testing complexity grows with the number of service interactions
Can be developed by a small teamToo fine-grained services may create more overhead than utility
Team only needs to know the service’s business logicMessage formats, restrictions, and interaction knowledge are required
Continuous deploymentVersioning is critical due to interactions with older service versions
Use the technology you preferTransactional operations across many services increase logic complexity

GraphQL: Why It Won Me Over

GraphQL was created by Facebook in 2012, driven by the mobile team. It’s a query language for communication between clients and servers — a complete alternative to REST. (Note: it’s not like SQL; it’s a typed API language, not a database query language.)

What I liked most from the start: the client defines what it receives. No more over-fetching or multiple requests per view.

REST vs GraphQL

RESTGraphQL
It’s a conventionIt’s a typed language
Server exposes resourcesClient defines what it receives
Often sends more data than neededOnly necessary data is sent
Multiple requests per viewOne request per view
Documentation separate from developmentDocumented by definition
Multiple endpointsSingle endpoint: /graphql

Core Concepts

  • Schema — Defines the structure of your API
  • Types — Strong typing for queries and responses
  • Queries — Read operations
  • Mutations — Write operations
  • Resolvers — Functions that resolve each field in the schema

If you want to play with a real example, the Star Wars API (SWAPI) is great to explore.


Resources I Use

GraphQL

Microservices & Docker


View full presentation

Let’s keep building.