fix: stabilize membersGlobalActivityCount mv refresh (CM-1302)#4309
Merged
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Temporal workflow failures and query blocking caused by long-running refreshes of the membersGlobalActivityCount materialized view as the underlying memberSegmentsAgg table grows. It increases the activity timeout, limits retries to prevent lingering Postgres sessions/locks, and makes the refresh non-blocking for readers by switching to a concurrent refresh while also removing an unnecessary ORDER BY from the MV definition.
Changes:
- Increased the Temporal activity
startToCloseTimeoutfor MV refresh from 10 to 45 minutes and added a capped retry policy (max 3 attempts with backoff). - Switched MV refresh to
REFRESH MATERIALIZED VIEW CONCURRENTLYformembersGlobalActivityCount. - Removed
ORDER BYfrom themembersGlobalActivityCountMV definition to avoid extra sorting work during refresh.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| services/apps/members_enrichment_worker/src/workflows/refreshMemberEnrichmentMaterializedViews.ts | Increases activity timeout and adds bounded retries to stabilize the MV refresh workflow. |
| services/apps/members_enrichment_worker/src/activities/enrichment.ts | Enables concurrent MV refresh in the activity implementation to avoid blocking readers. |
| backend/src/database/migrations/R__memberEnrichmentMaterializedViews.sql | Removes unnecessary ORDER BY from the MV definition to reduce refresh cost. |
💡 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
The
refreshMemberEnrichmentMaterializedViewsworkflow was failing becauseREFRESH MATERIALIZED VIEW "membersGlobalActivityCount"exceeded the 10-minute activity timeout. AsmemberSegmentsAgggrew (~239M rows), refresh duration crossed that limit. Unlimited activity retries left zombie PG sessions holding exclusive locks, which also blocked member list queries.Changes
startToCloseTimeoutfrom 10 to 45 minutesREFRESH MATERIALIZED VIEW CONCURRENTLYso reads on the MV are not blocked during refreshORDER BYfrom themembersGlobalActivityCountMV definition (enrichment already sorts in its own query; removes an extra sort over ~635K rows on each refresh)