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
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

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
TCP
reliable delivery
sequence numbers
flow control
interval merging
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample Answer
Requirements
  • receive(seq, data): seq is the offset of data[0] in the stream.
  • Deliver bytes in order to delivered; never deliver a byte twice or out of order.
  • Buffer at most window bytes 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:

  1. Clip it to [next_seq, next_seq + window)....

Submit Your Answer
Markdown supported