Database Performance Tradeoffs

Ý chính

Database performance không có một đòn tối ưu duy nhất. Mỗi cải tiến đổi chi phí sang chỗ khác: index tăng read speed nhưng làm write chậm; denormalization giảm join nhưng tăng sync complexity; cache giảm load nhưng tạo stale read; sharding scale write nhưng tăng vận hành.

Vòng chẩn đoán

slow path
-> đọc [[Query Execution Plan]]
-> xác định scan/index/join/sort/lock bottleneck
-> sửa query hoặc index
-> kiểm tra schema/partition/workload isolation
-> đo lại latency, throughput, CPU, memory, I/O

Bảng trade-off

Kỹ thuậtGiúpGiá phải trả
Database IndexingRead/filter/join nhanhWrite chậm, storage, maintenance
Database PartitioningScan ít dữ liệu hơnKey sai làm query xuyên partition chậm
DenormalizationRead path nhanhDuplicate data, stale/inconsistency
Materialized ViewQuery phức tạp thành lookupRefresh lag, pipeline vận hành
Read ReplicaScale readReplication lag
Database ShardingScale write/storage ngangCross-shard query, rebalancing, ops complexity
MVCCReader/writer ít block nhauVersion cleanup, conflict semantics

Chọn database

  • SQL Database: ưu tiên schema, constraints, join và transaction correctness.
  • NoSQL Database: ưu tiên scale, schema flexibility hoặc access pattern chuyên biệt.
  • NewSQL: cần SQL/ACID nhưng phải scale phân tán, chấp nhận coordination latency.
  • Document Store: đọc theo aggregate/document, tránh join read-time bằng materialized read model.

Liên kết