title: Microservices and database
body: <p>What is the best practice to deploy database in microservices architecture, more precisely in distributed environment, such as docker swarm? Microservices principles states each service should be stateless to enable scaling. As database obviously has a state, should it live at fixed position outside of cluster, deployed and configured before the cluster is initialized?</p>
  
  <p>I'm confused, because all docker compose examples includes database container in the service definition. But things aren't that simple. Often the database needs a lot of configuration before it's ready to use. Also, docker sucks at coordinating the service starting order.</p>
  
  <p>If it's really a good practice to deploy the database alongside with services to docker swarm, how to ensure consistency and persistence of cricial data?</p>