Designing a web application "with protocols" means treating protocols as the structure of the system, not an afterthought wired in at the end. In practice, you pick a transport and application protocol (HTTP/1.1, HTTP/2, or HTTP/3 over QUIC), a request style on top of it (REST-style HTTP semantics, GraphQL, gRPC, or asynchronous messaging), a session and identity mechanism, and a data-consistency contract. Each choice fixes what you can change later without breaking clients. The key condition: protocol decisions must be explicit, versioned, and tested, because they outlive frameworks and often outlive the people who chose them.

That framing is the whole job. Once protocols are a design artifact — documented, versioned, and reusable by different clients — the rest of the architecture gets easier to reason about.

Start by naming the protocols you're already using

Most web applications involve more protocols than the team can list. A single page typically uses DNS, TCP, TLS, HTTP, and HTTP's own semantics (methods, status codes, caching headers), plus cookies or bearer tokens for identity. A mobile client adds background networking rules; a service backend adds a queue protocol, cache protocols, and connection pooling.

The first design step is an inventory. Write down, for each direction of communication:

Who initiates (browser, mobile app, server-to-server service, scheduled job). What the payload looks like (JSON, binary, form, stream). Whether the conversation is one request/one response or continues over time (streaming, subscriptions, long polling). Whether the connection must survive across requests, and for how long. What must happen when a message is delivered twice, dropped, or reordered.

That inventory prevents the common failure where a team discovers mid-build that their chosen style can't express streaming progress, client cancellation, or offline retry.

A practical rule: pick protocols that match the shape of the interaction, not the shape of the current feature list. Fire-and-forget notifications and interactive queries have genuinely different needs, and a design that treats them as the same thing usually ends up with one of them badly served.

Choose a foundation: HTTP versions as transport and shape

HTTP remains the default application protocol for web clients because everyone speaks it: browsers, proxies, CDNs, API gateways, mobile runtimes, and load balancers. The version matters mostly for transport behavior.

HTTP/1.1 is text-based and simple to debug, but it allows limited concurrency per connection (one request at a time in the common case), which encourages many connections and head-of-line blocking at the connection level. HTTP/2 multiplexes multiple streams over one connection, so many small requests become cheap. HTTP/3 runs over QUIC (UDP-based) and avoids TCP-level head-of-line blocking; it's the option most sensitive to network conditions, so availability of intermediaries matters.

The design consequence: if your clients issue dozens of small API calls per screen, HTTP/2 or HTTP/3 removes much of the pressure to "bundle everything into one call" — but the calls still exist, so API shape and payload size still govern latency. Multiplexing fixes connection overhead; it doesn't fix a bad API.

Two transport-level details worth deciding early:

1: Serialization. JSON is debuggable and universally supported; binary formats such as Protocol Buffers or CBOR are smaller and schema-enforced. gRPC uses HTTP/2 frames plus Protocol Buffers and shines for service-to-service calls, but browser support requires a proxy that translates to a gRPC-Web-compatible shape. Mixed estates are normal: gRPC internally, JSON over HTTP at the public edge. 2: Streaming direction. Server-Sent Events push text events over a long-lived HTTP response; WebSockets provide a full-duplex frame protocol after an HTTP upgrade. Server-Sent Events is the simpler choice when the data flows one way; WebSockets fit genuinely interactive, bidirectional sessions such as collaborative editing. Both need explicit reconnect and backoff logic, and both interact badly with naive proxy timeouts.

Pick the smallest mechanism that expresses the interaction. A design that reaches for WebSockets before confirming a one-way push is needed usually pays for state management it never needed.

Match request style to the interaction

The protocol question most teams actually argue about is request style. The fair comparison is on equivalent criteria: what each style guarantees about caching, failure, and evolution, not which is trendier.

Criterion REST-style HTTP semantics GraphQL gRPC (service-to-service) Asynchronous messaging
Typical transport HTTP/1.1–3, JSON HTTP POST, JSON HTTP/2, Protocol Buffers Broker protocol (e.g., AMQP, Kafka protocol)
Caching Strong via HTTP headers, CDNs Weak by default; needs persisted queries or caching layers Not HTTP-cacheable N/A
Payload shape Server-defined resources Client-defined selection Schema-defined methods Event-defined
Evolution Versioning by URL/header/media type Schema evolution with deprecation of fields Schema-based, strict field rules Schema/event versioning
Coupling Moderate; clients know resources Low query coupling, high schema coupling High: generated stubs Low temporal coupling, higher operational cost
Failure model Per-request status codes Per-request, but partial errors possible Status codes plus deadlines Retries, dead-letter handling

REST-style semantics over HTTP are the lowest-friction default: they reuse caching, conditional requests, content negotiation, and status codes that every intermediary understands. GraphQL reduces over- and under-fetching for clients whose data needs vary widely, at the cost of HTTP caching and of queries that need cost limits and complexity analysis. gRPC is efficient and contract-strict for internal calls but awkward at the browser edge. Message brokers fit work that must survive spikes or that fans out to multiple consumers.

A common, defensible pattern: REST-style HTTP for public and browser-facing endpoints, gRPC for high-volume internal service calls where schemas are already managed, and a broker for background work like sending email, generating reports, or processing uploads. The protocols differ because the interactions differ, and the architecture documents why.

Identity, state, and where sessions live

Authentication and session protocols deserve a dedicated decision because changing them later breaks all clients at once.

The core options are bearer tokens (opaque or structured, sent per request), cookies with session identifiers, and mutual TLS for service-to-service calls. For browser apps, HttpOnly, Secure cookies with appropriate SameSite settings remain the safer default for session identifiers, because they aren't readable by page scripts. Bearer tokens in JavaScript-reachable storage widen the impact of cross-site scripting.

Two protocol-level details that cause real failures:

Token lifetime and refresh. Short-lived access tokens with a refresh flow limit damage from theft, but the refresh step itself needs a defined protocol: rotation, reuse detection, and revoke-on-logout. Without that, refresh turns into a long-lived credential in disguise. State across instances. If session state lives in application memory, horizontal scaling breaks. Put sessions in a shared store with a defined eviction policy, or make tokens stateless with a revocation list whose protocol is documented.

Cross-service identity adds another layer: how one service proves who is calling it. A common approach is short-lived signed tokens with narrow scopes and audience claims, validated at each service rather than trusted blindly. Whatever the mechanism, write down the trust boundary: which services validate tokens themselves and which rely on a gateway.

Contracts, versions, and evolution

A protocol is a contract between parties that deploy independently. That makes versioning a design activity, not a release chore.

Three practices carry most of the weight:

1: Define the contract in a machine-readable form. OpenAPI for HTTP APIs, a schema file for Protocol Buffers or GraphQL, and an event schema for messages. The contract artifact is what clients generate from, what tests assert against, and what compatibility is measured on. 2: Choose an evolution rule and test it. Adding an optional field is usually backward compatible; renaming one, changing its type, or changing a status code from 200 to 400 is not. Establish a rule such as "additive changes only within a major version," then enforce it with a compatibility checker in continuous integration. 3: Keep old versions alive for a known period. Deciding a deprecation window and announcing it is a protocol decision. Without a stated window, clients stay on old versions indefinitely and every later change becomes a breaking change.

A concrete example: an endpoint returns {"status": "shipped"}. If a client later needs the shipping date, adding "shipped_at" is additive and safe. Replacing "status" with a nested object is not. The rule predicts which change requires a new version and which doesn't.

The same discipline applies to events. Consumers that have already read an old event schema will see new events in production, so event evolution rules must be documented alongside the event definition, including how unknown fields should be handled by consumers.

Error handling and idempotency as protocol behavior

How failures are expressed is part of the protocol, and it's the part clients interact with when things are worst.

For HTTP APIs, use status codes as specified rather than inventing a parallel system: 4xx for client-side problems, 5xx for server problems, 429 with retry information for rate limits, and 409 or 412 for conflicts and precondition failures. Pair codes with a stable error body that has a machine-readable code and a human-readable message.

For operations that change state, define idempotency explicitly. A retried "charge card" request must not charge twice; a retried "create order" must not create duplicates. The common approach is a client-supplied idempotency key, stored with the result and returned on repeats. That key is protocol surface: clients need to know to send it and what happens when they reuse it with different payloads.

Retries themselves need boundaries. Retrying is safe for idempotent operations and dangerous for others; exponential backoff with jitter and a maximum attempt count prevents synchronized retry storms. A retry policy stated in the API documentation is more valuable than any generic advice, because generic advice is what clients already have.

A success check for this section: a client that loses a response mid-request should be able to retry safely, and a test should demonstrate it. If the test would double-charge, the protocol isn't finished.

Worked estimate: where protocol choices show up in latency

Protocol decisions are often argued in absolute terms, so a small calculation helps. Consider a screen that makes 40 small API calls, each with a 40 ms server processing time, on a connection with a 60 ms round-trip time. Suppose TLS is already established unless stated.

HTTP/1.1 with limited per-connection concurrency forces additional connections. If six connections are used, the wall-clock time is dominated by round trips per batch: roughly 7 batches × 60 ms of round-trip overhead plus processing. That's about 420 ms of network overhead before the 40 ms per call is fully overlapped. HTTP/2 multiplexing sends all 40 requests over one connection: one round trip for the batch, so approximately 60 ms of overhead, with processing overlapping across streams. Call it roughly 90–120 ms in a favorable case. Bundling the 40 calls into 3 broader calls reduces overhead to about one round trip plus the serialized work the server does for each bundle.

