title: How to Handle two http requests from a distributed system?
body: <p>We have an application where users can sign in only with Facebook. On successful Facebook login an another http rest call is made to store the name, email and some other information from Facebook login provider. We would end up with data consistency issues if The second RESTful service fail to store the information from fb to the the Mongodb</p>
  
  <ol>
  <li>User can only signup/ sign in via Facebook </li>
  <li>On every successful signup Facebook sends back the some information like the users name, email and uid </li>
  <li>We then store this information on our database immediately </li>
  </ol>
  
  <p>So if the 3rd step fails, we loose the information about the user who signed up via Facebook.</p>
  
  <pre><code>loginWithFacebook() {
        const provider = new firebase.auth.FacebookAuthProvider();
        provider.addScope('user_birthday');
        provider.addScope('user_friends');
        provider.addScope('user_gender');
        return new Promise&lt;any&gt;((resolve, reject) =&gt; {
          this.afAuth.auth
          .signInWithPopup(provider) // a call made to sign up via fb
          .then(res =&gt; {
            if (res) {
              resolve(res);
              if (res.additionalUserInfo.isNewUser) { // creatin profile only if he is a new user
                this.createProfile(res); // a call to store the response in the db
              }
              this.setTokenSession(res.credential.accessToken);
            }
          }, err =&gt; {
            console.log(err);
            reject(err);
          })
        })
      }
  </code></pre>
  
  <p>Is there a neat architectural way of orchestrating this?</p>