Skip to content

perf(backend-sync): restore backfill-lane routing behind a default-off flag - #11966

Merged
Git-on-my-level merged 1 commit into
mainfrom
cost/c002-backend-sync-backfill-lane
Aug 21, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
cost/c002-backend-sync-backfill-lane

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Always-on backend-sync (Cloud Run, minScale 5) is running at 16–22 instances and costing ~$63.5/day net because enqueue_sync_job sends every sync job to the main queue. 95% of lane tokens are lane=backfill. The already-provisioned backend-sync-backfill worker took 0 HTTP requests in 6 hours and costs $2.30/day sitting idle.

Live config, verified 2026-08-20:

  • always-on backend-sync: SYNC_TASKS_QUEUE=sync-jobs, minScale 5, max 25, cpu-throttling=false, concurrency 20
  • backend-sync-backfill: SYNC_BACKFILL_TASKS_QUEUE=sync-backfill, SYNC_BACKFILL_ENABLED=true, minScale 1, max 30, request-based, concurrency 1
  • Occupancy on always-on: /v2/sync-jobs/run (STT) 17,268 s/h = ~61%; audio-merge 10,660 s/h; admission 481 s/h

Modelled saving: always-on 18 → ~7 instances (−$38/day), request-based backfill picks up ~4.8 concurrent STT jobs (+$17/day) ⇒ net ~$15–25/day.

This PR restores lane-based queue selection in enqueue_sync_job: lane=backfill goes to SYNC_BACKFILL_TASKS_QUEUE + the backfill handler URL; everything else keeps the main queue. Audio-merge routing, minScale, and deploy YAML are out of scope.

Why this is not a naive revert of #10400

The two-lane split was collapsed in #10400 deliberately, to fix a real customer incident. Offline recordings can never carry server capture proof, so they all classify as lane=backfill. That sent the entire offline workload to a lane provisioned for occasional historical recovery. The backfill worker admitted only a few jobs at once (~4-dispatch), so Cloud Tasks retried the surplus with exponential backoff until recordings sat unprocessed for many hours.

A naive restore of that routing would re-open that incident. It is safe to restore now because the backfill worker's admission capacity changed: it is maxScale 30, concurrency 1, request-based — i.e. 30 concurrent jobs, versus the ~4-dispatch lane that caused the incident.

Flag

SYNC_BACKFILL_ROUTING_ENABLED (default false). With the flag off, behaviour is byte-identical to today: every job still goes to the main queue. With the flag on, lane=backfill is routed to the backfill queue/handler (including the backfill OIDC audience). If the backfill queue or handler env vars are unset or empty, the job falls back to the main queue and is never dropped.

Rollout

  1. Ship dark. Merge with SYNC_BACKFILL_ROUTING_ENABLED unset/false. No traffic moves.
  2. Enable. Set SYNC_BACKFILL_ROUTING_ENABLED=true on the enqueueing service once the 30-wide backfill worker is confirmed live.
  3. Watch. Confirm backend-sync-backfill starts taking /v2/sync-jobs/run traffic and always-on instance_count falls. Flip the flag off immediately if recordings stall or always-on occupancy does not move.

Rollback bar

If backend-sync + backend-sync-backfill combined net over 7 closed UTC days is >= $56/day, the routing change saved nothing and the flag goes back off.
Independently: if always-on instance_count ALIGN_MEAN over 48 matched hours stays >= 16, STT did not leave the lane.

Tests

cd backend && python -m pytest tests/unit/test_sync_cloud_tasks.py → 90 passed.

🤖 Generated with Claude Code

Review in cubic

…f flag

The always-on worker is paying for ~95% backfill traffic the idle
backend-sync-backfill service was provisioned to take; keep #10400's
main-queue default until the 30-wide worker is proven in production.
@Git-on-my-level
Git-on-my-level merged commit 0e18931 into main Aug 21, 2026
41 checks passed
@Git-on-my-level
Git-on-my-level deleted the cost/c002-backend-sync-backfill-lane branch August 21, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant