Clean Architecture · Chinese · I upgraded our production clean-architecture-zh and hit these 11 landmines

687
CAr/clean-architecture-zh·posted by swoole_lee·yesterdayReview

I upgraded our production clean-architecture-zh and hit these 11 landmines

Short version: clean-architecture-zh needs almost no tuning at small and medium scale — the point where it starts to hurt is much further out than most people assume. Full measurements below.

// Minimal reproduction: you must use a real long-tail distribution here.
// Uniform load-test traffic will never trigger this.
func (s *Server) handle(ctx context.Context) error {
    conn, err := s.pool.Acquire(ctx)
    if err != nil {
        return fmt.Errorf("acquire: %w", err)
    }
    defer conn.Release()

    return s.do(ctx, conn)
}

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.

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 clean-architecture-zh itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

388 comments

388 comments

· first 120 loaded
M
Wwinter·2 days ago

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

492
Mmike_xu·2 days agoedited

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

44
Aalice_devOP·1 hour ago

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

410
Rrase·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.

414
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.

387
Kkernel_panic·2 days agoedited

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

362
Zzhu_zong·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.

61
Kkite·2 days ago

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

7
Wwinter·2 days agoedited

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

27
Zzhu_zongOP·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.

125
Nnikic·3 minutes ago

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

346
Rran_bo·yesterday

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.

485
Ttang_hao·3 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.

26
Hhuang_ke·5 hours ago

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

119
Bbob_chen·28 minutes ago

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

444
Nnikic·5 hours ago

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

44
Kkite·2 days ago

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

186
Rrase·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.

99
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.

96
Cchen_dev·just nowedited

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.

56
Wwinter·2 days ago

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

177
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.

343
Kkite·2 days ago

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

30
NnikicOP·2 days ago

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

56
Bbob_chen·2 hours ago

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

1
Kkernel_panic·2 days agoedited

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.

47
Hhuang_ke·2 days ago

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

39
Cchen_dev·28 minutes ago

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

9
Llinlin·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.

407
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.

145
Oops_wang·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.

63
Nnikic·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.

8
Ddev_zhouMod·just nowLevel 6

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.

101
Sswoole_lee·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.

3
Kkernel_panic·2 days agoedited

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

95
Ttang_hao·2 days agoLevel 6

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

316
Nnikic·2 days ago

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

1
Oops_wang·2 days agoeditedLevel 6

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.

3
Cchen_dev·28 minutes ago

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

45
Llinlin·12 minutes agoedited

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

1
Bbob_chen·yesterday

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.

377
Oops_wang·2 days ago

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

1
Aalice_dev·2 days ago

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

112
Sslow_query·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.

254
Hhuang_ke·just now

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

398
Wwinter·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.

78
Nnikic·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.

17
Zzhou_yiOP·2 days ago

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

8
Mmike_xu·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.

65
Mmike_xu·2 days ago

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

20
Ttang_hao·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.

61
Sswoole_lee·2 days agoLevel 6

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

225
Oops_wangMod·2 days agoedited

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

14
Zzhu_zong·28 minutes ago

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

1
Rran_bo·just now

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

53
Kkite·3 minutes ago

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

23
Mmike_xu·2 days agoLevel 6

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.

388
Llinlin·2 days agoeditedLevel 6

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

8
Lli_ming·2 days ago

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

322
Zzhu_zong·3 minutes 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.

317
Sswoole_leeOP·3 minutes 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.

250
Ddev_zhouOP·2 days ago

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

55
Cchen_dev·2 days agoedited

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

138
Kkite·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.

1
Mmike_xu·3 minutes agoedited

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.

216
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.

4
Hhuang_ke·2 days ago

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

494
Wwinter·2 days ago

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

212
Ttang_hao·2 days ago

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

186
Oops_wang·2 days agoedited

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

118
Nnikic·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.

109
Zzhou_yi·2 days ago

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

489
Kkernel_panic·1 hour agoedited

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

101
Wwinter·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.

94
Sslow_query·2 days ago

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

87
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.

87
Zzhu_zong·2 days agoedited

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.

76
Zzhu_zongMod·2 days agoedited

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

74
Aalice_dev·3 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.

46
Ddev_zhou·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.

29
Oops_wang·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.

416
Oops_wang·2 days ago

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

120
Sslow_query·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.

1
Cchen_dev·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.

218
RraseMod·2 days ago

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

204
Mmike_xuOP·2 days agoedited

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

50
Mmike_xu·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.

28
Sswoole_lee·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.

28
Rrase·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.

27
Nnikic·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.

22
Nnikic·2 days ago

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

19
Rran_bo·2 days ago

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

16
Lli_ming·2 days ago

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

15
Aalice_dev·12 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.

95
Ttang_hao·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.

126
Sswoole_lee·3 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.

12
Ttang_hao·2 hours ago

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

10
Zzhu_zong·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.

211
Oops_wang·2 days agoedited

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

12
Lli_ming·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.

5
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.

26
Ttang_hao·2 days ago

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

226
Mmike_xu·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.

231
Aalice_dev·2 days ago

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

1
Kkernel_panic·2 days ago

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

4
Wwinter·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.

4
Sslow_query·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.

2
Hhuang_ke·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.

2
Kkite·3 minutes agoedited

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.

1
Cchen_dev·2 days ago

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

444
NnikicOP·2 days ago

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

12
Sslow_query·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.

6
Rrase·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.

17
Zzhou_yi·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.

31
Cchen_dev·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.

1
Bbob_chen·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.

103
Rrase·just now

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

1
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.

170
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
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.

1

This is the post detail page /en/c/clean-architecture-zh/post/p9. 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 →