title: RxJava Fetching Observables In Parallel
body: <p>I need some help in implementing parallel asynchronous calls in RxJava. I have picked up a simple use case wherein the FIRST call fetches (rather searches) a list of products (Tile) to be displayed. The subsequent calls go out and fetch (A) REVIEWS and (B) PRODUCT IMAGES</p>
  
  <p>After several attempts I got to this place. </p>
  
  <pre><code> 1    Observable&lt;Tile&gt; searchTile = searchServiceClient.getSearchResults(searchTerm);
   2    List&lt;Tile&gt; allTiles = new ArrayList&lt;Tile&gt;();
   3    ClientResponse response = new ClientResponse();
  
   4    searchTile.parallel(oTile -&gt; {
   5      return oTile.flatMap(t -&gt; {
   6        Observable&lt;Reviews&gt; reviews = reviewsServiceClient.getSellerReviews(t.getSellerId());
   7        Observable&lt;String&gt; imageUrl = reviewsServiceClient.getProductImage(t.getProductId());
  
   8        return Observable.zip(reviews, imageUrl, (r, u) -&gt; {
   9          t.setReviews(r);
  10          t.setImageUrl(u);
  
  11          return t;
  12        });
  
  13      });
  14    }).subscribe(e -&gt; {
  15      allTiles.add((Tile) e);
  16    });
  </code></pre>
  
  <p>Line  1: goes out and fetches the product (Tile) to be displayed</p>
  
  <p>Line  4: We take the list of the Observable and SHARD it to fetch reviews and imageUrls</p>
  
  <p>Lie 6,7: Fetch the Observable review and Observable url</p>
  
  <p>Line  8: Finally the 2 observables are zipped up to return an updated Observable</p>
  
  <p>Line 15: finally line 15 collates all the individual products to be displayed in a collection which can be returned back to the calling layer</p>
  
  <p>While the Observable has been sharded and in our tests run over 4 different threads; fetching of reviews and images seems to be one after another. I suspect that the zip step on line 8 is basically causing the sequential invocation of the the 2 observables (reviews and url).</p>
  
  <p><img src="https://i.stack.imgur.com/YVERX.png" alt="enter image description here"></p>
  
  <p>Does this group have any suggestion to parallely fetch reiews and image urls. In essence the waterfall chart attached above should look more vertically stacked. The calls to reviews and images should be in parallel</p>
  
  <p>thanks
  anand raman</p>