title: packet order in TCP packet fragmentation
body: <p>In TCP/IP, we have MSS and MTU when sending and receiving packets.</p>
  
  <ol>
  <li>MTU is an IP layer concept, which is determined by the underlying hardware. It shows the maximum data size that an IP layer packet can contain during one transmission.</li>
  <li>MSS is a TCP layer concept, which is limited by the MTU, showing that the TCP data stream will be fragmented into MSS-size packets.</li>
  </ol>
  
  <p>Our protocol lies on top of TCP, and each protocol will define its own packet. One example is MySQL, which defines its packet size up to 2^24-1, that is around 16M. When the big enough protocol packet comes to TCP, it will be fragmented according to MSS.</p>
  
  <p>Assume that a client needs to send DATA1 and DATA2 to server. DATA2 size is bigger than MSS, and DATA2 will be fragmented into DATA2_1, DATA2_2. As the packets will be handled by the IP layer, so the time that each packet arrives at server might not be the same as that when the client sends them.</p>
  
  <p>So I think the sequence of packets' arriving might be the following:</p>
  
  <ol>
  <li>DATA1 DATA2_1, DATA2_2</li>
  <li>DATA1, DATA2_1, DATA2_2</li>
  <li>DATA1, DATA2_2, DATA2_1</li>
  </ol>
  
  <p>In the first case, the server receives DATA1 and DATA2_1 in one tcp packet and then another packet contains DATA2_2 arrives.</p>
  
  <p>In the second case, the server receives DATA1, DATA2_1 and DATA2_2 in three packets.</p>
  
  <p>In the third case, the server first receives DATA2_2 and then DATA2_1. </p>
  
  <h2>My question:</h2>
  
  <p>Is the third case possible? </p>
  
  <p>If yes, it disobeys that TCP is a stream protocol, and stream protocol should be ordered. And even this does not break the stream rule, how to handle this scenario? </p>
  
  <p>If no, how TCP makes the disordered packets into its original order?</p>