This blog is part of the Architecting a System series, where we are breaking down what all goes behind designing and building a system.
The previous part covered requirements and the guidelines - extensibility, flexibility, decoupling - that shape every decision after them.
In this part, we move to communication and flow design. We will look at how users and different components of a system communicate, how data flows through the system, and how to decide between synchronous and asynchronous communication.
Introduction
Once the requirements and foundational guidelines have been defined, the next step is to understand how users, services, and data communicate with one another.
This means designing both the user flow and the data flow through the system.
When doing flow design, always keep the following points in mind. We will revisit many of them in more detail later:
- HTTP/1.1 allows persistent TCP connections, subject to the connection being closed because of a timeout, server policy, network issue, or explicit
Connection: closebehaviour. - HTTP/2 supports multiplexing, which HTTP/1.1 does not. Multiplexing allows multiple requests and responses to share a single connection without requiring every response to be completed strictly in request order. One workaround for HTTP/1.1 limitations was to open multiple TCP connections, usually bounded by a browser-defined maximum.
- HTTP/2 multiplexes at the stream layer, but it still runs over a single TCP connection. One lost packet stalls every stream sharing that connection until the retransmission arrives, so head-of-line blocking moved down to the transport layer rather than disappearing. HTTP/3 runs over QUIC, which recovers loss per stream, so a dropped packet only holds up the stream it belonged to.
- Retries are essential, but only for the right failures. Retry timeouts, connection resets, 5xx responses, and 429s that ask you to back off. Do not blanket-retry 4xx, because a request the server has rejected on its merits will usually be rejected again. Pair retries with exponential backoff, and bound them with a retry budget or a circuit breaker. Unbounded retries turn a struggling dependency into an outage, because they send it the most traffic at exactly the moment it can handle the least.
- Idempotent behaviour is a necessity. If the same request is produced once but processed twice, it should not cause an issue.
- Random jitter helps avoid different types of retry and coordination problems.

Another important decision is whether processing should be done synchronously or asynchronously.
In synchronous processing, a client makes an API call, the system performs the processing, and then sends the complete response.

Do not look down on synchronous processing, it is what is keeping most of the systems up and running.
With regards to asynchronous processing, there are multiple ways to do it. Here is a generic flow.

The HTTP shape underneath that diagram is worth naming, because every mechanism below reuses it. The write endpoint does not return the result. It accepts the work, returns 202 Accepted with a job identifier in the body, and sets a Location header pointing at a status resource, usually something like /jobs/{id}. The user then polls or waits on that resource rather than on the endpoint they originally called.
The job id is the part to pay attention to. Short polling reads it from the status URL, a long-poll request holds it open, a WebSocket message carries it, an SSE event names it in its id: field, and a push notification often contains little more than it.
Every approach that follows is a different way of asking about the same job id.
Now let’s take a look at the different ways.
Polling
The user sends a request, immediately gets a response, and then keeps “asking” the system whether the final response is ready.
There are two widely used types of polling.
Short Polling
The user sends a request, and the system responds immediately with either the result or a response indicating that the result is not ready yet. If the result was not received, the user then repeats the request after an interval.

Say some processing takes 10 seconds and the user sends a request every 2 seconds. The user will receive the response after approximately five attempts.
Also, because HTTP/1.1 supports persistent connections, you will not necessarily be penalised with a new TCP handshake for every attempt.
Two things keep short polling affordable.
The first is conditional requests. Have the status resource carry an ETag, or a Last-Modified date, and have the user send it back as If-None-Match or If-Modified-Since. A poll against a job that has not changed then returns 304 Not Modified with no body. The round trip still happens, but it stops costing serialisation, bandwidth, and in most designs a read of the full job record.
The second is backoff. A fixed interval spends the same effort at second 2 as at second 60, which is wrong in both directions. Something like 1s, 2s, 4s, 8s, capped at 15s and jittered, tracks the actual uncertainty better.
The load worth thinking about, though, is the aggregate one. Say 10,000 users are polling every 2 seconds. That is 5,000 requests per second against your status store, and that floor holds whether one job completed in a given second or none did. In the example above, a single job costs five requests. Ten thousand concurrent jobs cost fifty thousand, most of which return nothing new.
Polling costs the same whether anything is happening or not, and that, rather than the price of any single request, is what makes it expensive.
Long Polling
The user sends a request, and the system waits for up to X seconds.
During those X seconds, the system waits to be told that the result is ready, typically through something such as Redis Pub/Sub or ZeroMQ. Just a heads up, we will discuss much more about Pub/Sub in the next blog.

The order of operations here matters. Pub/Sub delivers only to subscribers that are already listening, and it retains nothing. If the worker publishes completion in the gap between the request arriving and the handler subscribing, that message is gone, and the request sits idle for the full X seconds even though the result was ready almost immediately. So the handler should do three things, in this order:
- Subscribe to the channel for that job.
- Then read the result store, in case the job finished before the subscription existed.
- Only then wait, up to
Xseconds, for the published message or the timeout, whichever comes first.
If the result is already there at step 2, respond straight away and drop the subscription. If the X seconds pass without a result, the system responds that the result is not ready yet.
Pub/Sub is a perfectly good choice here as long as it is paired with that read-after-subscribe check. If you would rather not depend on getting the ordering right, use something that retains the message. Redis Streams, or a durable queue, lets the reader collect a completion that was published while it was not looking.
Say processing takes 10 seconds, the user waits 2 seconds before starting to poll, and the long-poll duration is 5 seconds. The first “not yet ready” response will be received at approximately t = 7s. During the second request, the user will receive the result.
What that example does not show is where the cost went. Long polling moves it from the user to the server, and how much it costs there depends almost entirely on the runtime.
On a thread-per-request stack, such as WSGI behind synchronous gunicorn workers, a servlet container on the classic blocking model, or PHP-FPM, a held request occupies a worker for the whole hold window. The worker is not computing anything. It is waiting. With 32 workers and a 30 second hold, the server can accept roughly one new request per second before the pool is exhausted, and once it is, everything queues behind it, including requests that have nothing to do with polling. Long polling on such a stack can starve a server that is using almost no CPU.
On an async runtime, such as asyncio, Node, Go, or Netty, a held request is a suspended coroutine or goroutine waiting on a future or a channel. It costs a file descriptor and a few kilobytes. Tens of thousands of them in one process is unremarkable.
This is usually the deciding factor. The question is not how much traffic you have, but what your server does with a request that is doing nothing.
When to Use What?
A good rule of thumb is:
- Short polling: Use it when results are expected quickly, the polling frequency is low, or simplicity matters more than efficiency.
- Long polling: Use it when results can take an unpredictable amount of time and you want to reduce unnecessary requests.
Push Mechanisms
With a push mechanism, the user sends a request and receives an immediate acknowledgement. The system then takes responsibility for initiating delivery whenever the response becomes available.
There are a few ways to do this.
WebSockets
When a WebSocket connection is established, the system can push responses to the client over that connection.

Holding that connection open is the easy part. Closing it is where the decisions are, and who closes it turns out to matter.
At a normal scale it is fine for the server to initiate the close, and it is what the specification asks for. RFC 6455 Section 7.1.1 says the underlying TCP connection “in most normal cases, SHOULD be closed first by the server, so that it holds the TIME_WAIT state and not the client”. The reasoning is that a client left in TIME_WAIT cannot reopen that connection for two maximum segment lifetimes (MSL), while the specification treats the server-side cost as negligible.
At a very large scale that cost is not quite negligible, and it lands on whichever side sends the first FIN. Every server-initiated close leaves a TIME_WAIT entry on the server for 2MSL, which on Linux is a fixed 60 seconds. At a few thousand connections you will never notice. Drain 200,000 connections during a deploy and you have 200,000 TIME_WAIT entries in the socket table at once, which costs memory and can collide with tcp_max_tw_buckets. This is table pressure, not port exhaustion, since the server is still listening on one port.
So in high-scale systems, one approach is to invert the close. The server asks the client to close the connection, the client then sends a WebSocket close frame, and the server responds with its own close frame. Once the close handshake is complete, the server can release the connection resources, and the client rather than the server holds TIME_WAIT.

It is worth being plain that this is a deliberate deviation from what the specification recommends. It earns its keep only for planned drains, such as deploys or shard rebalancing, where you are closing a large batch at a time of your own choosing.
There is a second reason to spread a drain out. Every client you disconnect will try to come back, and if you close them all in the same instant they will all reconnect in the same instant, onto a process that has only just started. This is where the jitter point from the introduction pays off. The close request should carry a reconnect delay with randomness in it, so that the herd arrives spread across a window instead of as a single spike.
The server should not rely on the client indefinitely.
After asking the client to close, it should start an asynchronous cleanup timer. When the timer fires, the system should check for connections that were asked to close but are still open and force-close the remaining connections.
Server-Sent Events
Server-Sent Events, or SSE, allow the user to initiate a request while the system keeps the response open.
Instead of ending the response after sending one payload, the system can continue sending chunks of data over the same connection.