The numbers are illustrative, and the point is the ratio: the protocol and API shape change the overhead from hundreds of milliseconds to tens of milliseconds, while the processing time stays the same. Real systems add connection setup, cold starts, and congestion, so measure rather than assume. The estimate's purpose is to show which levers matter: reducing round trips, enabling multiplexing, and shaping endpoints so clients need fewer calls.

Testing and documenting the protocol layer

Protocols need tests that assert contract behavior, separate from tests that assert business behavior.

Useful checks:

Contract tests. Validate responses against the OpenAPI or schema artifact. Fail the build when a change breaks compatibility. Error-path tests. Force 4xx and 5xx responses and confirm clients handle them, including retry and idempotency behavior. Version behavior tests. Run old and new client versions against the new server version to confirm the stated compatibility window. Transport tests. Verify that streaming, cancellation, and long-lived connections behave through the actual proxy or gateway configuration in staging, not only against the app server.

Documentation should state the protocol facts clients need: which HTTP versions are supported, which headers matter, which idempotency keys are required, how errors are shaped, and the deprecation window for versions. That document is more durable than framework documentation because it describes commitments, not implementation.

Where protocol design goes wrong

A few failure modes recur, and naming them makes them easier to avoid.

Choosing a style for internal convenience and exposing it publicly. gRPC across a browser edge, or a GraphQL endpoint with no query cost limits, works until the clients you don't control arrive.

Assuming the gateway preserves everything. Proxies and CDNs often buffer, rewrite, or time out in ways that break streaming and long polling. Test through the real path.

Treating versioning as a naming convention. Putting /v2/ in a URL without a compatibility rule and a deprecation window doesn't version anything; it just adds a path segment.

Hiding state in connections. Any design that depends on an in-memory session or a sticky connection breaks on redeploy or scaling. If the protocol requires connection affinity, say so and engineer for it.

Inventing a parallel error scheme. Clients, libraries, and monitoring tools understand HTTP status codes; a bespoke error taxonomy usually means retries and alerts misbehave.

Skipping the idempotency decision. The gap surfaces as duplicate records or double charges in production, typically during an incident when retries spike.

A practical sequence for designing one

With the reasoning in place, a workable order of operations looks like this. Prerequisites: a written inventory of client types, the interaction shapes from the first section, and the deployment topology, since gateways and CDNs constrain what protocols can pass through.

1: List every client and its interaction shapes. Classify each as request/response, one-way push, bidirectional, or background work. 2: Pick the transport and application protocol for each interaction group: HTTP version at the public edge, gRPC or broker internally where the interaction fits. 3: Define the contract artifact for each group, then write the evolution rule (additive-only within a major version) and the deprecation window. 4: Specify identity and session behavior, including token lifetime, refresh, revocation, and the trust boundary between services. 5: Specify error shapes, status code usage, retry policy, and idempotency keys for state-changing operations. 6: Write protocol tests: contract validation, error paths, version compatibility, and a run through the real proxy in staging. 7: Publish the protocol document and record the decisions that would otherwise be rediscovered in an incident.

Success check: a new client team can build against the document without asking the server team questions, and a compatibility test fails the build when someone breaks the rule. Stop condition: if the protocol needs to satisfy both a strict regulatory audit requirement and an adversarial public client at the same time, get a security or compliance review before implementation rather than after; the design may need separate enforcement layers, and that's outside what a design document alone can settle.

A design that treats protocols as durable commitments gets cheaper to change over time. Each client integration is a small, bounded negotiation against a documented contract, and the architecture stops being a pile of endpoints that everyone is afraid to touch.

FAQ

Does using HTTP/2 or HTTP/3 mean I don't need to worry about API shape?

No. Multiplexing reduces connection-level overhead, but each call still carries headers, payload, and server work. Fewer, well-shaped calls usually beat many small ones regardless of version.

Is GraphQL the right choice if clients have widely varying data needs?

Often yes, provided you add query cost limits, persisted queries, and a caching strategy. The comparison in the table is the one to run: GraphQL's gains in payload fit come with losses in HTTP-level caching.

When should I version an API versus evolve it in place?

Evolve in place with additive changes inside a major version. Introduce a new version when a required field, a type, or a status code contract changes in a way clients cannot absorb, and announce the old version's retirement window at the same time.

Do idempotency keys matter for read-only endpoints?

Not in the same way. They matter for operations that change state and could be retried after a lost response: payments, order creation, provisioning. For reads, retries are naturally safe unless they trigger side effects.

How do I test protocols that run through a CDN or API gateway?

Run the same protocol tests in a staging environment configured like production, including the proxy layer, and pay particular attention to streaming, long-lived connections, and header rewriting. A test that passes only against the app server proves less than it appears to.