Skip to content

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: Visualization

luồ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 data

Tech Stack

LớpCông nghệLý do
Ngôn ngữTypeScriptType safety, IDE support
RuntimeNode.jsEcosystem, compatibility
HashmurmurhashNhanh, distribution tốt
NetworkTCP socketsLatency thấp, tương thích Redis
FrontendReact + CanvasPhổ biến, rendering hiệu quả
TestingJestIndustry standard
CI/CDGitHub ActionsMiễn phí, tích hợp sẵn
BuildtsupBundler nhanh

Released under the MIT License.