AI Hints
Home›System Design Tutorial›Safe Retries and API Styles
System Design · Lesson 20 of 120

GraphQL and gRPC

Other API styles.

⏱ 2 min read▶ Video at 22:44🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

REST isn't the only style. GraphQL lets the client ask for exactly the fields it needs. And g RPC is a fast binary style, popular between services inside a company.

GraphQL and gRPC
From the video: GraphQL and gRPC
  • REST is not the only way
  • GraphQL: ask for fields
  • gRPC: fast, binary

GraphQL

With REST, a phone app might call three endpoints to build one screen, and get fields it doesn't need. With GraphQL, it sends one query, listing exactly the fields it wants, across several resources. The trade off is a more complex server, and harder caching.

REST

  • Several calls per screenFixed responsesSimple to cache

GraphQL

  • One query per screenExactly the fields askedHarder to cache

Choosing a style

So which should you use? REST is the safe default for public APIs. GraphQL shines when many different clients need different shapes of data. g RPC, with its compact binary messages, is great for fast calls between your own services. And many companies use all three.

StyleBest for
REST + JSONpublic APIs, simple
GraphQLmany clients, flexible data
gRPCfast service-to-service

Summary

REST is the default, GraphQL lets clients choose fields, and g RPC is fast between services. Next, how servers push updates to clients in real time.

Key takeaways
  • REST: default
  • GraphQL: flexible
  • gRPC: internal speed
Next up: Real-Time Updates — polling, WebSockets, SSE