Module 1 — Kiến trúc (bấm vào từng tầng)
Service chỉ phụ thuộc interface của 4 tầng. Bấm từng hộp để xem tầng đó làm gì và có thể swap sang backend thật nào.
handler — lớp HTTP (request → JSON)
▼
service — LOGIC (cache-aside · index · transaction · invalidation)
▼ (qua interface)
storage
Repository
Repository
cache
Cache + TTL
Cache + TTL
search
InvertedIndex
InvertedIndex
migration
version tracker
version tracker
Bấm một tầng để xem chi tiết.
Module 2 — Request flow
Mô phỏng hai luồng quan trọng nhất. Bấm nút để chạy từng bước.
2a. Create post → write storage + index search
1. validate — title không rỗng?
2. repo.CreatePost — gán id, lưu storage (Postgres)
3. index.AddOrUpdate — tokenize title+body → posting list
4. (không invalidate) — post mới chưa từng được cache
→ 201 Created
2b. Get post → cache-aside (cache → miss → storage → populate)
hits=0 · misses=0
cache.Get("post:3")
repo.GetPost(3) — chỉ chạy khi MISS
cache.Set("post:3", ttl=5m) — populate (chỉ sau MISS)
→ trả post
Lần 1: cache trống → MISS → xuống storage → nạp cache. Lần 2: HIT → không chạm storage.
Module 3 — Search demo (inverted index + TF-IDF)
Corpus 4 bài (N=4). Nhập từ khoá → tra inverted index → tính điểm TF-IDF → xếp hạng.
| id | title | body (rút gọn) | tags |
|---|---|---|---|
| 1 | Go concurrency patterns | goroutines channels concurrent | go, concurrency |
| 2 | Postgres indexing tips | btree index query write | postgres, database |
| 3 | Redis cache strategies | cache aside pattern read heavy | redis, cache |
| 4 | Full text search inverted index | inverted index term document tfidf | search, database |
Thử nhanh: