One Slow Webhook Receiver Stalled Every Tenant
In a load test, eight tenants shared one worker of the Cycles Events Service (cycles-server-events). Together they produced 20 webhook deliveries a second. Seven of their endpoints answered immediately. The eighth took 500 ms to send its response headers. On release 0.1.25.27, a minute of that traffic pushed the p95 across the seven healthy tenants' requests, measured from enqueue until the receiver read the request, to about 51 seconds. The only thing that differed from the all-fast run was one endpoint's response delay.
The per-tenant scheduler that shipped in 0.1.25.28 changed that. On 0.1.25.32, the same minute measured 8.3–8.6 ms. Four more releases followed 0.1.25.28 within a day, fixing failure and recovery paths that the new scheduler exposed or that review found along the way.
How one lease caused webhook head-of-line blocking
The Cycles specs promise less than you might expect. A tenant's events are dispatched in order on their first attempt. A retried delivery can arrive after later events, and ordering across tenants is not guaranteed at all. A receiver that gets budget.exhausted before the budget.threshold_crossed that preceded it should reconstruct order from the envelope's timestamp and, where present, its correlation_id chain. Runtime protocol: webhook delivery · Webhook event delivery protocol · Webhook delivery contract
Release 0.1.25.24 added a fleet-wide lease in Redis, dispatch:ordering:lock, to keep dispatch order across replicas. Through 0.1.25.27, a worker took the lease, claimed the next delivery, sent the HTTP request, recorded the result and released the lease. The lease had to outlast the pending-queue wait plus the HTTP timeout, so its default was two minutes. Release 0.1.25.27 tightened first-attempt order through pre-send failures and crash recovery, but kept the lease around the send. The design was easy to reason about: one delivery was in flight across the whole fleet at any moment. It was also much stronger than a per-tenant guarantee needs.
That made the slowest receiver everyone's problem. In the scenario above, the slow tenant receives one delivery in eight, 2.5 a second. Each one holds the lease for half a second, so that tenant alone asks for 1.25 seconds of lease time every second. Every other delivery waits behind it while input continues.
We reran that minute twice on the released 0.1.25.27 image with one worker. The load test is described in detail below.
| Receivers | Healthy p95 | Completed per second, including drain | Requests unread when input stopped | Drain after input stopped |
|---|---|---|---|---|
| All answer immediately | 6.7 ms, 4.7 ms | 20.01, 20.01 | 1, 1 | 0.02 s, 0.02 s |
| One answers after 500 ms | 51.17 s, 50.12 s | 10.57, 10.67 | 571, 561 | 53.6 s, 52.5 s |
The input arrived at 20 deliveries a second for 60 seconds. With the slow receiver present, more than 560 of the 1,200 requests were still unread when input stopped, and the queues needed another 52–54 seconds to drain. A second worker does not add a second lane. In shorter 160-delivery runs recorded in the Events Service audit log, two workers moved healthy p95 from about 7.0 s to 6.6–6.7 s. Both workers wait for the same lease. Events Service audit log
Per-tenant webhook queues instead of one lease
A per-tenant guarantee does not need a fleet-wide send lease. The redesign in PR #187 and PR #188 keeps the fleet-wide lease only for admission and moves the HTTP send outside it.
| Step | Holds the fleet-wide lease? | What it does |
|---|---|---|
| Admission and first ready publication | Yes | Claims an ID from dispatch:pending, resolves its tenant from the source event, appends it to that tenant's FIFO and, if it is now the head, publishes it to the ready list. No HTTP request. |
| Claim from the ready list | No | Gives a sender a tenant's current head. A tenant has at most one deliverable head across the fleet. |
| Send | No | Up to DISPATCH_SEND_CONCURRENCY sends per worker, default 4, each on its own virtual thread. |
A sender claims from the ready list with one Lua script. The script takes an ID only if it is still first in its tenant's FIFO and first in line for its subscription. A system subscription can receive events from many tenants, so sends to one subscription are serialized across workers even when the tenants differ. The script records the worker's claim token before returning the ID. Every later write for that delivery, whether a retry schedule, an acknowledgement or a quarantine, checks that token. A worker that stalled and lost its claim cannot overwrite the work of the worker that recovered it. Redis Lua scripting · Why Cycles uses Redis Lua
Whether a head keeps its place depends on how far its send got. If a worker cannot send yet, for example because a secret or the security policy is unreadable, it defers the delivery before any HTTP request, and the delivery holds its position with its followers waiting behind it. If the request was sent and needs a retry, the tenant's next delivery is promoted in the same Redis operation that schedules the retry, and the retry returns through admission when its deadline arrives. That second path is why the spec only guarantees first-attempt order. If a worker crashes mid-send, recovery reissues the stale claim at its existing position.
Tenants whose deliveries target different subscriptions now send concurrently, up to the free sender slots across the fleet. The slow tenant still sends one request at a time, because its order requires that. At 500 ms a request, its ceiling is about two deliveries a second.
Concurrent senders also changed what an idle worker costs. Each worker polls the ready list on a configurable 25 ms delay to pick up work admitted by other workers, retries and promoted followers. The claim script originally ran with EVAL, which sends the whole script body on every call. On an empty queue, 200 warm polls sent 2,259,625 bytes to Redis. Before 0.1.25.28 shipped, the worker switched to EVALSHA, which sends the script's SHA-1 digest and falls back to EVAL when Redis answers NOSCRIPT, such as on first use or after a script-cache flush. The same 200 polls then sent 67,825 bytes. The worker's Redis ACL needs both commands. PR #189 verification · Redis script cache
What the same load test shows now
The Events Service repository ships the load test we used. It runs the worker image, Redis 7 and a Python producer and receiver on a private Docker network. The producer enqueues on a fixed schedule independent of completions, so a slow worker cannot ease its own input. Before reporting latency, the harness checks that every delivery arrived exactly once, in tenant order, and finished SUCCESS on its first attempt. Healthy-tenant percentiles pool the requests of every tenant except the slow one. Load test source
We ran each deployment twice with 1,200 deliveries, a minute of input, on the released 0.1.25.27 and 0.1.25.32 images. With 16 tenants the slow tenant receives one delivery in 16, 1.25 a second.
| Deployment | Release | Healthy p95, slow receiver present | Completed per second, including drain | Drain after input stopped |
|---|---|---|---|---|
| 1 worker, 8 tenants | 0.1.25.27 | 51.17 s, 50.12 s | 10.57, 10.67 | 53.6 s, 52.5 s |
| 1 worker, 8 tenants | 0.1.25.32 | 8.6 ms, 8.3 ms | 15.52, 15.56 | 17.4 s, 17.2 s |
| 2 workers, 16 tenants | 0.1.25.27 | 9.70 s, 8.94 s | 17.15, 17.34 | 10.0 s, 9.3 s |
| 2 workers, 16 tenants | 0.1.25.32 | 9.1 ms, 8.8 ms | 20.01, 20.01 | 0.02 s, 0.02 s |
On one worker of 0.1.25.32, 34 requests were unread when input stopped in both mixed runs. Thirty-three belonged to the slow tenant, which was offered 2.5 deliveries a second against a ceiling of about two. The 17-second drain is that tenant working through its own FIFO. Meanwhile the healthy tenants received 17.51 deliveries a second, matching what they were offered. With 16 tenants the slow tenant stays under its ceiling, and the harness first observed empty queues about 20 ms after the last enqueue. On 0.1.25.27 the 16-tenant mix still reached a healthy p95 of about nine seconds with two workers. We did not break that shortfall down between HTTP time, Redis work and lease contention.
The new release was slower on the easy path. With every receiver answering immediately, healthy p95 on one worker was 8.4–9.9 ms on 0.1.25.32 against 4.7–6.7 ms on 0.1.25.27. The two images differ in more than the scheduler, and we have not isolated the cause.
All runs used one Docker Desktop host with an AMD Ryzen Threadripper 3990X. They measure how the worker schedules dispatch, not production network latency. The same question for the reserve-commit API, with a quiet tenant beside busy ones, is in Can one busy tenant slow down everyone else? Download the 16 measured trials (JSON Lines)
What broke in dispatch and recovery
Releases 0.1.25.28 through 0.1.25.32 fixed failure and recovery paths. Some appeared only once sends ran concurrently. Others existed with a single sender too, and review found them while the dispatch code was open.
The delivery changed target during the request. The delivery row in Redis, not the worker's claim, says which subscription a delivery belongs to, and another writer can change it while a request is in flight. The worker compares the subscription it was admitted for with the current row before recording a result. On a mismatch it discards the result and tries to readmit the delivery, under its claim token, behind existing work for its new target. cycles_webhook_delivery_retargeted_result_total counts every discarded result by status family. A 2xx there means the original endpoint acknowledged a request whose result was dropped, so that endpoint may already have acted. Events 0.1.25.29 release
Workers disagreed about the time. Each worker stamps a subscription's last success, failure and trigger times with its own clock. A later write from a worker whose clock runs behind could move a timestamp backward. Each field now keeps the latest occurrence, and a value implausibly far in the future is repaired on the next write.
Recovery met a parked follower. Deferred heads, retries waiting for their deadlines and stale claims from a crashed worker all have to rejoin the right queue without overtaking each other. One randomized Redis run in the verification for PR #189 drained 720 deliveries across 12 tenants and nine subscriptions, including 103 target changes and 144 deferrals, and checked tenant and subscription order at every dispatch. PR #189 verification
The receiver answered and Redis did not. A final response can arrive and then a Redis write can fail. The worker now tries to save the outcome as a checkpoint on the delivery row. Once that checkpoint is durable, recovery can finish the bookkeeping without a second POST. A crash before it is written can still produce a duplicate request. That case has its own write-up. The webhook returned 503. What should we retry?
None of these changes the receiver's side of the contract. Delivery is at least once, and a receiver deduplicates by event_id. Receiver-side idempotency patterns
Two matchers for one allowlist
Operators can restrict webhook destinations with allowed_url_patterns. The Admin Server checks a URL when a subscription is created or its URL changes. The worker checks it again before every send, because DNS and policy can change in between. Both services turned a pattern into one regular expression over the whole URL, with * becoming .*. A wildcard could therefore cross the host boundary: https://attacker.net/a.example.com/x matched https://*.example.com/*. The worker's default denylist for private, loopback and metadata addresses still applied, but the allowlist itself could be bypassed. Admin PR #271
The fix matches the scheme, host, port, path, query and fragment separately, so a host wildcard stays inside the hostname. Shipping it in two services showed how easily two implementations of one rule drift:
| Change | Where the two services disagreed |
|---|---|
| Events PR #195 | A path * matched one segment. Admin's existing patterns needed it to span nested paths. PR #196 restored admin's behavior before release. |
| Events 0.1.25.31 | Admin let a host * match IPv6 literals. The worker did not, and it also rejected IPv6 literal patterns that were not written in canonical form. Admin approved destinations the worker then refused. In 0.1.25.32 the worker accepts them, and it also accepts equivalent spellings of an IPv6 literal where admin still requires the same spelling. |
The governance spec gives the example https://*.example.com/* but does not define the glob grammar. Until it does, each service carries its own tests for the same bypass and must-match cases, and keeping them in step is a manual review item.
The same release window closed a second gap between checking and sending. Through 0.1.25.29, the worker validated a destination's resolved addresses, then let the HTTP client resolve the name again. A DNS answer that changed between the two lookups could send the request somewhere the guard never approved. Since 0.1.25.30 the client connects to an address approved for that attempt and keeps the original hostname for TLS and the Host header. Events 0.1.25.30 release
What the upgrade cost operators
Releases 0.1.25.27, 0.1.25.28, 0.1.25.30 and 0.1.25.31 each required stopping all older workers before starting new ones. The first two moved deliveries into new queue structures. Operators who need exact first-send order across those two cutovers pause producers and let the old workers drain first. Releases 0.1.25.30 and 0.1.25.31 added terminal and retry checkpoints that older workers would ignore. Rolling back to 0.1.25.27 or earlier means draining the new queues, stopping the upgraded workers, confirming the drain again and deleting a migration counter. Operators also needed new Redis ACL grants for the send-queue keys and the EVALSHA path. Upgrade guide · Worker rollback procedure
That is a real cost of shipping a queue redesign as a series of patches. Folding the series into fewer releases would have meant fewer cutovers, but each release fixed something a running fleet could hit. Deploying the Events Service
The takeaway
- Scope a lock to the guarantee it protects. The specs promise first-attempt order within a tenant. A fleet-wide lease around the HTTP send protected far more than that, and turned one slow receiver into every tenant's latency.
- Keep receiver time out of admission. A worker still takes the fleet-wide lease to admit deliveries, but releases it before any HTTP request. Sends run outside it, one active head per tenant.
- Test recovery as part of the scheduler. Releases 0.1.25.28 through 0.1.25.32 fixed target changes during a request, clock skew between workers, stale claims rejoining the queue, and Redis writes that failed after a receiver answered.
- Give a shared rule one definition. The two allowlist matchers diverged on nested paths and then on IPv6 literals, and they still differ on equivalent IPv6 spellings. A glob grammar in the governance spec would leave less to keep in step by hand.
- Measure healthy receivers separately. In both one-worker mixed runs on 0.1.25.32, the slow tenant accounted for 33 of the 34 unread requests at the end of input, while healthy-receiver p95 stayed below 9 ms.
Run the slow-receiver load test
The benchmark needs Docker with Compose v2.17 or later and nothing else from Cycles. It pulls the published worker images, builds a small Python load container and publishes no host ports. The worker images are built for linux/amd64. On an ARM machine, Docker runs them under emulation and the timings will differ from ours. Download these files into the same empty directory:
- compose.yaml, the Redis, worker and load services
- dispatch.py, the producer, receiver and checks
- run-benchmark.sh, the runner
- LICENSE, the Apache License 2.0 that covers the first two files
Then run:
sh run-benchmark.shThat repeats all four deployments from the table above, 0.1.25.27 and 0.1.25.32 with one worker and with two, and takes about 20 minutes. To run one deployment, pass its release, worker count and tenant count, for example sh run-benchmark.sh 0.1.25.32 2 16. LOAD_COUNT=160 shortens each trial to 8 seconds of input. On Windows, use Git Bash or WSL.
Each deployment runs one warm-up and four measured trials: fast, mixed, mixed, fast. The script appends each measured trial to my-results.jsonl in the same format as our published results, so you can compare them row by row. healthy_p95_ms excludes the slow-receiver tenant in both workloads, including the all-fast control, and drain_after_input_s shows how long the queues took to empty after the last enqueue. A deployment fails on any missing, duplicated or out-of-order delivery, and the script then stops with a non-zero exit code. Each deployment's Compose output, including the load generator's log, stays in the directory.
The load generator is copied unchanged from the Events Service repository, where the same harness can test a local build. Load test in the Events Service repository
For your own webhook dispatcher, hold one receiver's response for half a second and measure the others from enqueue to receipt. If their latency grows with the length of the run, something in the send path is shared.
Resources