Replication · Interviews · Six rules for error handling in replication-interview that I settled on

366
REr/replication-interview·posted by zhou_yi·2 days agoInternalsLocked

Six rules for error handling in replication-interview that I settled on

It took me two weeks of on-and-off digging and plenty of wrong turns. Writing the process down as it happened so the next person spends less time.

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.

On trade-offs, my view is this: if nobody on the team owns this area long-term, do not introduce a second mechanism. With two coexistence you first have to work out which one is even in play when things break, and that costs far more than the performance you saved.

Bblog.rust-lang.orgExternal link · opens in a new tab
140 comments

140 comments

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

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

500
KkiteOP·2 days ago

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

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

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

415
Nnikic·2 days ago

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

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

364
Mmike_xu·2 days ago

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

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

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

70
Bbob_chen·2 days ago

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

294
Hhuang_ke·2 hours agoedited

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

292
NnikicOP·2 days ago

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

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

278
Sswoole_lee·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
Kkernel_panic·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.

225
Mmike_xu·2 days ago

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

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

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

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

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

104
Aalice_dev·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.

202
Hhuang_ke·2 days ago

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

194
Aalice_dev·1 hour 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.

193
Wwinter·2 days ago

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

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

173
Mmike_xu·2 days ago

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

163
NnikicOP·just nowedited

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

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

53
Hhuang_ke·2 hours agoedited

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

238
Cchen_dev·3 minutes ago

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

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

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

128
Cchen_dev·2 days ago

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

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

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

90
Sslow_query·2 days ago

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

89
Bbob_chenOP·yesterday

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

25
Wwinter·2 days ago

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

84
Kkernel_panic·12 minutes agoedited

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

83
Ddev_zhou·3 minutes ago

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

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

202
Ddev_zhou·just nowedited

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.

510
Cchen_dev·yesterday

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

406
Rran_bo·2 days ago

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

450
Zzhu_zong·2 days ago

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

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

82
Zzhu_zong·2 days ago

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

20
Zzhou_yi·2 days agoedited

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

58
Rrase·2 days agoeditedLevel 6

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.

216
Mmike_xu·just nowLevel 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.

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

162
Mmike_xuOP·2 days ago

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

50
Rran_bo·yesterdayedited

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.

106
Wwinter·2 days ago

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

324
RraseMod·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.

392
Bbob_chenOP·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.

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

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

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

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

356
Ddev_zhouOP·2 days agoLevel 6

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

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

35
Nnikic·2 days 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.

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

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

1
Hhuang_ke·28 minutes ago

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

246
Hhuang_ke·yesterday

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

45
Kkite·2 days agoLevel 6

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

6
Rrase·2 days ago

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

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

10
Llinlin·2 hours agoedited

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

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

507
Oops_wang·2 days ago

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

353
Kkernel_panicMod·2 days ago

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

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

53
Sswoole_lee·2 days ago

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

423
Zzhu_zong·just nowedited

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

50
Ddev_zhou·just now

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

219
Rran_bo·28 minutes ago

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

170
Ttang_hao·1 hour ago

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

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

7
Oops_wang·28 minutes ago

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

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

43
Kkernel_panic·2 days ago

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

32
Wwinter·2 days ago

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

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

26
Sswoole_lee·3 minutes ago

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

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

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

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

321
Lli_ming·2 days ago

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

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

28
Oops_wangOP·2 days ago

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

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

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

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

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

150
Ttang_hao·2 days ago

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

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

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

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

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

19
Cchen_devMod·2 days ago

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

14
Ddev_zhou·2 days agoedited

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

7
Zzhu_zong·1 hour agoedited

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

6
Llinlin·2 hours agoedited

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

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

282
RraseMod·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.

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

362
Kkernel_panic·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
Lli_ming·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.

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

15
Ddev_zhou·2 days ago

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

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

388
Rran_bo·2 days ago

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

6
Rrase·2 days agoedited

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

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

1

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