API Architecture Styles

REST, GraphQL, gRPC, WebSockets, webhooks and SOAP — what each is for.

Beginner10 min read3 interview questions

An API style is the contract shape between a client and a server: how requests are expressed, how data is encoded and who starts the conversation.

Most systems use more than one. A public REST API for partners, gRPC between internal services, WebSockets for live updates and webhooks to notify other systems.

Diagram

ClientRESTresources over HTTP + JSONGraphQLclient picks the fieldsgRPCbinary, HTTP/2, contractsWebSockettwo-way, real-timeWebhookserver calls you backServer
Five common styles between a client and a server. Webhooks reverse the direction.

Key concepts

REST
Resources identified by URLs, manipulated with HTTP verbs. Cache-friendly and universally understood.
GraphQL
One endpoint; clients send a query describing exactly the data they need. Great for varied front ends.
gRPC
Protocol Buffers over HTTP/2 with generated clients. Fast and strongly typed — ideal service-to-service.
WebSocket
A persistent two-way connection. Used for chat, live dashboards, multiplayer games.
Webhook
The provider sends an HTTP POST to your URL when an event happens, e.g. a payment succeeded.
SOAP
XML envelopes with strict WSDL contracts. Still common in banking and enterprise integrations.

Trade-offs

Benefits

  • REST: simple, cacheable, every tool supports it
  • GraphQL: no over- or under-fetching
  • gRPC: low latency, streaming, typed contracts
  • WebSocket and webhooks: no polling

Costs

  • REST: chatty for complex screens
  • GraphQL: caching and query-cost control are harder
  • gRPC: not natively supported by browsers
  • WebSocket: stateful connections complicate scaling

Use it when

  • REST for public and partner APIs
  • GraphQL for mobile and web apps with many screens
  • gRPC for internal microservice calls
  • WebSocket or Server-Sent Events for live updates
  • Webhooks for event notifications between companies

Common mistakes

  • Unbounded GraphQL queries that join everything
  • Webhooks without signature verification or retries
  • Using WebSockets where simple polling every 30 seconds would do

Interview questions

Q1When would you choose gRPC over REST?
For internal service-to-service calls where low latency, streaming and strict contracts matter, and both sides can use generated clients.
Q2How do you make webhook receivers reliable?
Verify the signature, respond 2xx quickly and process asynchronously, store the event ID to ignore duplicates, and expect the sender to retry.
Q3What is over-fetching?
Receiving more data than the screen needs, e.g. a full user object to show a name. GraphQL and REST field selection (?fields=name) address it.