title: Cosmos db graph vs Azure Sql Server - Performance and cost
body: <p>Imagine a social network app. Users follow other users and users take photos. Photos have tags of other users.<br/></p>
  
  <p>I'm trying to get an effective Cosmos db implementation of a graph for that app. I provide an SQL Server version as well as a benchmark.
  <br/><br/></p>
  
  <p>Here is the graph:
  <a href="https://i.stack.imgur.com/eHqzZ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/eHqzZ.jpg" alt="enter image description here"></a></p>
  
  <p>Here is a table version of it:</p>
  
  <p><a href="https://i.stack.imgur.com/SgzD7.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/SgzD7.jpg" alt="enter image description here"></a></p>
  
  <p>Here is the Gremlin query:</p>
  
  <pre><code>g.V('c39f435b-350e-4d08-a7b6-dfcadbe4e9c5')
  .out('follows').as('name')
  .out('took').order(local).by('postedAt', decr).as('id', 'postedAt')
  .select('id', 'name', 'postedAt').by(id).by('name').by('postedAt')
  .limit(10)
  </code></pre>
  
  <p>Here is the equivalent SQL query (linq actually):</p>
  
  <pre><code>Follows
  .Where(f =&gt; f.FollowerId == "c39f435b-350e-4d08-a7b6-dfcadbe4e9c5")
  .Select(f =&gt; f.Followees)
  .SelectMany(f =&gt; f.Photos)
  .OrderByDescending(f =&gt; f.PostedAt)
  .Select(f =&gt; new { f.User.Name, f.Id, f.PostedAt})
  .Take(10)
  </code></pre>
  
  <p>That user follows 136 users who collectively took 257 photos.</p>
  
  <p>Both SQL Server and Cosmos db are in West Europe Azure location. I'm in France.
  I did a bit of testing on Linpad.</p>
  
  <ul>
  <li>The Gremlin Query runs in over 1.20s and consumes about 330 RU. FYI, 400RU/s costs 20$/month.</li>
  <li>The SQL query runs in 70ms. The db is 10 DTU (1 instance of S0). So it costs 12.65eur / month</li>
  </ul>
  
  <p>How can I get the feed faster and cheaper with cosmos db?</p>
  
  <p>Note: In order to get the RU charged, I'm using <code>Microsoft.Azure.Graph</code>. But I can also use <code>Gremlin.Net</code> and get similar results.</p>