Modding · Reading list · Building an internal platform with modding-books from scratch: architecture and decision log

449
MOr/modding-books·posted by linlin·32 minutes agoReview

Building an internal platform with modding-books from scratch: architecture and decision log

Some background first. Our setup is modding-books plus three downstream services, seven figures of daily requests, peaking around nine in the evening.

-- The query that broke: a full scan over 20M rows.
-- A composite index took P99 from 1.8s down to 42ms.
SELECT id, title, created_at
  FROM posts
 WHERE community_id = ?
   AND status = 1
 ORDER BY score DESC
 LIMIT 20;

Worth noting: the official docs do cover this, just in a very inconspicuous spot. I only found it reading the source comments, where the author explains the reasoning — roughly "so that it degrades into predictable behaviour in extreme cases".

The first thing was to collapse the variables. We were changing config and upgrading the version at the same time, and afterwards nobody could say which change caused what. We rolled back to moving one variable at a time, re-ran three times, and only then did the curve settle. Tedious, but not skippable.

What genuinely surprised me was the tail. The average looked great while P99 jumped by an order of magnitude past some threshold. The cause was not modding-books itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

We also fixed monitoring along the way: replaced average-based alerts with percentiles and split them per endpoint. False alerts dropped by about seventy percent and the on-call rotation visibly cheered up.

181 comments

181 comments

· first 120 loaded
M
Kkernel_panic·3 minutes ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

520
Mmike_xuOP·3 minutes ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

177
Nnikic·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

56
Rrase·1 hour ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

380
Nnikic·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

324
Lli_ming·2 days ago

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

1
Rran_bo·1 hour ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

97
Lli_ming·yesterday

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

47
RraseMod·2 days agoedited

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

1
Lli_ming·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

1
Mmike_xu·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

2
Kkernel_panic·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

42
Sslow_query·2 days ago

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

488
Rrase·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

426
Zzhu_zong·2 days agoedited

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

417
LlinlinMod·12 minutes ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

399
Llinlin·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

260
LlinlinOP·yesterday

Saved. I am reworking this area this week — this saves a lot of wrong turns.

244
Rran_bo·5 hours ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

444
Bbob_chen·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

427
Llinlin·2 days ago

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

68
Zzhou_yi·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

224
Llinlin·just now

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

386
Mmike_xu·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

337
Nnikic·5 hours ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

79
Zzhu_zongOP·12 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

113
Rran_bo·5 hours ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

2
Rran_bo·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

390
Llinlin·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

356
Oops_wang·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

345
Cchen_dev·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

337
Sslow_query·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

24
Rran_bo·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

292
Wwinter·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

257
Rran_boMod·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

253
Zzhu_zong·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

229
Rran_bo·12 minutes ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

227
Kkernel_panic·28 minutes ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

217
Ttang_hao·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

295
Ddev_zhou·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

217
Lli_ming·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

212
Zzhou_yi·2 days ago

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

6
Mmike_xuOP·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

149
Lli_ming·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

9
Sslow_query·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

203
Ttang_haoOP·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

140
Wwinter·2 days ago

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

21
Cchen_dev·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

197
Cchen_dev·5 hours ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

185
KkiteMod·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

420
Wwinter·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

184
Kkernel_panic·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

178
Hhuang_ke·12 minutes ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

163
Rran_bo·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

150
Ddev_zhou·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

224
Sswoole_leeOP·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

24
Wwinter·12 minutes agoedited

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

408
Oops_wang·3 minutes ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

144
Ttang_hao·28 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

319
Mmike_xu·just nowedited

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

409
Ttang_hao·just now

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

5
Bbob_chenOP·2 days ago

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

191
Ttang_hao·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

110
Lli_ming·28 minutes ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

65
Sswoole_lee·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

462
Rrase·yesterday

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

323
Aalice_dev·2 hours agoLevel 6

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

183
Rrase·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

1
Cchen_dev·28 minutes agoeditedLevel 6

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

45
Zzhu_zong·1 hour ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

22
Bbob_chen·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

1
Mmike_xu·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

110
Bbob_chen·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

99
Llinlin·2 days agoedited

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

95
Llinlin·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

84
Rran_bo·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

84
Rrase·1 hour ago

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

63
Rran_bo·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

52
Lli_mingMod·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

43
Lli_ming·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

30
Kkite·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

42
Kkite·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

37
Kkernel_panic·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

397
Llinlin·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

32
Nnikic·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

29
Rran_bo·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

293
Nnikic·just now

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

23
Sslow_query·just now

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

152
Sswoole_lee·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

36
Zzhu_zong·5 hours ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

22
Llinlin·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

25
LlinlinMod·5 hours ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

237
Wwinter·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

317
Ddev_zhou·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

16
Hhuang_ke·2 days ago

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

168
Zzhou_yi·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

9
Ddev_zhou·yesterday

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

7
Kkite·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

5
Rran_bo·2 hours ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

1
Wwinter·yesterday

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

422
Cchen_dev·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

134
Wwinter·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

105
Lli_ming·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

5
Zzhou_yi·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

36
Bbob_chen·5 hours ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

194
Hhuang_ke·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

135
Kkernel_panic·2 days ago

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

49
Aalice_dev·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

371
Zzhu_zong·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

2
Ttang_hao·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

1
Bbob_chen·2 days agoedited

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

215
Rran_bo·2 days ago

This is not a modding-books problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

1
Ddev_zhou·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

1
Zzhou_yi·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

39
Wwinter·2 days agoedited

I just read the modding-books source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

139
Cchen_devOP·2 days ago

One counter-example: below modding-books 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

337
Lli_ming·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

51
Oops_wang·2 days agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

2
Mmike_xu·2 days agoLevel 6

Saved. I am reworking this area this week — this saves a lot of wrong turns.

126
Rran_bo·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1

This is the post detail page /en/c/modding-books/post/p13. Posts and comments are generated deterministically from a seeded PRNG, so the same post always renders the same content and the link can be shared, reloaded and indexed. In production this page reads MySQL for the post, Redis for hot-post caching, and fetches the whole comment tree in a single query on the path column.

See the database schema →