Best practice or design to scale out/horizontal scale database for microservices

ε祈祈猫儿з 提交于 2019-12-11 02:22:40

问题


The main benefit of Microservices are one Service “Type” can be scale out by using multiple container instances and load-balancing to improve through put.

But one things is, multiple instances (ie. containers) of a "Service Type" are sharing the same database instance; and this could leave to performance bottle neck when multiple instance write/read on that database instance.

Traditionally, we would scale up on the processing power of that database instance to meet high demand.

The main questions for me is, what is the current best practice/design/solution to scale out/ horizontal scale so we can have multiple instance of that database and having performance improvement?

In particular, what I want to archive are:

  • One instance is down, a nother instance can handle the load -> High Availability

  • Can load balance read, or maybe even write to multiple database intance

  • Maintain the persistent and consistency of data incase I want to create more database-instance

Within my knowledge,

One of the solution is Microsoft SQL Server provide High availability for SQL Server containers with can do most of the requirements above (https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-container-ha-overview?view=sql-server-2017). But I'm wonder is there a better solution to avoid technology lock-down?

Another solution which I'm thinking of is: Replicate to multiple instance by using CDC Stream Data from a master database instance to multiple replications. This allow replication read.

But I'm still not convince because to quarrant the consistency, every services instance should write to master-database-instance, this could also, leave to bottle neck on master database instance.


回答1:


There are 3 possible architectures for database at a broad level:

  1. Single leader (e.g. RDBMS)
  2. Multi leader (e.g. RDBMS in multiple DC)
  3. Leader less (e.g. Riak, Cassandra)

As you go from top to bottom in the above list, horizontal scalability potential increases, but consistancy becomes weaker.

Scalability potential increases because more nodes can accept writes as you go down the list. Consistancy becomes weaker as writes take time to propagate or replicate to all nodes responsible for the data. Conflicts arise when same record is written in two different nodes at almost same time and so at the time of replication the system does not know which one is correct.

There are various conflict resolution strategies. Different database use different strategies. You need to study these strategies to understand which one suits your usecase and based on that you pick your DB.




回答2:


There is always a trade off when making choices . database has its limitations and despite scaling database we can avoid performace hit by using simple best practices. you can't leave it to database to handle high request rate and mind it scaling database is expensive option and you will hit database limits eventually if not taken right so plan the whole system than just database.

coming to your point you can have one master and slave for read and write separately is very common approach but you have to rely on eventual consistency and sql always on is something you can have a look. You can cache the most frequently data. If you have very high request rate you may need to consider queues where you put the request and dequeue later to avoid database performance hit.



来源:https://stackoverflow.com/questions/54771633/best-practice-or-design-to-scale-out-horizontal-scale-database-for-microservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!