Kiến trúc
Tổng quan hệ thống
┌──────────────────────────────────────────────────────────┐
│ Ứng dụng Client │
│ (Kết nối TCP) │
└─────────────────────┬────────────────────────────────────┘
│
┌─────────────────────▼────────────────────────────────────┐
│ CacheServer │
│ (TCP Listener) │
├──────────────────────────────────────────────────────────┤
│ Protocol Parser → Request Router → Response Serializer │
└─────────────────────┬────────────────────────────────────┘
│
┌─────────────────────▼────────────────────────────────────┐
│ ConsistentHash (Hash Ring) │
│ key → hash(key) → tìm node chịu trách nhiệm │
└──────┬──────────────┬──────────────┬─────────────────────┘
│ │ │
┌──────▼──────┐ ┌─────▼──────┐ ┌────▼───────┐
│ Node 0 │ │ Node 1 │ │ Node 2 │
│ (RAM Store)│ │ (RAM Store)│ │ (RAM Store)│
│ + LRU │ │ + LRU │ │ + LRU │
│ + TTL │ │ + TTL │ │ + TTL │
│ + Persist │ │ + Persist │ │ + Persist │
└─────────────┘ └────────────┘ └────────────┘
│ │ │
└──────────────┼──────────────┘
│
┌───────▼───────┐
│ Replication │
│ (Cross-node) │
└───────────────┘Các Module
Module 1: Core (types, hashing, node)
↓
Module 2: Strategies (LRU, LFU, FIFO)
↓
Module 3: Network (protocol, server, client)
↓
Module 4: Cluster (election, failover)
↓
Module 5: Replication
↓
Module 6: Invalidation
↓
Module 7: Benchmark
↓
Module 8: Visualizationluồng dữ liệu
Ghi (SET)
1. Client gửi: SET key value ttl
2. Protocol parser trích xuất key, value, ttl
3. ConsistentHash tìm node chịu trách nhiệm
4. Node.set(key, value, ttl)
├── Kiểm tra key tồn tại → cập nhật eviction
├── Tạo CacheEntry với TTL
├── Lưu vào Map
└── Thực thi maxSize (evict nếu đầy)
5. ReplicationManager replicate sang backup nodes
6. Response: OKĐọc (GET)
1. Client gửi: GET key
2. Protocol parser trích xuất key
3. ConsistentHash tìm node chịu trách nhiệm
4. Node.get(key)
├── Kiểm tra key tồn tại
├── Kiểm tra hết hạn (TTL)
├── Cập nhật access stats
└── Trả value
5. Response: VALUE dataTech Stack
| Lớp | Công nghệ | Lý do |
|---|---|---|
| Ngôn ngữ | TypeScript | Type safety, IDE support |
| Runtime | Node.js | Ecosystem, compatibility |
| Hash | murmurhash | Nhanh, distribution tốt |
| Network | TCP sockets | Latency thấp, tương thích Redis |
| Frontend | React + Canvas | Phổ biến, rendering hiệu quả |
| Testing | Jest | Industry standard |
| CI/CD | GitHub Actions | Miễn phí, tích hợp sẵn |
| Build | tsup | Bundler nhanh |