Skip to content

APIs and communication: recap and quiz

  1. REST and HTTP APIs. An HTTP API names resources, keeps no conversation between requests, and relies on the meaning of each method: GET, PUT and DELETE are idempotent and POST is not, so only the first three may be repeated after a timeout.
  2. RPC and gRPC. An RPC makes a remote call look local, and gRPC adds a contract, four kinds of call on HTTP/2 and deadlines, which have to be passed down the chain as the time that is left.
  3. Polling and long polling. A client that cannot be called has to ask: short polling asks every interval and mostly gets empty answers, long polling holds the request until there is news.
  4. Server-sent events and WebSockets. Server-sent events stream updates one way over a response that does not end and resume with Last-Event-ID; a WebSocket upgrades the connection so that both sides can send.
  5. Webhooks. A provider calls your endpoint when something happens: verify the signature on the raw body, answer 2xx first, and expect repeats and disorder.
  6. Synchronous or asynchronous. Wait when the next step needs the answer, hand over when it does not, and remember that every call you wait for takes a little availability.
Idea What breaks What you see What helps
HTTP API A POST is repeated after a timeout Two orders, two charges An idempotency key, or a PUT to a client-chosen address
Remote call No deadline, or a fresh one at each hop Calls pile up behind one slow service A deadline set by the client and passed on as the time left
Polling Many clients, a short interval Thousands of empty requests a second A longer interval, or long polling
Open channel A dropped connection Missed updates Event ids and Last-Event-ID, or ids of your own on a WebSocket
Webhook A slow handler, a repeat, a forged request Retries, double effects, false events Verify the signature, answer first, record the event ids
Waiting chain Several services in a row Availability and speed fall with each one Hand over what can wait, and copy the data you need

What the flow measured, and what it did not

Section titled “What the flow measured, and what it did not”

The message flow of lessons 3 and 4 gave the time for two updates, at a round-trip time of 80 ms and a polling interval of 1 s: 2.2 s for short polling with 6 messages, 160 ms for long polling with 4, and 120 ms for server-sent events and for a WebSocket, with 3 each. These are floors set by round trips and by the interval. They do not include the server’s work, the headers, or the cost of holding a connection for each client, so they say which technique is faster in the best case, not what a real system will measure.

Each question points back to the lesson that answers it.

  1. Does the caller need the answer to go on? If so, call and wait, with a deadline. If not, hand it over. (Synchronous or asynchronous)
  2. Is it a resource that is read and changed, or an action? Methods and resources, or a contract with calls. (REST and HTTP APIs, RPC and gRPC)
  3. May the call be repeated? GET, PUT and DELETE may; for a POST or an action, add a key. (REST and HTTP APIs)
  4. What deadline does the client set, and does each hop pass on the time that is left? (RPC and gRPC)
  5. How does a client with no open connection hear about news? Poll, hold the request, or open a channel. (Polling and long polling)
  6. Does the data flow one way or both ways, and what happens to updates missed during a drop? (Server-sent events and WebSockets)
  7. If a provider calls you, do you check the signature, answer first and ignore repeated event ids? (Webhooks)
  8. What does a request through several services cost in availability, and which waits can become hand-overs? (Synchronous or asynchronous)

Nine questions cover the whole module. Every option is explained, whether it is right or wrong.

APIs and communication: module quiz

This quiz needs JavaScript to check your answers.

Question 1 of 9

20,000 browsers each ask a server for updates every 4 seconds with short polling.

How many requests per second does the server receive, whether or not there is anything new?

Enter a number and choose its unit.

requests a second
Question 2 of 9

A client needs to hear about a new event soon after it happens. The only thing it can do is send HTTP requests.

What does long polling change compared with short polling?

Choose one answer.

Question 3 of 9

Which of these methods does RFC 9110 define as idempotent?

Choose every answer that applies.

Question 4 of 9

A gRPC call fails with an application error. A trace of the HTTP/2 exchange shows that the response status is 200.

Where is the gRPC status?

Choose one answer.

Question 5 of 9

A client calls service A with a deadline of 800 ms. A works for 150 ms and calls B. B works for 250 ms and calls C.

How much time does C have, if the deadline is passed on?

Enter a number and choose its unit.

ms
Question 6 of 9

A browser dashboard shows a live feed. The server sends updates and the page never sends anything back except its first request.

Which channel fits best?

Choose one answer.

Question 7 of 9

A client uses long polling. The round-trip time is 200 ms, the server needs no time to prepare an answer, and two updates are waiting: the second one is ready as soon as the client has received the first.

At the least, how long after the first long poll does the client have both updates?

Enter a number and choose its unit.

ms
Question 8 of 9

A provider sends a webhook for a payment and retries it if it does not get a 2xx. A receiver that answers 200 only after it has booked the payment is sometimes told the same event twice.

Which change makes the receiver correct?

Choose one answer.

Question 9 of 9

A checkout request calls three services one after the other and fails if any of them fails. Each service is available 99.9% of the time, and they fail independently.

What share of checkout requests succeeds?

Enter a number and choose its unit.

%

The next modules build on these choices. Rate limiting decides how many requests an API accepts before it refuses, and a refusal is one more answer a client has to handle. Observability shows what the calls between services did, and security covers who is allowed to make them. The question to bring with you is the one from this module: who waits for whom, and what happens when the other side does not answer.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.