Commit 398f902
fix: continuous backend config cache cause postgres disk bloat (#6983)
# Description
The backend config cache persists the workspace config to postgres on
every config update. On every update the row was rewritten regardless of
whether the config value had actually changed or not. In postgres an
`UPDATE` always writes a new tuple version — even when the new values
equal the old ones — leaving the previous one dead; and since the large
`config` value lives in TOAST, each rewrite churns the TOAST table too.
This becomes pathological when:
- **There are a lot of continuous configuration changes**: every change
is another full-row rewrite.
- **Multiple pods try to cache the same config**: each pod independently
writes the same config to the same row, so a single logical change
becomes one write per pod, most of them re-writing a value identical to
what another pod just stored.
Dead tuples accumulated faster than autovacuum reclaimed them, steadily
bloating postgres disk usage.
### Changes
- **Conditional upsert via content hash** — a new `config_hash` column
stores a SHA-256 hex digest of the marshalled config. The upsert now
carries `WHERE config_cache.config_hash IS DISTINCT FROM
excluded.config_hash`, so when the stored config is already identical
the row is not rewritten and `updated_at` is not bumped. This
de-duplicates both no-op updates and redundant cross-pod writes.
- **Skip redundant work** — `set` does a cheap `SELECT config_hash`
first and returns early on a match, so a pod that finds the config
already cached skips encrypting and transferring the large config blob
entirely.
- **Debounce writes** — a burst of config updates is coalesced into a
single write per pod, controlled by `BackendConfig.dbCacheWriteDebounce`
(default `10s`).
- **Aggressive TOAST autovacuum** — the migration tunes `config_cache`
so dead tuples from any remaining rewrites are reclaimed promptly
(`toast.autovacuum_vacuum_scale_factor = 0`,
`toast.autovacuum_vacuum_threshold = 1`).
## Linear Ticket
resolves PIPE-3018
## Security
- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
Co-authored-by: Aris Tzoumas <atzoumas@rudderstack.com>1 parent b211809 commit 398f902
4 files changed
Lines changed: 144 additions & 7 deletions
File tree
- backend-config
- internal/cache
- sql/migrations/config_cache
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| 457 | + | |
457 | 458 | | |
458 | 459 | | |
459 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
| |||
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| 78 | + | |
| 79 | + | |
72 | 80 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
78 | 95 | | |
79 | 96 | | |
80 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
81 | 109 | | |
82 | 110 | | |
83 | 111 | | |
| |||
89 | 117 | | |
90 | 118 | | |
91 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
92 | 142 | | |
93 | 143 | | |
94 | 144 | | |
| |||
97 | 147 | | |
98 | 148 | | |
99 | 149 | | |
100 | | - | |
| 150 | + | |
101 | 151 | | |
102 | 152 | | |
103 | 153 | | |
104 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
105 | 157 | | |
106 | 158 | | |
| 159 | + | |
107 | 160 | | |
108 | 161 | | |
109 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments