Reassemble Out-of-Order Segments Into a Byte Stream Like TCP
Last updated: November 29, 2026
Quick Overview
Implement the receive side of a reliable byte stream: segments arrive with a byte offset, possibly out of order, duplicated, or overlapping. Deliver bytes to the application strictly in order, respect a receive window, and return the cumulative acknowledgment after each segment.
Microsoft
November 29, 20260
0
0 solved
Implement the receive side of a reliable byte stream: segments arrive with a byte offset, possibly out of order, duplicated, or overlapping. Deliver bytes to the application strictly in order, respect a receive window, and return the cumulative acknowledgment after each segment.
Networking fundamentals come up for Microsoft teams on Windows networking, Azure networking and Teams real-time media. This question checks whether the candidate understands what TCP's receive buffer does: sequence space, cumulative ACKs, the receive window, and careful interval handling for overlaps.
What the Interviewer Expects
- Tracks the next expected byte and returns it as the cumulative ACK
- Buffers out-of-order data and delivers it once the gap fills
- Trims data that is already delivered or outside the window
- Handles overlapping and duplicate segments without duplicating bytes
- Explains how the window provides flow control
- Tests with randomized reordering and duplication
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would selective acknowledgments (SACK) change what you report?
- How does the sender use the advertised window, and what happens when it reaches zero?
- How would you handle 32-bit sequence number wraparound?
- Why might QUIC choose per-stream reassembly instead?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
receive(seq, data):seqis the offset ofdata[0]in the stream.- Deliver bytes in order to
delivered; never deliver a byte twice or out of order. - Buffer at most
windowbytes beyond the ...
High-Level Design
State: next_seq (everything before it is delivered) and pending, a map of non-overlapping buffered chunks keyed by start offset. On each segment:
- Clip it to
[next_seq, next_seq + window)....