<p>I'm working on a web service at the moment and there is the potential that the returned results could be quite large ( > 5mb). </p>

<p>It's perfectly valid for this set of data to be this large and the web service can be called either sync or async, but I'm wondering what people's thoughts are on the following:</p>

<ol>
<li><p>If the connection is lost, the
entire resultset will have to be
regenerated and sent again. Is there
any way I can do any sort of
"resume" if the connection is lost
or reset?</p></li>
<li><p>Is sending a result set this large even appropriate? Would it be better to implement some sort of "paging" where the resultset is generated and stored on the server and the client can then download chunks of the resultset in smaller amounts and re-assemble the set at their end?</p></li>
</ol>

[{'answer_id': 11813, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 2, 'selected': False, 'text': '<p>There\'s no hard law against 5 Mb as a result set size. Over 400 Mb can be <a href="http://msdn.microsoft.com/en-us/library/aa528822.aspx" rel="nofollow noreferrer">hard to send</a>.</p>\n\n<p>You\'ll automatically get async handlers (since you\'re using .net)</p>\n\n<blockquote>\n  <p>implement some sort of "paging" where\n  the resultset is generated and stored\n  on the server and the client can then\n  download chunks of the resultset in\n  smaller amounts and re-assemble the\n  set at their end</p>\n</blockquote>\n\n<p>That\'s already happening for you -- it\'s called tcp/ip ;-) Re-implementing that could be overkill.</p>\n\n<p>Similarly --</p>\n\n<blockquote>\n  <p>entire resultset will have to be\n  regenerated and sent again</p>\n</blockquote>\n\n<p>If it\'s MS-SQL, for example that is generating most of the resultset -- then re-generating it will take advantage of some implicit cacheing in SQL Server and the subsequent generations will be quicker. </p>\n\n<p>To some extent you can get away with not worrying about these problems, until they surface as \'real\' problems -- because the platform(s) you\'re using take care of a lot of the performance bottlenecks for you.</p>\n'}, {'answer_id': 11823, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 0, 'selected': False, 'text': "<p>I somewhat disagree with secretGeek's comment:</p>\n\n<blockquote>\n  <p>That's already happening for you -- it's called tcp/ip ;-) Re-implementing that could be overkill.</p>\n</blockquote>\n\n<p>There are times when you may want to do just this, but really only from a UI perspective.  If you implement some way to either stream the data to the client (via something like a pushlets mechanism), or chunk it into pages as you suggest, you can then load some really small subset on the client and then slowly build up the UI with the full amount of data.</p>\n\n<p>This makes for a slicker, speedier UI (from the user's perspective), but you have to evaluate if the extra effort will be worthwhile... because I don't think it will be an insignificant amount of work.</p>\n"}, {'answer_id': 11873, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 0, 'selected': False, 'text': "<p>So it sounds like you'd be interested in a solution that adds 'starting record number' and 'final record number' parameter to your web method. (or 'page number' and 'results per page')</p>\n\n<p>This shouldn't be too hard if the backing store is sql server (or even mysql) as they have built in support for row numbering.</p>\n\n<p>Despite this you should be able to avoid doing any session management on the server, avoid any explicit caching of the result set, and just rely on the backing store's caching to keep your life simple.</p>\n"}, {'answer_id': 920922, 'author': 'DavidValeri', 'author_id': 107057, 'author_profile': 'https://Stackoverflow.com/users/107057', 'pm_score': 3, 'selected': True, 'text': "<p>I have seen all three approaches, <strong>paged</strong>, <strong>store and retrieve</strong>, and <strong>massive push</strong>.</p>\n\n<p>I think the solution to your problem depends to some extent on why your result set is so large and how it is generated.  Do your results grow over time, are they calculated all at once and then pushed, do you want to stream them back as soon as you have them?</p>\n\n<h2><strong>Paging Approach</strong></h2>\n\n<p>In my experience, using a paging approach is appropriate when the client needs quick access to reasonably sized chunks of the result set similar to pages in search results.  Considerations here are overall chattiness of your protocol, caching of the entire result set between client page requests, and/or the processing time it takes to generate a page of results.</p>\n\n<h2><strong>Store and retrieve</strong></h2>\n\n<p>Store and retrieve is useful when the results are not random access and the result set grows in size as the query is processed.  Issues to consider here are complexity for clients and if you can provide the user with partial results or if you need to calculate all results before returning anything to the client (think sorting of results from distributed search engines).</p>\n\n<h2><strong>Massive Push</strong></h2>\n\n<p>The massive push approach is almost certainly flawed.  Even if the client needs all of the information and it needs to be pushed in a monolithic result set, I would recommend taking the approach of <code>WS-ReliableMessaging</code> (either directly or through your own simplified version) and chunking your results.  By doing this you </p>\n\n<ol>\n<li>ensure that the pieces reach the client </li>\n<li>can discard the chunk as soon as you get a receipt from the client</li>\n<li>can reduce the possible issues with memory consumption from having to retain 5MB of XML, DOM, or whatever in memory (assuming that you aren't processing the results in a streaming manner) on the server and client sides.</li>\n</ol>\n\n<p>Like others have said though, don't do anything until you know your result set size, how it is generated, and overall performance to be actual issues.</p>\n"}]
['https://Stackoverflow.com/questions/11804', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/493/']