Amazon DynamoDB
Managed NoSQL, single-digit ms latency, scales to millions of requests per second. The exam tests key design (PK · PK+SK), LSI vs GSI, TTL, Streams, DAX, and Global Tables.
NoSQL managed, độ trễ vài ms, scale tới hàng triệu request/giây. Bài exam kiểm tra key design (PK · PK+SK), LSI vs GSI, TTL, Streams, DAX, Global Tables.
✓ Reach for it✓ Nên chọn
- Predictable access by key (user profile, session, feature flag)Access theo key dễ đoán (profile, session, feature flag)
- Massive scale with low ops overheadScale khủng, ops nhẹ
- Multi-region active-active (Global Tables)Multi-region active-active (Global Tables)
- Serverless-friendly (matches Lambda scaling)Serverless-friendly (khớp Lambda scaling)
✗ Avoid✗ Tránh
- Ad-hoc analytics / joins → Redshift or AthenaAnalytics / join tuỳ ý → Redshift, Athena
- Items > 400 KB → store blob in S3, keep pointer hereItem > 400 KB → lưu blob ở S3, ở đây chỉ giữ pointer
- Full-text search → OpenSearchFull-text search → OpenSearch
- Strong relational modeling / joins → AuroraModel quan hệ / join phức tạp → Aurora
Primary key shapesDạng primary key
Pick PK-only for lookup-by-id. Add a sort key when you need "get all items for a user, ordered by time". Chọn PK không SK cho lookup theo id. Thêm sort key khi cần "lấy hết item của 1 user, sắp theo thời gian".
LSI vs GSILSI vs GSI
| LSI · Local Secondary Index | GSI · Global Secondary Index | |
|---|---|---|
| Partition keyPartition key | Same as tableCùng bảng | DifferentKhác |
| Sort keySort key | Different from tableKhác bảng | AnyTuỳ |
| When definedĐịnh nghĩa khi | At table creation onlyChỉ khi tạo bảng | AnytimeBất kỳ lúc nào |
| CapacityCapacity | Shares table'sDùng chung với bảng | Own RCU/WCURCU/WCU riêng |
Streams, TTL, Global TablesStreams, TTL, Global Tables
- TTL — set an epoch attribute per item; deletes are best-effort, typically within a few days — don't rely on it for locks/state. Deletes fire on Streams (free WCU). TTL — gán epoch attribute; xoá best-effort, thường trong vài ngày — đừng dựa vào nó cho lock/state. Xoá cũng bắn Streams (không tốn WCU).
- Streams — 24 h retention, order preserved per partition. Lambda / EC2 consumers. Streams — giữ 24 giờ, giữ order trong 1 partition. Consumer là Lambda / EC2.
-
Kinesis Data Streams for DDB — same item-level events, retention up to 1 yr, plug into Firehose / Flink. Gotcha: no order guarantee, possible duplicates — dedupe via
ApproximateCreationDateTime. DDB Streams stays ordered + exactly-once. Kinesis Data Streams for DDB — cùng event item-level, giữ tới 1 năm, cắm Firehose / Flink. Gotcha: không đảm bảo order, có thể trùng — dedupe bằngApproximateCreationDateTime. DDB Streams thì vẫn ordered + exactly-once. - Global Tables — active-active replication. Requires Streams. Default mode = async, last-writer-wins conflict resolution. Great for low RTO / DR / global low latency. Global Tables — replication active-active. Cần Streams. Mode mặc định = async, xung đột giải quyết kiểu last-writer-wins. Tốt cho RTO thấp / DR / latency toàn cầu.
- Multi-Region strong consistency (MRSC) option — RPO 0, read latest from any region. Needs 3 Regions (3 replicas, or 2 + a witness). Choose it at table creation for the strict-consistency-across-regions scenario. Tuỳ chọn Multi-Region strong consistency (MRSC) — RPO 0, đọc data mới nhất từ mọi region. Cần 3 Region (3 replica, hoặc 2 + 1 witness). Chọn lúc tạo bảng cho scenario cần strict consistency đa region.
DAX — cache in frontDAX — cache đằng trước
In-memory, sub-ms reads, 5-min TTL default, up to 11 nodes (1 primary + 10 replicas), multi-AZ (min 3 for prod). Fixes hot-key reads. Gotcha: strongly consistent reads bypass the cache. Cache in-memory, đọc dưới ms, TTL mặc định 5 phút, tối đa 11 node (1 primary + 10 replica), multi-AZ (prod ≥ 3). Giải quyết hot-key đọc. Gotcha: đọc strongly consistent bỏ qua cache.
| DAX | ElastiCache | |
|---|---|---|
| Use forDùng cho | Item / row cachingCache item / row | Session, computed results, aggregatesSession, kết quả tính toán, aggregate |
| App changesSửa app | None — SDK-compatibleKhông — SDK tương thích | Needs client codeCần code client |
| Fits underĐặt trước | DynamoDB | RDS · custom compute |