flowchart TB
C1["Consume batch
up to 1,000 statements or 200ms (Kafka Consumer Batch Window)"]:::main
C2["Pseudonymize + resolve + enrich"]:::main
C3["BKT Streaming Update
per (student, concept), in partition order"]:::main
C4["Write batch to ClickHouse
ReplacingMergeTree Dedup absorbs redelivered rows"]:::main
C5["Checkpoint mastery state
Compacted State Checkpoint topic"]:::ckpt
C6["Commit Kafka offset"]:::main
L1["Late Arrival Detector
statement far behind the watermark"]:::late
L2["Enqueue Targeted Replay Command
scoped to (student, concept)"]:::late
L3["Recompute mastery trajectory in order
directly from the ClickHouse log"]:::late
C1 --> C2 --> C3 --> C4 --> C5 --> C6
C1 --> L1
L1 --> L2 --> L3
L3 --> C5
classDef main fill:#2a9d8f,stroke:#1f7a6f,color:#fff,font-size:13px
classDef late fill:#e9a23b,stroke:#b8791f,color:#222,font-size:13px
classDef ckpt fill:#7b6cc4,stroke:#544a91,color:#fff,font-size:13px
linkStyle default stroke:#999,stroke-width:2px