Database
D2 · Resilient
D3 · Performance
~1 phút đọc

DynamoDB — NoSQL serverless ở scale

Key-value & document, latency ms, multi-region active-active. Nắm capacity modes, index, streams, caching (DAX).

dynamodb
nosql
dax
global-tables

Sơ đồ tổng quan

Đang tải sơ đồ…

Capacity modes

  • On-Demand: pay per request; tự scale, không cần plan, đắt hơn provisioned khi load ổn định.
  • Provisioned: set RCU/WCU, bật Auto Scaling; rẻ khi traffic ổn định.
  • 1 RCU = 1 strongly-consistent read 4 KB/s (hoặc 2 eventually-consistent). 1 WCU = 1 KB/s.

Key & index

  • Partition key (HASH) quyết định partition. Composite key = HASH + SORT (RANGE).
  • LSI (Local Secondary Index): cùng PK, khác SK; tạo lúc tạo table, tối đa 5.
  • GSI (Global Secondary Index): PK & SK khác hẳn; tạo/xóa bất cứ lúc nào; có capacity riêng.
  • Hot partition: tránh key bị skew; bật adaptive capacity.

Nâng cao

  • DynamoDB Streams: change log 24h → Lambda trigger cho CDC.
  • TTL: tự xóa item sau epoch time.
  • Transactions: ACID cho tới 100 item hoặc 4 MB.
  • Global Tables: multi-region multi-active, replication tầm ms.
  • DAX: in-memory cache µs latency, API-compatible — thay drop-in cho read-heavy.
Tip
So sánh cache: ElastiCache cho bất kỳ DB, code thay đổi. DAX tích hợp trong suốt cho DynamoDB.