Skip to content

Commit f1cc61f

Browse files
committed
Wave 2 batch 2c: mermaid in 019, 025, 026, 033
019 Same Query Different Answers, ordered triage checklist as a mermaid flow with the most likely cause in red. 025 Smart Meter to Monthly Bill PDF, end-to-end flow from meter raw to PDF delivery, showing sealed-bill immutability. 026 Delivery Idle Driver Tracking, Kafka -> Flink -> Redis -> dispatch architecture, plus the driver state machine as a real state diagram (login, on_trip, break). 033 Executive Needs a Number Tomorrow, CAC summary as a markdown table instead of an ASCII grid. 018, 029, 030, 031, 032, 034 had no ASCII art to convert, only SQL code blocks. Left as is.
1 parent 8117ed2 commit f1cc61f

4 files changed

Lines changed: 80 additions & 118 deletions

File tree

problems/019-same-query-different-answers/solution.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@
66
77
### My mental order of checks
88

9+
```mermaid
10+
flowchart TB
11+
A([1. Time zone difference?])
12+
B([2. Row-level security / filtered views?])
13+
C([3. Late-arriving rows? Snapshot timing?])
14+
D([4. Are you really reading the same table?])
15+
E([5. Session settings, date format, locale?])
16+
F([6. Collation, case sensitivity, trim?])
17+
G([7. Materialized views or aggregated layers?])
18+
19+
A --> B --> C --> D --> E --> F --> G
20+
21+
style A fill:#fecaca,stroke:#b91c1c,color:#7f1d1d
22+
style B fill:#fed7aa,stroke:#c2410c,color:#7c2d12
23+
style C fill:#fed7aa,stroke:#c2410c,color:#7c2d12
24+
style D fill:#fef3c7,stroke:#a16207,color:#713f12
25+
style E fill:#fef3c7,stroke:#a16207,color:#713f12
26+
style F fill:#dbeafe,stroke:#1e40af,color:#1e3a8a
27+
style G fill:#dbeafe,stroke:#1e40af,color:#1e3a8a
928
```
10-
1. Time zone difference? ← starts here most often
11-
2. Row-level security / views the user can see?
12-
3. Late-arriving rows: when was each snapshot taken?
13-
4. Are you really reading the same table?
14-
5. Session settings (date format, locale, NULLs ordering)?
15-
6. Collation / case sensitivity / trim differences?
16-
7. Materialized views or aggregated layers?
17-
```
29+
30+
About 90% of the time it's one of the first three.
1831

1932
Let me walk through each.
2033

problems/025-smart-meter-to-monthly-bill-pdf/solution.md

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,23 @@
22

33
### The whole flow at a glance
44

5-
```
6-
┌──────────────────────────┐
7-
│ Meter readings (15-min) │
8-
│ s3://meter-raw/... │
9-
└────────────┬─────────────┘
10-
│ parser, validation
11-
12-
┌──────────────────────────┐
13-
│ Curated 15-min fact │ (reads_15min, partitioned by date)
14-
└────────────┬─────────────┘
15-
16-
17-
┌──────────────────────────────────────────────┐
18-
│ Billing calc job │
19-
│ (runs once per customer per billing period) │
20-
│ │
21-
│ Inputs: │
22-
│ - reads_15min for the period │
23-
│ - tariffs (SCD2) │
24-
│ - customers (dim) │
25-
│ - account_adjustments │
26-
│ │
27-
│ Output: one bill row + bill_lines │
28-
└────────────┬─────────────────────────────────┘
29-
30-
31-
┌──────────────────────────┐
32-
│ bills (sealed) │ immutable once issued
33-
│ bill_lines │
34-
└────────────┬─────────────┘
35-
36-
37-
┌──────────────────────────┐
38-
│ PDF rendering service │ pure function of bill_id
39-
│ (deterministic) │
40-
└────────────┬─────────────┘
41-
42-
43-
┌──────────────────────────┐
44-
│ Customer portal + │
45-
│ email delivery │
46-
└──────────────────────────┘
5+
```mermaid
6+
flowchart TB
7+
M([Meter readings, 15-min<br/>s3://meter-raw/...])
8+
C([Curated 15-min fact<br/>reads_15min<br/>partitioned by date])
9+
B([Billing calc job<br/>per customer per period<br/>uses reads_15min + tariffs (SCD2)<br/>+ customers + adjustments])
10+
S([bills (sealed) + bill_lines<br/>immutable once issued])
11+
P([PDF rendering service<br/>deterministic, pure function of bill_id])
12+
D([Customer portal + email delivery])
13+
14+
M --> C --> B --> S --> P --> D
15+
16+
style M fill:#fef3c7,stroke:#a16207,color:#713f12
17+
style C fill:#fef3c7,stroke:#a16207,color:#713f12
18+
style B fill:#dbeafe,stroke:#1e40af,color:#1e3a8a
19+
style S fill:#fed7aa,stroke:#c2410c,color:#7c2d12
20+
style P fill:#dbeafe,stroke:#1e40af,color:#1e3a8a
21+
style D fill:#dcfce7,stroke:#15803d,color:#14532d
4722
```
4823

4924
The principle: each step is a function of the layer beneath it. Re-run the same step on the same inputs and you get the same output. The PDF is the last and least interesting step.

