Post

API Communication Protocols: REST, GraphQL, gRPC, WebSocket and Beyond

What API and messaging protocols are, why there are so many, where each one came from, and a one-page summary of REST, GraphQL, gRPC, WebSocket, SSE, long polling, SOAP, webhooks, MQTT and AMQP with their use cases.

API Communication Protocols: REST, GraphQL, gRPC, WebSocket and Beyond

Every distributed system is a conversation between programs: a browser asking a server for a page, a phone asking for an order history, a microservice calling another, a sensor reporting a temperature, a payment provider telling a shop that a card was charged. The rules of those conversations are communication protocols and API styles. This post is the entry point to a series that explains the ones you meet most often: what they are, why each was invented and where each one fits.

This post is the hub of the API communication protocols series. Each protocol has its own deep dive, and the series ends with a side-by-side comparison.

Index

What a communication protocol is

A protocol is an agreement between two parties about:

  • Who speaks first, and whether the other side may speak without being asked.
  • How a message is framed: where one message ends and the next starts.
  • How data is encoded: JSON text, XML, or a binary format such as Protocol Buffers.
  • How operations are named: a URL plus an HTTP verb, a method name in a contract, a topic, a queue.
  • What happens on failure: status codes, faults, retries, acknowledgements, redelivery.
  • What the connection looks like: one request per connection, a long-lived connection, or a broker in the middle.

An API (Application Programming Interface) is the set of operations a system exposes to others. The protocol or style is how those operations are reached over a network. For the basics of APIs, see Introduction to APIs.

Protocol, API style or transport?

The names in this series sit at different layers, which is why comparisons such as “REST versus WebSocket” can be confusing. REST is an architectural style, gRPC is a framework, WebSocket is a transport-level protocol and AMQP is a messaging wire protocol. The diagram shows what each one is built on.

flowchart BT
    TCP["TCP"] --> TLS["TLS (optional)"]
    UDP["UDP"] --> QUIC["QUIC"]
    TLS --> H1["HTTP/1.1"]
    TLS --> H2["HTTP/2"]
    QUIC --> H3["HTTP/3"]
    H1 --> REST["REST"]
    H1 --> SOAP["SOAP"]
    H1 --> GQL["GraphQL"]
    H1 --> SSE["SSE and long polling"]
    H1 --> WH["Webhooks"]
    H2 --> REST
    H2 --> GQL
    H2 --> GRPC["gRPC"]
    H3 --> REST
    H1 -- "Upgrade handshake" --> WS["WebSocket"]
    TLS --> MQTT["MQTT"]
    TLS --> AMQP["AMQP"]
LayerExamplesWhat it decides
TransportTCP, UDP, QUICReliable byte stream or datagrams; see OSI and TCP/IP model and UDP
Application protocolHTTP/1.1, HTTP/2, HTTP/3, WebSocket, MQTT, AMQPFraming, connection lifetime, who may send when
API style or frameworkREST, GraphQL, gRPC, SOAPHow operations and data are modelled on top of the protocol
Integration patternWebhooks, long polling, SSEA way of using HTTP to get push or event behaviour

Why there are so many

No single protocol can be best at everything, because the requirements pull in opposite directions:

PressurePulls towards
Anyone must be able to call it (browsers, partners, curl)Plain HTTP and JSON: REST, webhooks
The client needs many related things in one round tripA query language: GraphQL
Millions of internal calls per second, many languagesBinary encoding and generated code: gRPC
The server must speak firstLong-lived connections: WebSocket, SSE, long polling
Formal contracts, signed messages, transactionsSOAP and WS-* standards
Tiny devices on bad networksA minimal binary pub/sub protocol: MQTT
Messages must never be lost, even if the consumer is downA broker with queues and acknowledgements: AMQP
The other system belongs to another companyCallbacks over public HTTP: webhooks

Each protocol in this series was created because the existing ones failed one of these pressures.

Where they came from

The history runs from document fetching, through enterprise RPC and messaging, to real-time push and contract-first APIs. Press play, or step through it:

  1. 1991, HTTP: Tim Berners-Lee's HTTP fetches documents with a request and a response. Almost every protocol in this series runs on it or starts from it.
  2. 1998, XML-RPC and SOAP: Enterprises want to call remote procedures across firewalls and languages, so they wrap calls in XML and send them over HTTP POST.
  3. 1999, MQTT: IBM and Arcom need a tiny publish/subscribe protocol for oil pipeline sensors on expensive, unreliable satellite links.
  4. 2000, REST: Roy Fielding's dissertation describes the architecture of the web itself, resources, URLs, verbs and caching, as a style for APIs.
  5. 2003, AMQP: JPMorgan Chase starts an open, interoperable wire protocol for reliable business messaging to replace proprietary middleware.
  6. 2006, Comet and SSE: Web apps like chat need server push. Long polling and streaming (Comet) work around HTTP, and Server-Sent Events standardise one-way streams.
  7. 2007, Webhooks: Jeff Lindsay names the pattern of user-defined HTTP callbacks, so services can notify each other instead of being polled.
  8. 2011, WebSocket: RFC 6455 gives browsers a real full-duplex connection, ending the Comet workarounds for chat, games and live data.
  9. 2015, gRPC: Google open-sources the successor of its internal Stubby RPC system, built on HTTP/2 and Protocol Buffers.
  10. 2015, GraphQL: Facebook open-sources the query language it built in 2012 for its mobile News Feed, to fetch nested data in one request.
  11. 2022, HTTP/3: HTTP moves onto QUIC over UDP (RFC 9114), removing TCP head-of-line blocking for every protocol that rides on HTTP.
YearProtocolOriginProblem it solved
1991HTTPTim Berners-Lee, CERNFetch hypertext documents across the internet
1998XML-RPC, then SOAPDave Winer (UserLand) with Microsoft; SOAP 1.2 became a W3C Recommendation in 2003Call remote procedures across languages and firewalls, unlike DCOM and CORBA
1999MQTTAndy Stanford-Clark (IBM) and Arlen Nipper (Arcom)Monitor oil pipelines over costly, unreliable satellite links
2000RESTRoy Fielding’s PhD dissertation, UC IrvineDescribe why the web scales, and apply those constraints to APIs
2003AMQPJohn O’Hara, JPMorgan Chase; AMQP 1.0 became an OASIS standard in 2012Replace proprietary, non-interoperable message-oriented middleware
2006Comet, long polling, SSEAlex Russell named Comet; SSE grew out of WHATWG work and shipped in Opera in 2006Push data to browsers that could only make requests
2007WebhooksTerm coined by Jeff LindsayLet services notify each other instead of being polled
2011WebSocketIETF RFC 6455A real two-way connection for browsers
2015gRPCGoogle, from its internal RPC system StubbyFast, typed, polyglot service-to-service calls
2015GraphQLFacebook (internal since 2012)Fetch nested data for mobile apps in one request
2015 / 2022HTTP/2, HTTP/3IETF RFC 7540 (now 9113), RFC 9114Multiplexing and, with QUIC, no TCP head-of-line blocking

The five communication patterns

Most of the differences between protocols come down to which of these patterns they support.

sequenceDiagram
    autonumber
    participant C as Client
    participant S as Server
    participant B as Broker
    Note over C,S: 1. Request and response (REST, GraphQL, gRPC unary, SOAP)
    C->>S: request
    S-->>C: response
    Note over C,S: 2. Server push on a held connection (SSE, long polling, GraphQL subscriptions)
    C->>S: subscribe once
    S-->>C: event
    S-->>C: event
    Note over C,S: 3. Full-duplex streaming (WebSocket, gRPC bidirectional)
    C->>S: message
    S->>C: message
    C->>S: message
    Note over C,S: 4. Callback (webhooks)
    S->>C: HTTP POST when something happens
    C-->>S: 2xx
    Note over C,B: 5. Publish and subscribe through a broker (MQTT, AMQP)
    C->>B: publish to a topic or exchange
    B->>S: deliver to every subscriber
