title: Aggregation of data on API Gateway
body: <p>I am working on microservice architecture and I want to aggregate data from two microservices.</p>
  
  <p>For example, Frontend calls the API Gateway and API Gateway calls two microservices Customer and Order microservices. Customer microservice returns customer details and Order microservice returns all ordered products by customer. </p>
  
  <p>This is the format returned by API Gateway after aggregation from two microservice using Ocelot or Azure API Management. </p>
  
  <p><strong>Format 1</strong></p>
  
  <pre><code>{ 
     "Customers":[ 
        { 
           "customerId":1001,
           "customerName":"Tom"
        },
        { 
           "customerId":1002,
           "customerName":"Jerry"
        }
     ],
     "Orders":[ 
        { 
           "CustomerId":1001,
           "Orders":[ 
              { 
                 "ProductId":"PRO1",
                 "ProductName":"Books"
              },
              { 
                 "ProductId":"PRO2",
                 "ProductName":"Pens"
              }
           ]
        },
        { 
           "CustomerId":1002,
           "Orders":[ 
              { 
                 "ProductId":"PRO3",
                 "ProductName":"Pencils"
              },
              { 
                 "ProductId":"PRO4",
                 "ProductName":"Toys"
              }
           ]
        }
     ]
  }
  </code></pre>
  
  <p>The Format that I want is format 2.</p>
  
  <p><strong>Format 2</strong></p>
  
  <pre><code>{
     "OrderDetails":[
        {
           "customerId":1001,
           "customerName":"Tom",
           "Orders":[
              {
                 "ProductId":"PRO1",
                 "ProductName":"Books"
              },
              {
                 "ProductId":"PRO2",
                 "ProductName":"Pens"
              }
           ]
        },
        {
           "customerId":1002,
           "customerName":"Jerry",
           "Orders":[
              {
                 "ProductId":"PRO3",
                 "ProductName":"Pencils"
              },
              {
                 "ProductId":"PRO4",
                 "ProductName":"Toys"
              }
           ]
        }
     ]
  }
  </code></pre>
  
  <p>The second format is achievable using Ocelot but the merging of data is based on the ids on Gateway and it requires some processing.</p>
  
  <p>Is it a good practice to aggregate data on Gateway using business logic. If not what practices should be followed for this kind of aggregation?</p>
  
  <p>It would be nice if you can provide some references for achieving this aggregation using the Azure API Management. </p>