<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="132809" data-post-id="132809">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="yurko" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/yurko/120/2369_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  yurko
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>We do something similar and the collection size is also way too big to consider an in memory solution. This happens in the background every couple dozen hours.</p>
<p>Here are few points as to how we approach it:</p>
<ul>
<li>
<p>The basic logic is similar to what you describe under continuation-passing style, it is done in a GenServer that is a bit state-machine like (without using fsm) - there is startup routine, crawling, finalizing and waiting states</p>
</li>
<li>
<p>We have a special “cache” DB Table to persist data while it is gathered one page at a time</p>
</li>
<li>
<p>After the crawling is done we “activate” the gathered data by streaming it from the “cache” table to the “live” one (using Repo.stream in transaction), this way the rest of the system always accesses data that was successfully gathered and we never end up with inconsistent state in the live table, any problems would be contained with the “cache” part</p>
</li>
<li>
<p>No circuit breaker but fixed retrying after 5 seconds on failed requests, this part is fully flexible though</p>
</li>
<li>
<p>We have extra status that we persist to ETS table - “waiting”, “crawling”, “retrying”, “finalizing” etc, we also might hold the current error if there is one and the number of page if crawling is in progress, this way UI layer has access to info as to what is happening at the moment</p>
</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="132809" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/software-design-processing-remote-collection-of-items-via-paginated-api-while-properly-handling-errors/23212/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-132809" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="132809"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="270628" data-post-id="270628">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="megalithic" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/megalithic/120/20937_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  megalithic
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey there Greg!</p>
<p>Is this still a solution you’d reach to for paginated API requests; specifically, APIs with rather restrictive rate limits?</p>
<p>Thanks sir!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270628" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/software-design-processing-remote-collection-of-items-via-paginated-api-while-properly-handling-errors/23212/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-270628" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270628"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="270715" data-post-id="270715">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gregvaughn" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/120/954_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gregvaughn
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="megalithic" data-post="13" data-topic="23212">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/megalithic/48/20937_2.png" class="avatar"> megalithic:</div>
<blockquote>
<p>Is this still a solution you’d reach to for paginated API requests; specifically, APIs with rather restrictive rate limits?</p>
</blockquote>
</aside>
<p>It’s been a couple of years since I worked on that system, but, yes, the overall approach held up well. The <code>Stream.unfold</code> approach was mostly a convenience to the caller. The idea of using a Task to get one page ahead was more of an optimization in our case. I’d recommend you first get a synchronous <code>Stream.unfold</code> working before adding in the optimization.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="270715" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/software-design-processing-remote-collection-of-items-via-paginated-api-while-properly-handling-errors/23212/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-270715" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270715"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>