SSE is especially useful when communication primarily flows in one direction: from the server to the client.
There are four constraints worth knowing before choosing it.
Under HTTP/1.1, browsers cap simultaneous connections per origin at around six, and an open SSE stream holds one of those slots for as long as it stays open. A user with six tabs open on your site has spent the entire budget on streams, and ordinary requests to the same origin then queue behind them. Over HTTP/2 the streams are multiplexed onto a single connection and the limit becomes the negotiated maximum concurrent streams, which defaults to 100, so the problem largely goes away.
EventSource reconnects on its own when the connection drops. On reconnecting it sends the last event id it saw back in a Last-Event-ID request header. That only helps if the server emits an id: field on its events and can resume from a given id. Without both halves, the client reconnects cleanly and silently misses whatever was produced while it was away. The server can also set the reconnection delay itself with a retry: field.

Anything between the server and the client that buffers responses will defeat the streaming behaviour. Reverse proxies commonly hold chunks until a buffer fills or the response ends, which turns a stream of events into a single delivery at the end, and looks from the client exactly like a slow server. Response buffering has to be disabled explicitly along that path.
Finally, SSE is text only and the stream must be UTF-8. Binary payloads have to be encoded, usually as base64, at a cost of roughly a third more bytes.
Push Notifications
When using Firebase Cloud Messaging or Apple Push Notification Service, the push notification generally contains a minimal payload indicating that a result or update is available.
The client can then send a separate request to fetch the actual data.

This approach keeps the push-notification payload small and avoids placing sensitive details directly inside it.
Webhooks
The mechanisms above deliver to a user’s client. A webhook delivers to another system.
The receiver registers a callback URL with the sender ahead of time. When the work completes, the sender makes an HTTP POST to that URL carrying the event. It is the same push model, except both ends are servers.

Push notifications keep the payload minimal and let the client fetch the real data. Webhooks usually do the opposite and carry the full event body. That saves the receiver a round trip, but it puts your data in transit to an endpoint you do not control, and the receiver ends up acting on a copy that may already be stale. Sending an identifier and letting the receiver fetch remains the safer default when the payload is sensitive or changes quickly.
Anyone can POST to a public URL, so the receiver has to establish two things: that the request came from the sender, and that it is not a replay. Introducing something slightly complex here regarding the first point, the two systems interacting with each other, in secured environments can have VPC Peering which is establishing a Site-To-Site VPN connection between two VPCs, in this case, your URL does not have to be public.
Authenticity is handled with an HMAC signature over the request body, keyed on a secret shared when the endpoint was registered and sent in a header. Stripe uses Stripe-Signature and GitHub uses X-Hub-Signature-256, both HMAC-SHA256. The receiver recomputes the digest and compares it in constant time.
Compute it over the raw bytes, before any JSON parse and re-serialise. Key order and whitespace will not survive that round trip, and verification will fail on a payload that is perfectly valid.
Rotating the secret works by overlap. For a window, the sender signs with both the old and the new secret and sends both signatures, and the receiver accepts a match against either.
Replay protection comes from putting a timestamp inside the signed payload and rejecting anything outside a tolerance window, commonly five minutes. Pair that with the event id and the idempotent behaviour mentioned earlier. Record the ids you have processed, and drop repeats.
Delivery is not guaranteed. The receiver can be down, slow, or simply return a 500. So the sender needs retries with exponential backoff, bounded attempts, and somewhere for the failures to go.
Say the base delay is 1 second, it doubles each attempt, and there are eight attempts. The delays are 1s, 2s, 4s, 8s, 16s, 32s, 64s, 128s, roughly four minutes of retrying. Apply random jitter to each delay, otherwise a receiver coming back up gets every queued delivery at the same instant. Longer schedules are normal for events that matter. Stripe retries for up to three days.
Anything that exhausts its attempts should land in a dead-letter queue, with a manual replay endpoint behind it.

On the receiving side, acknowledge fast. Verify the signature, enqueue the event, return 2xx, and process it outside the request. Senders time out aggressively, GitHub allows ten seconds, and a timeout is indistinguishable from a failure, so it triggers a retry. Processing inline does not just make you late, it turns one event into several duplicate deliveries.
Ordering is not guaranteed either. Attempt one of event A can land after event B if A had to be retried. Put a sequence number or a version on each event, and let the receiver discard anything older than what it has already applied.

One last thing on the sending side. You are making outbound HTTP to a URL a user supplied, so resolve and check the address before connecting, and reject private and link-local ranges. Otherwise your delivery worker becomes an SSRF tool pointed at your own network.
Conclusion
Communication and flow design determine how the different parts of your system interact and how users experience the work being done behind the scenes.
We looked at synchronous and asynchronous processing, short and long polling, WebSockets, Server-Sent Events, push notifications, and webhooks. Each mechanism solves a slightly different problem, and the correct choice depends on factors such as processing time, communication direction, connection scale, implementation complexity, and the user experience you want to provide.
Regardless of the mechanism you select, retries, idempotency, timeouts, cleanup, and jitter should be treated as part of the design rather than added later as afterthoughts.
Next up, we will look at buffers, events and streaming - and what happens when producers generate data faster than consumers can process it.



