PWA · Interviews · Cut our pwa-interview build from 4 minutes to 40 seconds with these 5 changes

2.3K
PWr/pwa-interview·posted by zhou_yi·just nowPostmortem

Cut our pwa-interview build from 4 minutes to 40 seconds with these 5 changes

Short version: pwa-interview 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.

Order of investigation, by return on effort: 1. Check downstream latency first — usually it is not your problem 2. Then pool hit rate and wait-queue length 3. Only then GC and allocation 4. Suspect the framework last

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

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.

One last trap: in container environments remember to adjust the memory-related parameters in step. Otherwise the host limit and the process expectation disagree, and the symptom is intermittent, unreproducible failure.

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.

815 comments

815 comments

· first 120 loaded
M
Bbob_chen·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.

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

480
Nnikic·yesterday

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

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

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

5
Ttang_haoOP·3 minutes ago

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

41
Oops_wang·just now

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.

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

375
Mmike_xu·28 minutes ago

One counter-example: below pwa-interview 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
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.

278
Mmike_xu·2 days ago

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

72
Ttang_hao·2 days ago

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

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

49
Lli_ming·2 days ago

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

418
Oops_wang·2 days ago

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

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

347
Kkernel_panic·2 days ago

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

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

372
Mmike_xu·28 minutes ago

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

350
Oops_wang·3 minutes ago

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

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

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

24
Hhuang_ke·2 days ago

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

1
Nnikic·2 days ago

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

312
Llinlin·yesterday

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

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

19
Sslow_queryMod·2 days ago

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

250
Kkernel_panic·2 days ago

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

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

217
NnikicOP·2 days ago

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

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

197
Zzhou_yiOP·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.

123
Zzhou_yi·2 days ago

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

178
Sslow_query·yesterdayedited

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.

175
Mmike_xu·2 days ago

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

170
Wwinter·2 days ago

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

37
Sswoole_lee·1 hour ago

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

146
Kkernel_panic·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.

144
Mmike_xu·2 days ago

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

144
Kkernel_panicOP·2 days ago

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

69
Wwinter·2 days ago

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

126
Zzhou_yi·28 minutes agoedited

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.

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

174
Rran_bo·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.

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

479
NnikicOP·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.

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

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

3
Sslow_queryOP·2 days ago

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

361
Kkernel_panicOP·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.

152
Mmike_xu·2 days ago

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

70
WwinterMod·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.

37
Ddev_zhou·12 minutes ago

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

24
Rran_bo·3 minutes ago

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

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

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

387
Zzhu_zongOP·3 minutes ago

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

221
Rran_boMod·just now

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

116
Bbob_chenOP·1 hour ago

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

46
Bbob_chen·2 days ago

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

1
Sswoole_leeOP·just nowLevel 6

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

27
Bbob_chen·3 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.

23
Nnikic·28 minutes ago

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

231
Sswoole_leeOP·5 hours agoedited

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.

1
Nnikic·yesterday

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

389
Kkite·2 days ago

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

81
Sswoole_leeOP·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.

500
Kkite·2 days agoLevel 6

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

108
Kkernel_panic·2 days agoLevel 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.

1
Zzhou_yi·2 days ago

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

10
NnikicOP·3 minutes ago

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

1
Kkernel_panic·yesterday

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

15
Rrase·2 days ago

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

10
Hhuang_keMod·2 days ago

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

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

24
Zzhu_zong·2 days ago

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

127
Llinlin·just now

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.

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

326
Ttang_haoOP·3 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.

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

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

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

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

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

207
Sswoole_leeOP·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.

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

433
Bbob_chen·2 days agoLevel 6

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.

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

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

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

136
KkiteOP·2 days ago

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

414
Rran_bo·2 days ago

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

413
Hhuang_ke·2 days agoLevel 6

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

419
Bbob_chen·28 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.

67
Rrase·2 days agoLevel 6

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

239
Cchen_dev·2 days ago

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

51
Bbob_chenMod·2 days agoLevel 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.

49
Sswoole_leeOP·2 days ago

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

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

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

8
Rran_bo·2 days ago

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

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

19
Sslow_query·2 days ago

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

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

64
Lli_ming·2 days ago

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

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

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

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

1
Kkernel_panic·2 days ago

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

320
Rran_bo·2 days ago

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

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

6
Sslow_query·3 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.

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

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

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

23
Oops_wangMod·3 minutes ago

One counter-example: below pwa-interview 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
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.

1
Kkernel_panic·2 days ago

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

1

This is the post detail page /en/c/pwa-interview/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 →