Choosing a Protocol
Definition
Protocol
- In plain English
- A protocol is an agreed set of rules for how two programs exchange messages.
- Think of it like
- It is like the rules of a card game that everyone at the table agrees to.
Trade-off
- In plain English
- A trade-off is a choice where gaining one benefit means giving up another.
- Think of it like
- It is like paying more for a faster train.
Why it exists
A daily update rarely needs a connection that stays open. For 50,000 internal calls per second, test a compact format. Choose tools that solve the actual communication problem.
Choose for each connection. A single product can use one protocol for public requests and another for frequent internal calls.
How it works
- Identify the caller
Check whether it is a browser, partner, device or internal service.
- Trace direction
Decide whether updates arrive without a new request and whether replies flow back frequently.
- Set a delay budget
Decide how much update delay users accept before choosing connections that stay open.
Without push, use REST for browsers or partners, or consider gRPC for heavy internal traffic. With updates, consider WebSocket for frequent two-way messages, SSE for frequent one-way messages, and polling for rare changes.
| Option | Direction | Format | Browser support | Scaling work | Typical use |
|---|---|---|---|---|---|
| REST | Request and response | Often JSON | Native HTTP | Less work when requests stand alone | Public and partner APIs |
| gRPC | Unary or streaming | Usually Protocol Buffers | Extra browser tools | Varies with streaming | Internal typed calls |
| SSE | Server to client | UTF-8 event text | Native EventSource | Keep streams open | Live scores and queues |
| WebSocket | Two-way | Text or binary | Native WebSocket | Connections and routing | Interactive live screens |
Examples
Mix protocols for esports fans
An esports scoreboard serves fans and receives statistics from game servers.
Fans receive scores over SSE and fetch match history through REST. Game servers report statistics to the backend over gRPC. Each path has a different caller and message pattern.
The fan browser requests history from the backend over REST, and the backend sends scores over SSE. Game servers send statistics to the backend over gRPC.
The insight
Pick per connection, not per system.
Support an interactive triage board
Nurses claim patients on a live triage board and also read patient records.
Nurses claim patients and receive urgent updates over WebSocket. REST serves patient records. Internal lab and triage services use gRPC. Check permissions and record each result regardless of protocol.
The nurse tablet exchanges board updates with triage over WebSocket and requests records over REST. The lab sends gRPC messages to triage.
The insight
Two-way, urgent flows justify WebSockets.
Reach chargers behind site routers
Chargers connect outward through a site router while drivers use a mobile app.
OCPP defines messages between chargers and management services. Versions 1.6J and 2.x use WebSockets for commands over charger-started connections. Version 1.6 also supports another message format.
Use REST for driver reservations and history, and gRPC for internal billing. Plan charger reconnection and replies confirming each command.
The insight
Hardware behind routers often needs the device to open the connection.
Trade-offs
Pros
- Match each path to its needs.
- Keep contracts appropriate to callers.
Cons
- Maintain more tooling.
- Monitor several connection patterns.
Use when
- Communication needs differ by path.
- The team can operate added protocols.
Avoid when
- A small team is validating a product.
- REST meets measured requirements.
Quick check
Takeaways
- Choose per connection.
- Ask: who speaks first, how often, and who is calling.
- Start with REST; add another protocol for a measured need.