title: Express/NodeJS + Mongoose App server response slow
body: <h3>Issue</h3>
  
  <p>I have an Express (Node.JS) + MongoDB app with a server response load time of 4 - 7 seconds on average (slow).</p>
  
  <p>I understand that the average server response time is under 200ms as per <a href="https://developers.google.com/speed/docs/insights/Server" rel="noreferrer">google pagespeed tools</a>.</p>
  
  <p>This app is fetching data from a mongoDB asynchronously but the roundtrip times to the database is extremely slow with each call averaging about 500ms - 1s. These calls are simple findAll calls to retrieve data of less than &lt; 100 records.</p>
  
  <h3>Context</h3>
  
  <ul>
  <li>Mongoose version: 4.13.14</li>
  <li>DB server's MongoDB version is 3.4.16</li>
  <li>DB server is hosted on MongoDB Atlas M10 in AWS / Oregon (us-west-1)</li>
  <li>Web server is hosted with now.sh in SFO1 (us-west-1)</li>
  <li>Have performed recommended indexes as advised by MongoDB Atlas's performance advisor</li>
  <li>Data fetching perfectly fine in local environment (local server + local db) as data is queried in a matter of few ms</li>
  <li>Mongoose logs for the affected page can be found in this <a href="https://gist.githubusercontent.com/clodal/ff1d5da3b326f7cea33af5bbfe1167ee/raw/1b45533e79a818baea6480e93b06637bb1ab9e9d/debug-mongoose-logs.md" rel="noreferrer">gist</a></li>
  </ul>
  
  <h3>Mongo Server configuration</h3>
  
  <ul>
  <li>Mongo Atlas M10</li>
  <li>2GB Ram</li>
  <li>10 GB Storage</li>
  <li>100 IOPS</li>
  <li>Encrypted</li>
  <li>Auto-expand storage</li>
  </ul>
  
  <h3>Attempted solutions:</h3>
  
  <p>I have checked my DB metrics, they looked fine. There are also no slow queries. These are simple findAll queries. Performance advisor on mongo atlas reports nothing unusual.</p>
  
  <p>The production application and database are both hosted in the same region.</p>
  
  <p>I have already tried optimising the application layer of the query (mongoose) by running .lean()</p>
  
  <h3>Question:</h3>
  
  <p>Where else should i look to improve the database latency? How can a simple query take so long? Otherwise, why is my server response time taking up to 4s when the expected is about 200ms?</p>