PWA · Interviews · Why this pwa-interview pattern gets slow in production: a source-level explanation

1.3K
PWr/pwa-interview·posted by alice_dev·1 hour agoJobs

Why this pwa-interview pattern gets slow in production: a source-level explanation

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

# Load test: do not jump straight to the max concurrency.
# Ramp it up, otherwise you miss the knee.
for c in 50 100 200 400 800; do
  wrk -t8 -c$c -d60s --latency http://127.0.0.1:8080/api/feed
  sleep 20
done

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.

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.

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

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

226 comments

226 comments

· first 120 loaded
M
Rran_bo·5 hours 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.

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

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

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

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

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

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

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

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

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

320
Oops_wang·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".

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

268
Ddev_zhou·2 days ago

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

237
Zzhu_zong·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".

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

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

11
Cchen_dev·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".

197
Bbob_chen·just now

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

190
Wwinter·just nowedited

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.

432
Mmike_xu·12 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".

361
Sslow_query·2 hours 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.

316
Zzhou_yi·12 minutes ago

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

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

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

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

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

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

372
Hhuang_ke·2 days ago

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

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

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

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

146
Hhuang_ke·3 minutes agoedited

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.

380
Oops_wang·2 days ago

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

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

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

119
Oops_wang·2 days ago

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

116
Oops_wang·5 hours 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.

104
Zzhou_yi·1 hour ago

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

3
Sslow_query·5 hours ago

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

12
Zzhu_zong·2 hours ago

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

101
Bbob_chenOP·1 hour 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.

40
WwinterOPMod·2 days ago

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

37
Sslow_query·5 hours 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.

93
Lli_ming·2 days ago

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

93
Mmike_xu·just now

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.

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

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

105
Lli_mingOP·2 days ago

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

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

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

84
Aalice_devOP·1 hour 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.

20
Cchen_dev·2 days ago

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

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

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

68
Sswoole_lee·yesterdayedited

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.

66
Ttang_haoOP·12 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.

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

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

56
Mmike_xu·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".

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

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

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

23
Ttang_haoOP·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.

317
Oops_wang·2 days agoLevel 6

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

205
Kkernel_panic·2 hours ago

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

1
Bbob_chen·2 days ago

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

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

143
Nnikic·2 days agoLevel 6

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

12
Kkernel_panic·2 days agoedited

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

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

287
Kkernel_panic·2 days agoLevel 6

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

42
Ttang_hao·3 minutes agoedited

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

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

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

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

24
Sswoole_lee·28 minutes agoLevel 6

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

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

71
Rran_bo·2 days agoeditedLevel 6

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

10
Aalice_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
Ddev_zhou·3 minutes agoLevel 6

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

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

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

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

40
Sswoole_lee·2 days agoedited

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.

251
Wwinter·2 hours ago

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

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

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

1
Kkernel_panic·2 days agoedited

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

266
Sswoole_lee·2 days ago

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

29
Wwinter·just now

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.

24
Mmike_xu·2 days agoedited

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.

11
Rrase·3 minutes ago

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

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

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

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

14
Rran_bo·2 days ago

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

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

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

7
Oops_wang·2 days ago

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

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

4
Ddev_zhou·yesterday

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

364
Llinlin·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".

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

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

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

1
Kkernel_panic·12 minutes ago

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

200
Cchen_devOP·2 days ago

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

105
Ddev_zhouOP·3 minutes agoedited

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

352
Llinlin·5 hours ago

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

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

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

263
Sslow_query·just now

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.

346
Llinlin·2 days agoLevel 6

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
Zzhou_yi·3 minutes agoedited

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.

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

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

1
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
Oops_wang·yesterday

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

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

9

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