8.0 KiB
Two edges, one database: what actually happens
Measured 2026-10-01 on the deployable image (openwaf:multi, built from this
repo's Dockerfile) against the provider production uses — PostgreSQL 18 — not
the SQLite default the tests run on. Two edge containers, one shared database
(block_entries, allow_entries, country_rules, policy_settings), one
nginx upstream, TrustProxyHeaders=true so both edges derive the same source
key, Mode=Enforce, StreakThreshold=3.
Reproduce: ./run.sh (M1–M5), ./run2.sh (D1, D1b), ./run3.sh (D3), ./run4.sh (D4, two TTLs; its raw output is kept in run4-output.txt), ./run5.sh (D5, both sides of the alert-edge change; raw output in run5-output.txt). Each
builds the image, starts the stack, measures and tears it down; run.sh writes
results.json next to itself.
The numbers
| # | What was measured | Result |
|---|---|---|
| M1 | Two processes boot against an empty database at the same time | 1 row in __EFMigrationsHistory, 7 tables, 0 error-looking log lines. The migration race is not a problem: one migrates, the other waits. |
| D1 | 4 refusals from one source, split 2+2 across the edges, threshold 3 | No ban anywhere; engineBans in the shared database: 0. One edge seeing the same 4 requests bans at the third. |
| D1b | Same source, 3 more refusals to edge-a alone | edge-a answers 403; edge-b answers 403 about 2 s later — its snapshot was already past the TTL, so its next request triggered the refresh. |
| D3 | edge-b serving a steady ~36 req/s of upstream 200s from one source; edge-a writes an operator block at t0 | edge-b started enforcing 23.7 s after the write. The bound is the snapshot TTL: 30 s, hardcoded. |
| M4a | The three queries a snapshot refresh runs, at 2000 blocks + 2000 allow + 200 country rules | 1.6 ms + 1.0 ms + 0.5 ms, timed by psql \timing. Database side only — EF materialisation is not in this number. |
| M4b | Request path with that snapshot loaded, 200 × /healthz through edge-b |
p50 1.85 ms, p95 3.30 ms, max 4.50 ms. |
| M4c | Propagation of an operator block at that size, edge-b idle | 1.7 s. |
| M5 | Observations written by both edges | one row per source key; the shared table does not double-count a source both edges saw. |
| D4 | Propagation of an operator block written on edge-a, edge-b under a steady 200-only stream (~28 req/s), at two snapshot TTLs | 23.1 s at the default 30 s; 3.4 s at OpenWaf:State:RefreshTtlSeconds=5 — a 6.9x cut. Request path through edge-b at the same time: p50 1.75 ms / p95 3.15 ms at TTL 30, p50 1.93 ms / p95 2.78 ms at TTL 5 (n=200 each) — the two move in opposite directions, so the honest reading is "inside noise", not "cheaper". |
| D5 | Alert rows in the shared table for one upstream outage, measured on both sides of the edge-trigger fix | After: 2 rows [3, 6] through one edge, 4 rows [3, 3, 6, 6] through two. Before: 8 rows [3..10] and 16 rows. The dedup is per process, so two edges produce exactly twice the rows of one — and the row counts are identical per process, which is what proves it is the same rule running twice rather than a shared counter. 0 engine bans in both runs: a 5xx still never bans. |
What the numbers say
-
The streak is the multi-instance problem, and it is not a lag — it is a silent threshold change. D1 is decisive: four refusals from one address, two per edge, threshold 3, zero bans in the shared database. Round-robin over N instances multiplies the effective threshold by N, and nothing in the operator console says so. An operator who scales the edge horizontally weakens the one defence the project exists to provide, without touching a setting.
-
Block propagation is TTL-bound — and the TTL is now a setting. D3 measured 23.7 s under continuous traffic, and at the time of that run
EdgeStateStore.RefreshTtlreally was a property initialised to 30 s with no configuration binding anywhere in the tree: "shorten the TTL" was a rebuild. That sentence is now out of date, and deliberately kept here to show what changed. The key isOpenWaf:State:RefreshTtlSeconds(validated 1—300 s, anything outside aborts startup naming the key), reported by/healthzassnapshotTtlSecondsand by/admin-api/state, and shown on the console next to the snapshot age. D4 re-measured propagation with that knob: 23.1 s at 30 s, 3.4 s at 5 s, reproducing D3's 23.7 s at the default. On an idle edge the same propagation is 1.7 s (M4c) because the next request triggers the refresh — which is why a cold-start measurement understates it by more than an order of magnitude. -
The refresh is not the cost. At 2000 blocks the queries are ~3 ms total (M4a) and the request path is unchanged (M4b). The cost of multi-instance correctness is not CPU or database; it is the round trip a shared streak store would put on a path whose measured p95 is 3.3 ms.
-
Sharing the block list already works with no new machinery — M1, M4c and D1b are all the shared database converging on its own. Policy is shared the same way: the
PUT /admin-api/policyin run2.sh was visible on the other edge within one TTL, so the environment block in compose is a fallback, not a per-instance setting. -
The alert dedup is per process too, and that is visible in the shared table. D5 sent the same broken upstream through one edge and then through two. One edge: 2 rows, counts [3, 6]. Two edges, same source, same outage: 4 rows, counts [3, 3, 6, 6] — the single-process answer, twice. Before the fix the same two phases wrote 8 and 16. So the fix removes the per-request growth (which was attacker-shaped) but not the per-instance duplication, and the duplication is the same root cause as D1: the counter that decides whether to alert lives in the process. Option (c) below would collapse both at once; option (a) makes the operator's alert list read correctly by construction.
The decision this feeds (OPEN-12)
- (a) one instance per edge, documented — free, and the measurement says it is the honest default for the deployments this project targets.
- (b) shorten the TTL — measured now, not assumed: 23.1 s —> 3.4 s going from 30 s to 5 s (D4), with no measurable request-path cost at n=200. It fixes propagation only; D1 survives it untouched, and a shorter TTL is more database round trips per process per minute (12/min at 5 s against 2/min at 30 s), which is cheap at the measured snapshot size (M4a: ~3 ms of queries) and unmeasured at a size this project has not tested.
- (c) a shared streak store — the only option that fixes D1, and it buys exactness with a network round trip on the request path. Take it when the threshold has to be exact behind a load balancer, not before.
Caveats, stated plainly
- The M4a timings are database-side only. The end-to-end refresh cost was never measured directly; only its absence from the request path (M4b) and its effect on propagation (M4c) were.
- D3 is one run, one source, one upstream. 23.7 s is one sample of a wait bounded by 30 s, not a fitted distribution.
run2.sh's D2 is kept because its failure is instructive: the looper hit/probe, which is a refusal, so it banned its own source within a second and reported a negative propagation time. D3 inrun3.shis the corrected version, with the looper hitting a path the upstream answers with 200.- D4 is two runs, one source, one upstream, ~28 req/s — the same shape as D3, not a distribution. The 6.9x is a ratio of two single samples.
- D5 is one run per side, N=10 per phase, one source per phase. The row counts are exact (they are counts, not timings), so the 8 -> 2 and 16 -> 4 comparison does not depend on a distribution; what has not been measured is behaviour at more than two instances, where the expectation is N rows per escalation.
- The request-path comparison in D4 is n=200 per phase and the two percentiles moved in opposite directions. It supports "shortening the TTL did not make the request path measurably slower"; it does not support "it is free".