简体   繁体   English

一个数据库或多个数据库

[英]One Database or multiple Databases

So, today we had long conversation in company between project leader and programmers, shall we run one DB with all tables in it for our new project or to run multiple databases with each DB storing one set of module. 因此,今天我们在项目负责人和程序员之间进行了长时间的交谈,是为新项目运行一个包含所有表的数据库,还是运行多个数据库,每个数据库都存储一组模块。

Project is about shop, we have separate (lets call it modules) such as users, payment methods, products, statistics. 项目是关于商店的,我们有单独的(称为模块),例如用户,付款方式,产品,统计信息。

Now one side said that we should place all of it inside one DB(its standard procedure) because it will be faster, with one query you can get all data, while other side said that we should split it between multiple databases so that its more secure, if someone breaches inside products, they wont see users tables as that DB will be on different server or virtual machine. 现在,一侧说我们应该将所有数据放入一个数据库(它的标准过程)中,因为这样做会更快,用一个查询就可以获取所有数据,而另一侧则说我们应该将其拆分到多个数据库中,以便更多安全,如果有人破坏产品内部,他们将不会看到用户表,因为该数据库将位于不同的服务器或虚拟机上。

So my question is, what are pros and cons of having single DB for all data VS having multiple databases. 所以我的问题是,对于具有多个数据库的所有数据VS使用单个DB的优缺点是什么? I read few questions on stack-overflow, but none of them were precisely about pros and cons. 我读到的关于堆栈溢出的问题很少,但没有一个恰恰是关于利弊的问题。 And if having multiple databases is slower, how to speed it up? 而且,如果拥有多个数据库的速度较慢,如何加快速度?

Thanks! 谢谢!

Rather than providing you generic pros/cons (because everything depends on the use case...), I would say that we tend to prematurely optimize systems while optimization shouldn't be a problem in the future, if the whole system is architected with refactoring in mind. 我不会说给您通用的利弊(因为一切都取决于用例...),我想说的是我们倾向于过早地优化系统,而将来如果整个系统的架构都没有问题,那么优化就不会成为问题。重构思想。

IMHO, I had the same discussion some time ago and my conclusion is starting with a single database. 恕我直言,我前段时间进行了同样的讨论,我的结论是从一个数据库开始的。 It simplifies a lot of details: 它简化了很多细节:

  • Single database to backup, less maintainance. 单个数据库即可备份,维护较少。
  • You don't need to manage multiple connections. 您无需管理多个连接。
  • Multiple databases can break the chance to perform atomic transactions, a feature I would never throw away. 多个数据库可以打破执行原子事务的机会,这是我永远不会放弃的功能。
  • You avoid synchronizing two or more databases to avoid integrity problems. 您避免同步两个或多个数据库以避免完整性问题。

Also, since we're in the cloud computing era, infrastructures should scale horizontally. 另外,由于我们处于云计算时代,因此基础架构应该水平扩展。 That is, if you need more power, add a replication node and distribute your load across multiple servers instead of scaling in the application level. 也就是说,如果需要更多功能,请添加复制节点并在多台服务器之间分配负载,而不是在应用程序级别扩展。 This ensures your software will be still easy to maintain and develop, and good solutions should scale out easily if your code has quality and, of course, you've budget to support an increased load! 这样可以确保您的软件仍将易于维护和开发,并且如果代码具有质量,并且当然您有预算来支持增加的负载,那么好的解决方案应该可以轻松地横向扩展!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM