|
1 | | -# 1 — PlantUML code |
2 | | - |
3 | | - |
4 | | -```plantuml |
5 | | -@startuml |
6 | | -' Title |
7 | | -title Materialized Feed Architecture (BullMQ + Redis + MongoDB) |
8 | | -
|
9 | | -actor "Client (Browser / Mobile)" as Client |
10 | | -node "API Server\n(Node.js / Express)" as API |
11 | | -database "MongoDB\nPrimary DB\n(Questions, Likes, Answers)" as Mongo |
12 | | -database "MongoDB\nFeed Collection\n(denormalized)" as FeedDB |
13 | | -folder "Redis\nBullMQ" as Redis |
14 | | -node "Feed Worker\n(BullMQ Worker)" as Worker |
15 | | -node "Backfill Job\n(Batch Script)" as Backfill |
16 | | -cloud "Monitoring / Metrics\n(Prometheus / Grafana)" as Monitoring |
17 | | -
|
18 | | -Client --> API : GET /feed/public |
19 | | -API --> FeedDB : Query feed (fast indexed read) |
20 | | -API --> Mongo : (writes) create Question / Like / Answer / Update |
21 | | -API --> Redis : push job to queue (feed-updates)\n(e.g. like-added, answer-added) |
22 | | -API --> Client : 200 OK (feed JSON) |
23 | | -
|
24 | | -Redis --> Worker : job consumed |
25 | | -Worker --> FeedDB : upsert / $inc (likes,dislikes,replies) |
26 | | -Worker --> Mongo : optionally read question snapshot (on question-created/update) |
27 | | -Worker --> Redis : ack (job completed) |
28 | | -
|
29 | | -Backfill --> Mongo : scan questions, counts |
30 | | -Backfill --> FeedDB : bulk upsert seed / reconcile |
31 | | -
|
32 | | -Monitoring <.. API : metrics |
33 | | -Monitoring <.. Worker : worker metrics |
34 | | -Monitoring <.. Redis : queue depth |
35 | | -
|
36 | | -' Notes |
37 | | -note right of API |
38 | | - - Publish events (like-added, like-removed,\n dislike-added, answer-added, question-created) |
39 | | - - API only pushes job, returns quickly |
40 | | -end note |
41 | | -
|
42 | | -note left of Worker |
43 | | - - Jobs processed concurrently |
44 | | - - Atomic updates with $inc |
45 | | - - Idempotency & retries via BullMQ |
46 | | -end note |
47 | | -
|
48 | | -@enduml |
49 | | -``` |
50 | | - |
51 | | ---- |
52 | | - |
53 | | - |
54 | | -````markdown |
55 | 1 | # Materialized Feed Service (BullMQ + Redis + MongoDB) |
56 | 2 |
|
57 | 3 | ## Overview |
@@ -80,8 +26,9 @@ Reads are fast (single query to `Feed`), and expensive aggregations are handled |
80 | 26 | "likes": 0, |
81 | 27 | "dislikes": 0, |
82 | 28 | "replies": 0 |
83 | | - } |
84 | | -```` |
| 29 | + }``` |
| 30 | + |
| 31 | + |
85 | 32 |
|
86 | 33 | * **Backfill script**: Recompute and populate `Feed` documents from primary DB to recover drift. |
87 | 34 |
|
@@ -163,9 +110,8 @@ Prereqs: Node.js, MongoDB, Redis |
163 | 110 |
|
164 | 111 | MIT |
165 | 112 |
|
166 | | -``` |
167 | 113 |
|
168 | | ---- |
| 114 | + |
169 | 115 |
|
170 | 116 | # 3 — Cause-of-change examples in STAR format |
171 | 117 |
|
@@ -210,4 +156,4 @@ Below are short STAR entries for the common events that cause the feed to change |
210 | 156 | - c) the worker code with idempotency (event dedupe with Redis or Mongo dedupe table)? |
211 | 157 |
|
212 | 158 | Tell me which of (a–c) to deliver next and I’ll produce the code files ready to paste into your project. |
213 | | -``` |
| 159 | + |
0 commit comments