title: Node API Architecture on AWS
body: <p>I'm making an app that will have:  </p>
  
  <ul>
  <li>iOS and Android apps</li>
  <li>A web-based "dashboard" to display data gathered from the mobile apps</li>
  </ul>
  
  <p>The app requires that end-users create an account with us (we mostly likely will NOT use Facebook/Twitter logins).</p>
  
  <p>Everything is/will be hosted on AWS using EC2/RDS/S3 (All encapsulated in Elastic Beanstalk)</p>
  
  <pre><code>| Web Browser |  &lt;----&gt; | sails.js app | &lt;-------&gt; |actionhero.js API|
  
                                                          ⬆︎  
                                                          ⬆︎
  | Mobile app(s) | &lt;-------------------------------------/
  </code></pre>
  
  <p>So far, I've built most of the backing API in actionhero.js, hosted on AWS.</p>
  
  <p>It made sense to me to separate the API and the web app, because there web app is only for a small subset of users -- I'd expect 50x the traffic from our mobile apps over the web app.. We could scale the API to server the mobile users without unnecessarily scaling the sails.js app.</p>
  
  <hr>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li><p>(<em>biuggest unknown</em>) <strong>How should I handle authentication?</strong>   The <code>sails.js</code> app needs to be able to make requests to the API, and so do the mobile applications. </p>
  
  <p>I was looking at the <code>oauth2orize</code> node module for creating our own Auth server, but it is designed for Connect/Express, so I don't think I could leverage it in the actionhero.js-based API.</p>
  
  <p>If the solution is to create an OAuth server, am I supposed to host that on its own EC2 instance?</p></li>
  <li><p>(AWS-specific question) I don't fully understand the use case for creating what AWS describes as a "worker tier" enviornment.  Would there be a reason that the API would fall into that category?</p></li>
  <li><p>If I want to run a data querying and aggregation task, I would create a separate node process for that, correct?  If so, <strong>would that background worker have to exist on its own EC2 instance?</strong></p></li>
  <li><p>Sails.js and Actionhero.js both provide heavy support for socket.io.  Should communication between the Sails app and my API happen over a persistent WebSocket connection?  Will that scale if I need to create new instances in the future?</p></li>
  </ol>
  
  <p>This seems like a fairly typical pattern; I'd like to hear if there are any big red flags in this design, <em>before</em> I paint myself into a corner.  :-)   THANKS!</p>
  
  <p><strong>Bonus question</strong> (specific to AWS Elastic Beanstalk)</p>
  
  <p>Will I create separate "Applications" for the sails.js server and the API server? It looks like that's the only way to set it up, anyhow, but I want to make sure.</p>