Request-response, streaming and event-driven: the main ways APIs talk.
An API style is the pattern of conversation between two programs. The main patterns are request-response, streaming and event-driven.
There are two different ideas, and people mix them up. Keep them apart:
Choosing the wrong pattern costs speed, money and happiness.
| Pattern | Use it for | Examples |
|---|---|---|
| Request-response | Reading and changing data on demand | Open a profile, place an order, search products |
| Streaming | Live data that keeps coming | Chat, live scores, stock prices, video upload, logs |
| Event-driven | Tell others when something happened | Payment done, order shipped, code pushed |
The client sends a request and waits. The server sends one response. Then it is finished. This is how most web pages and REST APIs work.
Sync vs async: a call can be synchronous (the client waits) or asynchronous (the server says “accepted, check later”, usually with status 202 and a job id).
One connection stays open and carries many messages. There are three shapes:
Instead of asking, the client subscribes or registers an address. When an event happens, the server sends a message.
If you cannot get a push, you can poll: ask again on a timer. It is simple but wasteful. Long polling improves it: the server holds the request open until it has news. See the Real-Time topics later.
SOAP is an older request-response style that sends XML messages with strict rules. You still see it in banks, insurance and old enterprise systems. New public APIs rarely choose it.
| Question | Request-response | Streaming | Event-driven |
|---|---|---|---|
| Who starts each message? | Client | Server (after open) | Server |
| Connection | Short | Long, stays open | Short call-back |
| Latency for news | As late as the next poll | Instant | Instant |
| Server cost per client | Low | Higher (open connections) | Low |
| Ease to build | Easiest | Medium | Medium |
| Term | Meaning in easy words |
|---|---|
| Request-response | One request gets one response, then the exchange is over |
| Synchronous | The caller waits for the answer before doing anything else |
| Asynchronous | The caller does not wait; the answer comes later or through another channel |
| Streaming | Many messages travel over one open connection |
| Polling | Asking again and again on a timer to check for news |
| Push | The server sends data without being asked each time |
| Event | A fact that happened, like “order paid” |
| Webhook | An address you give so the other system can call you when an event happens |
| Bidirectional | Both sides can send messages at any time |
| 202 Accepted | A status code meaning “I got your request and will work on it” |
| Pattern | Pros | Cons |
|---|---|---|
| Request-response | Simple, easy to cache, test and retry, works everywhere | Slow for live data (needs polling), one answer per call |
| Streaming | Instant updates, fewer wasted calls | Open connections cost memory, harder to scale, reconnect logic needed |
| Event-driven | Systems are loosely joined, instant news, scales well with queues | Harder to debug, events can be lost, repeated or arrive out of order |