title: How to sync the database with the microservices (and the new one)?
body: <p>I'm developing a website with the microservice architecture, and each of the service owns a database. The database stores the data which the microservice needs.</p>
  
  <hr>
  
  <p><code>Post</code>, <code>Video</code> services need the user information, so both of the services subscribed to the <code>NEW_USER_EVENT</code>. </p>
  
  <p>The <code>NEW_USER_EVENT</code> will be triggered when there's a new user registered.</p>
  
  <p><a href="https://i.stack.imgur.com/0SY8a.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0SY8a.png" alt="enter image description here"></a></p>
  
  <p>Once the services received the <code>NEW_USER_EVENT</code>, they put the incoming user information to each of their own database. So they can do things without asking the <code>User</code> service.</p>
  
  <p><a href="https://i.stack.imgur.com/NR8Xk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NR8Xk.png" alt="enter image description here"></a></p>
  
  <p>So far so good. But here comes the question:</p>
  
  <ul>
  <li>What if I'm going to create a new service? How do I get the registered user informations and put them in the new service?</li>
  </ul>
  
  <p>Maybe I can get the informations from the existing services. But the events are pushed by the messaging queue (<code>NSQ</code>). </p>
  
  <p>If I'm going to copy the data from one of the microservices, how do I make sure which service has the latest user informations? (<em>Because some services haven't received the latest event</em>) </p>
  
  <p><a href="https://i.stack.imgur.com/vJoGv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vJoGv.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><em>Read More:</em></p>
  
  <p><a href="http://blog.christianposta.com/microservices/the-hardest-part-about-microservices-data/" rel="noreferrer">The Hardest Part About Microservices: Your Data</a></p>
  
  <p><a href="https://auth0.com/blog/introduction-to-microservices-part-4-dependencies/" rel="noreferrer">Intro to Microservices, Part 4: Dependencies and Data Sharing</a></p>