Skip to content

Reduce webhook delivery cleanup impact#2550

Open
jeremy wants to merge 2 commits intomainfrom
webhook-delivery-cleanup
Open

Reduce webhook delivery cleanup impact#2550
jeremy wants to merge 2 commits intomainfrom
webhook-delivery-cleanup

Conversation

@jeremy
Copy link
Member

@jeremy jeremy commented Feb 14, 2026

Summary

  • Add index on webhook_deliveries.created_at so the stale and ordered scopes no longer full-table-scan
  • Run cleanup every 15 minutes instead of every 4 hours, cutting per-run delete volume ~16x

Test plan

  • bin/rails db:migrate runs cleanly
  • bin/rails test test/models/webhook/delivery_test.rb — 23 tests pass

The stale scope (WHERE created_at < ?) and ordered scope
(ORDER BY created_at DESC) both benefit from this index.
Without it, Webhook::Delivery.cleanup does a full table scan.
Each run now deletes ~15 minutes of newly-stale records instead
of ~4 hours worth, a 16x reduction in per-run write volume.
Copilot AI review requested due to automatic review settings February 14, 2026 07:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a P99 latency incident that occurred on Feb 11 in Ashburn by optimizing webhook delivery cleanup operations. The changes reduce the impact of cleanup operations by adding a database index and increasing cleanup frequency to spread the workload more evenly.

Changes:

  • Added a database index on webhook_deliveries.created_at to eliminate full-table scans in cleanup operations
  • Changed webhook delivery cleanup schedule from every 4 hours to every 15 minutes, reducing per-run delete volume by approximately 16x

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
db/migrate/20260213170100_add_created_at_index_to_webhook_deliveries.rb New migration to add index on created_at column for webhook_deliveries table
db/schema.rb Updated schema version and added index entry for webhook_deliveries.created_at (MySQL)
db/schema_sqlite.rb Updated schema version and added index entry for webhook_deliveries.created_at (SQLite)
config/recurring.yml Changed cleanup_webhook_deliveries schedule from "every 4 hours at minute 51" to "every 15 minutes"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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