跳转到内容

Decision Guide:SQL vs NoSQL(SQL vs 非关系型数据库)

知识库位置:FDE Knowledge Base/03 Engineering/Decision Guides/SQL-vs-NoSQL.md

不要从:

哪个数据库更现代?

开始。

应该从:

数据结构和访问模式(Access Pattern,访问模式)是什么?

开始。

SQL(Structured Query Language,结构化查询语言)数据库更适合当数据具有:

  • 明确 Schema(数据结构定义)
  • 强关系
  • Transaction(事务)
  • Join(关联)
  • Financial or business consistency requirements(财务或业务一致性要求)

典型:

  • Customer(客户)
  • Order(订单)
  • Invoice(发票)
  • Payment(支付)
  • Inventory(库存)

Prefer NoSQL When(倾向 NoSQL 的场景)

Section titled “Prefer NoSQL When(倾向 NoSQL 的场景)”

NoSQL(Not Only SQL,非关系型数据库)更适合当数据具有:

  • Flexible Schema(灵活结构)
  • Large-scale document structure(大规模文档结构)
  • High write throughput(高写入吞吐)
  • 特定 Key-based access pattern(基于键的访问模式)

例如:

  • Session(会话)
  • Flexible Content(灵活内容)
  • Event Document(事件文档)
  • High-volume key-value lookup(高频键值查找)
  1. 是否需要事务?
  2. 是否存在复杂关系?
  3. Schema(数据结构)变化频繁吗?
  4. 主要 Query Pattern(查询模式)是什么?
  5. 数据规模多大?
  6. Consistency(一致性)要求如何?
  7. 团队熟悉哪种数据库?

在很多企业项目中:

PostgreSQL 往往已经足够好。

不要为了「未来可能扩展」过早引入多个数据库。