How does the web server communicate with the database?
<p>This is just to explain how I think it probably works:
Let's say the web server needs data from 10 tables. The data that will finally be displayed on the client needs some kind of formatting which can be done either on the database or the web server.Let's say the time to fetch the raw data for one table is 1 sec and the time to fetch formatted data for one table is 2 sec (It takes one second to format the data for one table and the formatting can be easily done either on the web server or the database.)</p>

<p>Let's consider the following cases for communication: </p>

<p>Case 1:</p>

<pre><code>for(i = 0; i &lt; 10; i++)
{
    table[i].getDataFromDB(); //2 sec - gets formatted datafrom DB, Call is completed before control goes to next statement

    table[i].sendDataToClient(); //0 sec - control doesn't wait for completion of this step
}
</code></pre>

<p>Case 2:</p>

<pre><code>for(i = 0; i &lt; 10; i++)
{
    table[i].getDataFromDB(); //1 sec - gets raw data from DB, Call is completed before control goes to next statement

    table[i].formatData(); //0 sec - will be executed as a parallel process     which takes 1 sec to complete (control moves to next statement before completion)
}

formatData()
{
    //format the data which takes 1 sec
    sendDataToClient(); //0 sec - control doesn't wait for completion of   this step
}
</code></pre>

<p><em>Assume it takes no time (0 sec) to send the data from the web server to the client since it will be constant for both cases.</em></p>

<p>In case 1, the data for each table will be displayed at interval of 2 seconds on the client, and the complete data will be
on client after 20 seconds.</p>

<p>In case 2, the data for first table will be displayed after 2 sec, but the data for the next 9 will then be displayed at sec 3,4,...,11.</p>

<p>Which is the correct way and how is it achieved between popular web server and databases ?</p>