problems/026-delivery-idle-driver-tracking/solution.md

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,46 @@
22

33
### The shape of the system
44

5-
```
6-
Driver app Trip system
7-
sends ping every 5 sec emits trip events
8-
│ │
9-
▼ ▼
10-
─────────────────────────────────────────────
11-
Kafka
12-
┌─────────────┐ ┌──────────────────┐
13-
│ driver_ping │ │ trip_status │
14-
│ topic │ │ topic │
15-
└──────┬──────┘ └────────┬─────────┘
16-
│ │
17-
└────────┬───────────┘
18-
19-
┌────────────────────────────────────────┐
20-
│ Stream processor (Flink) │
21-
│ │
22-
│ Keyed by driver_id, holds the state: │
23-
│ online | on_trip | break | offline │
24-
│ Updated by pings + trip events. │
25-
│ │
26-
│ For idle drivers, emits to │
27-
│ the "idle drivers" store keyed by H3. │
28-
└────────────────┬───────────────────────┘
29-
30-
31-
┌─────────────────────────────────────────┐
32-
│ Live driver store │
33-
│ Redis / DragonflyDB / Aerospike │
34-
│ │
35-
│ Per-driver hash: { state, lat, lng, │
36-
│ h3, last_ping } │
37-
│ TTL: 60 sec (auto-expire stale) │
38-
│ │
39-
│ Index: H3 -> set of driver_ids │
40-
└────────────────┬────────────────────────┘
41-
42-
43-
┌─────────────────────────────────────────┐
44-
│ Dispatch service │
45-
│ Query: "idle drivers within 1.5 km │
46-
│ of (lat, lng)" │
47-
│ → resolves to hex + neighbors, │
48-
│ reads sets, returns up to N drivers │
49-
└─────────────────────────────────────────┘
5+
```mermaid
6+
flowchart TB
7+
DA([Driver app<br/>ping every 5s])
8+
TR([Trip system<br/>trip events])
9+
KP([Kafka: driver_ping])
10+
KT([Kafka: trip_status])
11+
FL([Flink stream processor<br/>keyed by driver_id<br/>state: online / on_trip / break / offline<br/>emits idle drivers keyed by H3])
12+
STORE([Live driver store<br/>Redis / DragonflyDB<br/>per-driver hash with TTL 60s<br/>H3 index to driver set])
13+
DISP([Dispatch service<br/>query: idle drivers within 1.5 km<br/>resolves to hex + neighbors])
14+
15+
DA --> KP --> FL
16+
TR --> KT --> FL
17+
FL --> STORE --> DISP
18+
19+
style DA fill:#dcfce7,stroke:#15803d,color:#14532d
20+
style TR fill:#dcfce7,stroke:#15803d,color:#14532d
21+
style KP fill:#fed7aa,stroke:#c2410c,color:#7c2d12
22+
style KT fill:#fed7aa,stroke:#c2410c,color:#7c2d12
23+
style FL fill:#dbeafe,stroke:#1e40af,color:#1e3a8a
24+
style STORE fill:#dbeafe,stroke:#1e40af,color:#1e3a8a
25+
style DISP fill:#fed7aa,stroke:#c2410c,color:#7c2d12
5026
```
5127

5228
### The driver state machine
5329

54-
Drivers move between a few states:
55-
56-
```
57-
login start_trip
58-
offline ────▶ online ────────▶ on_trip
59-
▲ ▲ ▲ │
60-
│ │ │ end_trip │
61-
│ logout │ └──────────────┘
62-
└───────────┘
63-
break_start ┌─▶ break ─┐ break_end
64-
│ ▼
65-
└─── back to online
30+
Drivers move between four states:
31+
32+
```mermaid
33+
stateDiagram-v2
34+
[*] --> offline
35+
offline --> online: login
36+
online --> offline: logout
37+
online --> on_trip: start_trip
38+
on_trip --> online: end_trip
39+
online --> break: break_start
40+
break --> online: break_end
6641
```
6742

43+
Only `online` is idle.
44+
6845
Only `online` is idle. The stream processor maintains this state per driver from two streams:
6946

7047
* `driver_ping` (every 5 sec, with location, app says "online or break")

problems/033-executive-needs-a-number-tomorrow/solution.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ Most of the time, "directional tonight" is the answer. The exec needs a number t
2222

2323
One number per channel, plus a comparison metric they'll want next.
2424

25-
```
26-
Channel CAC last quarter vs last year
27-
─────────────────────────────────────────────
28-
Paid Search $42 +12%
29-
Social $61 +18%
30-
Affiliate $28 -4%
31-
Referral $9 +2%
32-
Organic $3 -1%
33-
─────────
34-
Blended $34 +9%
35-
```
25+
| Channel | CAC last quarter | vs last year |
26+
| --- | ---: | ---: |
27+
| Paid Search | $42 | +12% |
28+
| Social | $61 | +18% |
29+
| Affiliate | $28 | -4% |
30+
| Referral | $9 | +2% |
31+
| Organic | $3 | -1% |
32+
| **Blended** | **$34** | **+9%** |
3633

3734
The "vs last year" is unsolicited but always asked next. Saves the second round.
3835

0 commit comments

Comments
 (0)