PatternWho startsConnectionProtocols
Request/responseClient, every timeShort or reusedREST, GraphQL queries and mutations, gRPC unary, SOAP
Server pushClient subscribes, then the server sendsLong-lived, one directionSSE, long polling, GraphQL subscriptions
StreamingEither sideLong-lived, both directionsWebSocket, gRPC streaming
CallbackThe provider, on an eventShort, reversed rolesWebhooks
Publish/subscribePublisher; the broker deliversLong-lived, to a brokerMQTT, AMQP, also Kafka and NATS

The protocols in one paragraph each

REST

An architectural style that models data as resources with URLs and manipulates them with HTTP verbs (GET, POST, PUT, PATCH, DELETE). It uses HTTP status codes, headers and caching as they were designed, which makes it the default for public APIs. Its weakness is over-fetching and under-fetching: a screen that needs a user, their orders and their reviews may need three calls. Deep dive: REST API.

GraphQL

A query language and runtime where the client sends one query to a single endpoint and gets back exactly the fields it asked for, shaped like the query. A typed schema is mandatory and introspectable. Subscriptions add server push. The cost is moved to the server: resolver performance, N+1 queries, query cost limits and harder HTTP caching. Deep dive: GraphQL.

gRPC

A remote procedure call framework from Google. Services and messages are defined in a .proto file, code is generated for each language, payloads are binary Protocol Buffers and calls run over HTTP/2 with unary, client-streaming, server-streaming and bidirectional-streaming methods. Very fast and strictly typed, but not human-readable and not callable from browsers without gRPC-Web. Deep dive: gRPC.

WebSocket

A protocol (RFC 6455) that upgrades an HTTP connection into a persistent, full-duplex channel. Either side can send text or binary frames at any time with only a few bytes of overhead. Ideal for chat, games, trading screens and collaborative editing. You design your own message format, and stateful connections make load balancing and scaling harder. Deep dive: WebSocket.

Server-Sent Events and long polling

Two ways to get server push over plain HTTP. SSE keeps one HTTP response open and streams text/event-stream events to the browser’s EventSource, with automatic reconnection. Long polling holds each request until there is news, then the client immediately asks again. Both are simpler than WebSocket when data only needs to flow from server to client. SSE is how most LLM APIs stream tokens. Deep dive: SSE and long polling.

SOAP

An XML messaging protocol with a strict contract (WSDL), a standard envelope, standard faults and a family of WS-* standards for security, reliability and transactions. Verbose and heavyweight, yet still common in banking, insurance, telecom, government and older ERP integrations. Deep dive: SOAP.

Webhooks

User-defined HTTP callbacks. You register a URL, and the provider POSTs a signed event to it when something happens: a payment succeeded, a pull request was opened. Simple and firewall-friendly, but the receiver must verify signatures, return quickly and handle retries and duplicates. Deep dive: Webhooks.

MQTT

A lightweight publish/subscribe protocol for constrained devices and unreliable networks. Clients publish to hierarchical topics on a broker, subscribers use wildcards, and three Quality of Service levels trade overhead for delivery guarantees. Retained messages and the Last Will and Testament feature make it the standard protocol of IoT. Deep dive: MQTT.

AMQP

A wire protocol for reliable business messaging through a broker. In AMQP 0-9-1 (RabbitMQ), producers publish to exchanges, bindings route messages to queues and consumers acknowledge each message. Durable queues, acknowledgements, dead-lettering and publisher confirms let services communicate asynchronously without losing work. Deep dive: AMQP.

Summary table

 ModelTransportPayloadContractDirectionBrowser
RESTResources with URLs and HTTP verbsHTTP/1.1, 2 or 3Usually JSONOptional (OpenAPI)Request/responseNative
GraphQLClient-written query to one endpointHTTP (usually POST)JSONRequired schemaRequest/response plus subscriptionsNative
gRPCMethods on a service contractHTTP/2Protobuf (binary)Required .proto with codegenUnary and three streaming kindsNeeds gRPC-Web
WebSocketPersistent message channelTCP after an HTTP upgradeAny text or binaryNone built inFull duplexNative
SSEOne long HTTP response of eventsHTTPUTF-8 textEvent format onlyServer to clientNative (EventSource)
Long pollingHeld request, re-issuedHTTPAnyNoneServer to client, simulatedNative
SOAPOperations in an XML envelopeUsually HTTP POSTXMLRequired WSDLRequest/responsePossible, rarely done
WebhooksProvider calls your URLHTTP POSTUsually JSONProvider’s event docsServer to server, event-drivenNot applicable
MQTTPublish/subscribe on topicsTCP (or WebSocket)Any bytesNone (topics by convention)Pub/sub through a brokerOver WebSocket
AMQPExchanges, bindings and queuesTCPAny bytes plus propertiesNone (by convention)Pub/sub and work queuesNot directly

Which protocol for which use case

Use caseFirst choiceWhyAlternatives
Public API for third partiesRESTUniversal tooling, HTTP caching, easy to debugGraphQL for data-rich platforms
Mobile or SPA screen with nested dataGraphQL (often in a BFF)One round trip, no over-fetchingREST with aggregation endpoints
Internal microservice callsgRPCLow latency, typed contracts, streamingREST, or AMQP when async
Chat, multiplayer games, collaborative editingWebSocketLow-latency two-way messagesWebTransport, WebRTC data channels
Live notifications, progress bars, LLM token streamsSSEOne-way push over plain HTTPWebSocket, long polling
Clients behind restrictive proxiesLong pollingLooks like ordinary requestsSSE
Banking, insurance, government integrationsSOAPExisting WSDL contracts, WS-SecurityREST for new APIs
“Tell me when X happens” between companiesWebhooksNo polling, works across organisationsSSE or a shared queue
Sensors, vehicles, smart homeMQTTTiny overhead, QoS, offline handlingCoAP, AMQP
Order processing, background jobs, decoupled servicesAMQPDurable queues, acks, routing, retriesKafka for event streams, cloud queues

These protocols are rarely used alone. A typical system uses REST or GraphQL at the edge, gRPC between services, a broker for asynchronous work, webhooks with partners and WebSocket or SSE for live updates. The comparison post follows one order through all of them.

Beyond this series

ProtocolWhat it isWhen you meet it
JSON-RPC 2.0A minimal RPC envelope in JSONEthereum nodes, the Language Server Protocol, the Model Context Protocol (MCP)
tRPCEnd-to-end typed RPC for TypeScript monoreposNext.js and other TypeScript full-stack apps
WebRTCPeer-to-peer audio, video and data channels over UDPVideo calls, screen sharing
WebTransportMultiplexed streams and datagrams over HTTP/3A successor candidate to WebSocket
Kafka protocolA binary protocol for a distributed, replayable logEvent streaming and data pipelines
STOMPA simple text messaging protocol, often over WebSocketSpring and RabbitMQ web messaging
CoAPA REST-like protocol over UDP for tiny devicesConstrained IoT, alongside MQTT
ODataREST conventions for queryable dataMicrosoft Dynamics, SAP

Two specifications describe these APIs: OpenAPI for request/response HTTP APIs, and AsyncAPI for event-driven ones such as WebSocket, MQTT, AMQP and Kafka.

Reading order

  1. REST API: the baseline everything else is compared to
  2. GraphQL: client-driven queries
  3. gRPC: contract-first RPC between services
  4. SOAP: the enterprise XML ancestor
  5. WebSocket: full-duplex real time
  6. Server-Sent Events and long polling: push over plain HTTP
  7. Webhooks: event callbacks between systems
  8. MQTT: publish/subscribe for IoT
  9. AMQP: reliable messaging with brokers
  10. Comparison of all protocols: the differences, side by side

Related: API Security and Common Protocols and Ports.

This post is licensed under CC BY 4.0 by the author.