title: What's the right way to gather data from different microservices?
body: <p>I'm having a problem understanding how basic communication between microservices should be made and I haven't been able to find a good solution or standard way to do this in the other questions. Let's use this basic example.</p>
  
  <p><a href="https://i.stack.imgur.com/pOCGv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pOCGv.png" alt="enter image description here"></a></p>
  
  <p>I have an invoice service that return <strong>invoices</strong>, every invoice will contain information(ids) about the user and the products. If I have a view in which I need to render the invoices for a specific user, I just make a simple request.</p>
  
  <pre><code>let url = "http://my-domain.com/api/v2/invoices"
  let params = {userId:1}
  request(url,params,(e,r)=&gt;{
    const results = r // An array of 1000 invoices for the user 1
  });
  </code></pre>
  
  <p>Now, for this specific <strong>view</strong> I will need to make another request to get all the details for each product on each invoice.</p>
  
  <pre><code>results.map((invoice)=&gt;{
     invoice.items.map((itemId)=&gt;{
        const url=`http://my-domain.com/api/v2/products/${itemId}`
        request(url,(e,r)=&gt;{
         const product = r
         //Do something else.....
        });
     });
  });
  </code></pre>
  
  <p>I know the code example is not perfect but you can see that this will generate a huge number of requests(at least 1000) to the product service and just for 1 user, now imagine if I have 1000 users making this kind of requests.</p>
  
  <p>What is the right way to get the information off all the products without having to make this number of requests in order to avoid performance issues?.</p>
  
  <p>I found some workarounds for this kind of scenarios such as:</p>
  
  <ol>
  <li>Create an API endpoint that accepts a list of IDs in order to make a single request.</li>
  <li>Duplicate the information from the Product service within the invoice service and find a way to keep them in sync.</li>
  </ol>
  
  <p>In a microservices architecture are these the right ways to deal with this kind of issues? For me, they look like simple workarounds.</p>
  
  <p><strong><em>Edit #1: Based on Remus Rusanu response.</em></strong></p>
  
  <p>As per Remus recommendation, I decided to isolate my services and describe them a little bit better.</p>
  
  <p><a href="https://i.stack.imgur.com/BHosb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BHosb.png" alt="enter image description here"></a></p>
  
  <p>As shown in the image above the microservices are now isolated(in specific the Billing-service) and they now are the owners of the data. By using this structure I ensure that Billing-service is able to work even if there are async jobs or even if the other two services are down.</p>
  
  <p>If I need to create a new invoice, I can call the other two microservices(Users, Inventory) synchronously and then update the data on the "cache" tables(Users, Inventory) in my billing service.</p>
  
  <p>Is it also good to assume these "cache" tables are read-only? I assume they are since only the user/inventory services should be able to modify this information to preserve isolation and authority over the information.</p>