Bytes rather than messages
TCP presents an ordered byte stream between endpoints. It does not preserve application write boundaries. Two writes may be returned by one read, and a single write may require several reads. The application therefore needs framing, such as a length prefix, delimiters or a fixed record size.
A test where each write appears to match a read does not establish a protocol guarantee. Buffering, scheduling and segmentation can change the grouping while the transport remains completely correct.
Recovering missing bytes
Sequence numbers identify positions in the byte stream. Acknowledgments and sender timers help detect missing data and trigger retransmission. Duplicate segments are reconciled so that retransmission does not become duplicated bytes in the receiving application.
If later bytes arrive before an earlier gap is repaired, in-order delivery can make them wait. Multiplexing several application operations over one TCP connection does not remove this underlying ordering dependency. Distinguish an application stream from the transport stream carrying it.
An ACK is not a business receipt
A successful write commonly means acceptance into a local send buffer. A TCP acknowledgment indicates progress at the receiving transport endpoint, not that an order was committed to a database. Only an application-level response can communicate that business outcome.
If a connection breaks after an order request, the client may not know whether the server never processed it or processed it and lost the reply. Safe retries require an application mechanism such as an idempotency key, rather than an assumption that transport reliability provides exactly-once business execution.
Performance and failure limits
Flow control protects a receiver with limited buffer space; congestion control responds to conditions along the network path. A stalled receiver and a congested path are different causes of poor throughput. Large nominal bandwidth does not remove the effects of round-trip time and loss.
TCP cannot eliminate endpoint failures or permanent disconnection. Applications still need deadlines and a policy for uncertain outcomes. Choose those deadlines around the user operation, rather than assuming that transport retransmission will finish within an acceptable time.
Reconstruct two messages from three reads
Consider a small newline-delimited protocol sending HELLO followed by a newline and NEXT followed by another newline. Three reads may return HE, then LLO plus newline plus NE, then XT plus newline. The first fragment does not complete a message. The second completes HELLO while leaving NE buffered. The third completes NEXT. Parse the accumulated bytes according to the framing rule rather than counting sender write calls. A real protocol must also specify maximum message length and how payload data can contain or escape the delimiter.
This framing problem is separate from what the receiving application has done with the data. TCP acknowledgment of order bytes does not establish that the application read them, stored the order or completed a payment. If the application reply disappears and the caller retries, operation identifiers and outcome retrieval can be necessary to avoid duplicate business effects. Ordered bytes, receiver-capacity control, network-congestion response and business-level exactly-once handling are different responsibilities. Keeping them separate makes a successful transport observation useful without giving it application guarantees it cannot establish.
| Read | Completed message | Buffered remainder |
|---|---|---|
| HE | None | HE |
| LLO\nNE | HELLO | NE |
| XT\n | NEXT | Empty |
Handle short reads and short writes deliberately
A read returning fewer bytes than requested can be ordinary partial progress. With a length-prefixed format, collect the complete header, check the declared length against a limit, and buffer until the required body is available. Sending code likewise follows the byte count returned by the API and retains an unsent suffix when necessary. Blocking behavior, interruption, temporary unavailability, and connection termination need separate handling. A simple loop must not interpret every short operation as a complete message or retry every error forever. The TCP PSH flag does not create the application record boundaries needed to recover one write as exactly one read.
Identify three different completion points
Separate the sending application, the receiving TCP endpoint, and the receiving application’s business operation. A successful send commonly means local acceptance; an acknowledgment concerns transport receipt; an application success reply concerns the application’s own completion contract. If an order is committed and its reply disappears, the client can face an unknown result rather than a known failure. Stable request identifiers, result lookup, and deduplication address that uncertainty. TCP’s handling of duplicate sequence ranges does not stop an application from sending the same order again as a new request. Write down the completion point promised by each interface before designing retries or interpreting an apparently successful trace.
An established connection need not meet a deadline
A connection can remain established while an application stops reading, a receive window closes, or loss prevents useful progress. Flow control addresses receiving capacity, while congestion control addresses network conditions. Neither chooses the business deadline for an order. Set a request-wide deadline and decide how to investigate a possibly completed operation after it expires. TCP also supports one direction finishing before the other, so receiving end-of-stream need not forbid sending a final reply. Compare socket state, queued bytes, and application logs on the same timeline. A transport status is evidence about one stage, not a complete explanation of the user-visible delay.