Open
Conversation
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.
There was a problem hiding this comment.
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_atto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
webhook_deliveries.created_atso thestaleandorderedscopes no longer full-table-scanTest plan
bin/rails db:migrateruns cleanlybin/rails test test/models/webhook/delivery_test.rb— 23 tests pass