Machine Room

Machine Room · 1 Nov 2026 · 10:40

What Is an API? REST, Webhooks, WebSockets, GraphQL and gRPC Explained

Watch on YouTube

REST, webhooks, server-sent events (SSE), WebSockets, GraphQL and gRPC are the six API styles behind almost every app, and each one exists because the one before it broke on a specific job. This episode climbs them as seven levels on one food delivery app: REST endpoints (GET, POST, DELETE) on day one, a Stripe webhook instead of polling for the payment, SSE to stream the rider's position, a WebSocket for the chat between the customer and the rider, one GraphQL query for a home screen that needed four REST calls (over-fetching and under-fetching), and gRPC with Protocol Buffers over HTTP/2 for the calls between services inside the backend. Level seven, the boss level, is one order that uses all six at once.

This episode with chapters, full transcript and sources: https://themachineroom.dev/v/levels-of-api/?utm_source=youtube&utm_medium=description&utm_campaign=levels-of-api

Chapters

  1. 0:00The 7 Levels: one food delivery app grows up
  2. 0:21Level 1, REST: endpoints, JSON and polling
  3. 1:57Level 2, Webhooks: Stripe calls our server
  4. 2:56Level 3, Server-Sent Events: live rider tracking
  5. 3:58Level 4, WebSockets: one connection, both ways
  6. 5:12Level 5, GraphQL: over-fetching and under-fetching
  7. 7:00Level 6, gRPC: Protocol Buffers between services
  8. 9:10Level 7, The Boss Level: one order, all six APIs

Notes

the food delivery app, Leo and every order count are a made-up example; no real app is pictured. The 70-byte vs 21-byte order message (JSON vs protobuf) is our own measurement of one hand-encoded message. A GraphQL server usually lives at one address such as /graphql; that is a convention, not part of the spec. Stripe retries a webhook delivery for up to three days. ChatGPT and Claude stream their answers over SSE; Discord, Slack (Socket Mode) and Figma use WebSockets; Netflix moved its service-to-service calls to gRPC.

Sources

Get the next one by email

One email per video, with the sources. No newsletter padding, no selling the list. Leave any time.

Transcript

The narration, word for word, from the subtitle file that ships with the video.

0:00The 7 Levels: one food delivery app grows up

The seven levels of API. Watch one food delivery app grow up, from day one to Friday night. Every time it gets bigger, something breaks, there's a new challenge to solve, and the next level is what fixes it.

0:21Level 1, REST: endpoints, JSON and polling

Level one is REST. Right now, our app is just one server, one database and one page of restaurants. The app asks and the server answers. There's an endpoint for everything you want to do: a GET on restaurants returns the list, a POST on orders places an order, and a DELETE on an order cancels it. Call the endpoint, get JSON back. That's REST, and it runs most of the web. Leo orders a burger. Now, people pay in the app, so we have to integrate a payment gateway. There are many we could use, and we go with Stripe. Leo pays. Stripe takes the card and confirms the payment on its side, and that takes time. Here's the problem with REST. We have to call Stripe every time we want data, and the communication is one way. Our server can talk to Stripe, but Stripe can't talk back to our server. So our server asks Stripe every two seconds: is the payment done? And the answer keeps coming back no. That's polling. And it's not the right way, because almost every call comes back with nothing. Now do that for forty orders an hour, and it's hell. Stripe's own docs say polling is less reliable and can hit your rate limits. It'd be better if Stripe could talk back to our server. No polling, and no thousand calls an hour to Stripe's server. And there's a way.

1:57Level 2, Webhooks: Stripe calls our server

Level two is webhooks. A webhook flips the direction. Instead of our server calling Stripe, Stripe calls our server. We give it our payments endpoint and tell it to call that whenever a payment succeeds. This time, when Leo pays, Stripe confirms the payment, and the moment it does, it sends one POST to our endpoint: payment succeeded, Leo's order, eighteen dollars. We get that call, mark Leo's order paid in our system, and the order is confirmed. One call, when it happens, and we never ask again. And if our server is down for a minute, Stripe keeps retrying, for up to three days. Same forty orders an hour, and now nobody is polling anyone. Now we have to build live delivery tracking, so Leo can watch the rider move on the map.

2:56Level 3, Server-Sent Events: live rider tracking

Level three is server-sent events. The rider's position changes every few seconds. Leo's phone can't keep asking for it, that's polling again. And our server can't call Leo's phone, it has no endpoint. So Leo's phone opens one connection and keeps it open. Every time the rider moves, the server pushes the new position down that same connection. That's server-sent events, or SSE for short. The rider's phone sends its location to our server, and as soon as it arrives, it goes straight down to Leo's phone. The server talks, the phone listens. Most AI chatbots do this, ChatGPT and Claude included. The connection opens once, and the model sends each token down it the moment it's generated. Now Leo wants to message the rider, and the rider has to be able to answer.

3:58Level 4, WebSockets: one connection, both ways

Level four is WebSockets. Leo types "I'm at the back gate" and sends it to the rider, and the rider types back "two minutes". Our connection to Leo is one way. The server can push to his phone, but his phone can't send anything up it. His message has to go as a separate POST, and the rider's reply comes down the stream. That's two paths for one conversation, and it gets messy fast. A WebSocket is one connection that goes both ways. Leo's phone opens it once, and after that Leo can send and the rider can send, at any moment, on the same connection. That's what chat runs on. When you open Discord, it holds one WebSocket to Discord's servers, and every message in every channel arrives over that one connection. Slack apps connect the same way. Leo sends, the rider answers, and the chat runs on the WebSocket. The map still streams over server-sent events, exactly as before. Now the app has grown, and the first screen Leo sees is slow to load.

5:12Level 5, GraphQL: over-fetching and under-fetching

Level five is GraphQL. Leo opens the app, and the home screen needs four things: nearby restaurants, today's offers, ratings and delivery time. In REST that's four endpoints, so the phone makes four calls, one after another, and the screen waits for all four. And each call brings back everything that endpoint has. The restaurant endpoint returns forty fields, and the screen uses one of them: the name. That's over-fetching. Needing four calls for one screen is under-fetching, and REST does both at once. We could add a special endpoint for the home screen, then one for the search screen, one for the cart and one for the order page. Twelve screens, twelve custom endpoints, and the iOS and Android teams each want them slightly different. GraphQL turns it around. There's one endpoint, and the app sends a query that says the shape it wants: restaurants near me, with name, rating and delivery time, plus today's offers. The server answers with exactly that, in one trip. Nothing extra, nothing missing. The caller decides what it gets, not the server. Facebook built it in 2012 for the same reason: its mobile news feed was too many round trips over REST. Then comes Friday night, and orders go from two thousand an hour to ten thousand. Our one backend has grown into twelve services, like orders, restaurants, riders, payments, pricing and search, and they talk to each other more than they talk to the phone.

7:00Level 6, gRPC: Protocol Buffers between services

Level six is gRPC. Leo places one order, and inside our backend that one order is a chain of calls. Orders asks pricing, pricing asks offers, then orders asks payments and riders. Every order is a dozen calls between our own services. Every one of those calls is REST. So every service writes the message out as JSON text, sends it, and the other side reads the text back into an object. A phone making a few calls a minute, nobody notices. Our services make over a hundred thousand calls an hour to each other, and every one of them pays for that text twice: once to write it, once to read it back. gRPC starts with a contract. One file, order dot proto, says exactly what an order looks like: id, item, quantity, paid, amount. Both sides generate their code from that file, so calling the payments service looks like calling a function. And the message doesn't travel as text. It travels as protocol buffers, protobuf for short. JSON spells out every field name, in quotes, every single time. Protobuf already knows the fields from the contract, so it sends just a field number and the raw bytes of the value. No names, no quotes, no braces. Leo's order is seventy bytes as JSON and twenty-one bytes as protobuf. And it runs over HTTP two, which lets many calls share one open connection at the same time, instead of opening one connection per call. Google released it in 2015, built from the system its own services run on. Netflix moved nearly all of its service-to-service calls onto it. Twelve services, one contract, binary between them. Friday night holds.

9:10Level 7, The Boss Level: one order, all six APIs

Level seven is the boss level, and there's no new type. It's one order, using all six at once. Leo opens the app, and one GraphQL query draws the home screen: restaurants near him, offers, ratings and delivery time. He taps a restaurant, and its menu loads with one GET. Plain REST. He pays, Stripe confirms the card and calls our webhook, and the order is marked paid. Inside the backend, the orders service calls the restaurant service and the rider service over gRPC, in protobuf, and a rider is assigned. The rider's position streams to Leo's phone over server-sent events, and the dot moves. Leo types "I'm at the back gate". It goes to the rider over the WebSocket, and the reply comes back the same way. Six kinds of API, one burger. Big apps end up here. Most apps never need to. Every level in this video was added because something broke, or because the app needed something the level before couldn't do. Start at REST, and climb when something breaks or is needed. Which level is your app on? Tell me in the comments. And if this helped, subscribe.